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

Автор rahulkhairwar, история, 8 лет назад, По-английски

I was trying to learn Mo's Algorithm from here and this was one of the suggested problems. But, I'm getting TLE verdict with Java, while my code is very similar to the one that the tutorial's author has written, in C++.

Can someone please tell me what am I doing wrong(slow)? Thanks.

UPDATE : Sorry, forgot to post a link for my code

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

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

Auto comment: topic has been updated by rahulkhairwar (previous revision, new revision, compare).

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

I did not trace your code, but SPOJ is very strict judge. Some problems are only solvable in C++.

So sometimes no matter how much you optimise your Java's code, it won't pass.

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

slow input !?

»
8 лет назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

I believe your solution should pass as the time complexity is acceptable. But, as many people have already pointed out, SPOJ is pretty strict when it comes to TLEs.

However, there is a faster solution than yours. Try to come up with a solution using BIT.

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

Same here for my java code too. Tried all kinds of optimizations and gave up. I tried searching those 3 ppl (whose java passed) on codeforces but no luck A couple other similar tight tle problems were also solved by some of the 3.