Блог пользователя techt

Автор techt, 9 лет назад, По-английски

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 ??

  • Проголосовать: нравится
  • +3
  • Проголосовать: не нравится

»
9 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

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.