techt's blog

By techt, 9 years ago, In English

Problem : 439B — 29

This seems to be a new discovery for me o_o

My submissions :

long vs Long

Primitive vs a Wrapper Class... How can changing from long to Long suddenly impact the performance? why am I getting TLE with long but not Long ??

  • Vote: I like it
  • +3
  • Vote: I do not like it

| Write comment?
»
9 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

I think it's due to the Arrays.sort().

For primitive type it uses Quick sort which takes O(n^2) in worst case. And during object one it uses TimSort.

If you want to use Arrays.sort() for primitive one, shuffle the array before sorting. For example — use knuth shuffle.