以下是引用HJin在2007-9-16 13:03:19的发言: I think the algorithm for solving the invesion prolbem is O(n^2) --- you have two for loops and I would think in the worst case scenario, you will have O(n^2).
I submitted a O(n lgn) algorithm at yzfy.org, which uses a STL set (the set brings me TLE always).