Please subscribe to the official Codeforces channel in Telegram via the link https://t.me/codeforces_official. ×

zeref_dragoneel's blog

By zeref_dragoneel, history, 7 years ago, In English

Problem link: http://www.spoj.com/problems/XXXXXXXX/

Solution Link: http://ideone.com/Myb8M6

Can someone help me debug my solution? I am trying to use segtree + treap in the code.

Thanks.

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

»
7 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Got the mistake. It was int -> long long mistake.

  • »
    »
    7 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Can you please explain your approach.

    • »
      »
      »
      7 years ago, # ^ |
      Rev. 2   Vote: I like it +5 Vote: I do not like it

      I have used the approach explained in the comment http://codeforces.com/blog/entry/10508?#comment-158835

      while updating i for A[i], I add the value A[i] to the point representing (i, left[i]) where left[i] denotes the greatest j s.t. A[j] == A[i] & j < i. If no such j exists, then left[i] = 0.

      Now for query, I found the sum in (L,0) to (R,L-1) both included.

      Updated code with int -> long long correction: http://ideone.com/sJMdlW

      • »
        »
        »
        »
        7 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Thanks for the link.I guess instead of using treap we can also use square root decomposition with a bit in each block.

        • »
          »
          »
          »
          »
          7 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          Yes, that should also work but I am not sure whether it will pass the time limit (Q * sqrtN * logN solution) as spoj is relatively more time-strict than any other sites I know.

»
7 years ago, # |
  Vote: I like it +41 Vote: I do not like it

  • »
    »
    7 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Well -3 seems like downvoted to me...

    • »
      »
      »
      7 years ago, # ^ |
        Vote: I like it +8 Vote: I do not like it

      It was 0 when I came and we all know that -3 is nothing compared to what a green coder would receive.

  • »
    »
    7 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Well, I did not personally ask you or anyone to debug the code.

    I only posted it as a question. So, if someone will be available to debug it, he/she will and will tell me my mistake. You or Anyone for that matter had any obligation to see the code and try to find a bug.