maulik12's blog

By maulik12, 9 years ago, In English

Hi Everyone, I have been practicing Segment trees and there's a very straightforward problem on SPOJ. Link:http://www.spoj.com/problems/CDC12_H/

I have used Lazy Propagation by I am getting WA. And I don't know why. Here's my code. Link: http://ideone.com/gAx34B

Its pretty much understandable. Please tell me as to where I am wrong . Thanks, Maulik

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

| Write comment?
»
9 years ago, # |
  Vote: I like it +5 Vote: I do not like it

Lines 34-35 and 66-67 Replace

    lazy[2*index+1]+=1;
    lazy[2*index+2]+=1;

By:

    lazy[2*index+1]+=lazy[index];
    lazy[2*index+2]+=lazy[index];
  • »
    »
    9 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    wow it was the easier way :D... always an easier way exists :D

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

I have read your code and changed it and it got AC! here is your code: http://ideone.com/emLhch