SEACO - Editorial

I am not sure what you are trying to say. You can see my code that just uses running totals of the difference arrays. Both command types are handled in a single pass starting from the last command.

Well,

I don’t really understand what you are missing here, because i code in java and not used to C language, so don’t understand your code…

I think it depends upon the approach we are following. In your approach, as your code proved, There’s no need to restore sum sequences…

But in my approach, you need to restore sum array atleast once to find number of executions of command 1…

So, in short, restoring sum array is dependent upon approach followed.

Hope that helps…

Please UPVOTE…

Feel free to ask anything…

Illiteracy in popular programming languages does not justify your condescending attitude. :wink:

Thanks for the detailed explanation. But can u pls tell me how u came up with such a solution. I mean is this any standard algorithm? If yes, pls link some material where I can read more about it.
Thanks again :slight_smile:

Well,

I’m a new programmer with just one year in java programming mate…

I meant to co-operate as much as i can…

I tried my best explaining to you my code, the query you asked as well as the difference in our approaches…

But when i cannot understand a code, how can i explain what’s going on in the loop and statements…

Well, if you found my explanation / approach / effort or code, anything, Please Upvote…

Feel free to ask anything…

I’ll be pleased to clarify your doubts… :slight_smile:

May be it is some kind of misunderstanding, but I honestly don’t care about your code and have never asked you to explain to me anything about it. This is the editorial thread, in case you have not noticed. :slight_smile:

@dishant_18

You can read more about difference arrays at

example problem mentioned on that page is just the same…

Oh Sure,

I merely tried to help… :slight_smile:

can someone explain how to solve this using fenwick tree?

can anyone explain hw dis can be solved using seg trees ??

Can anyone give similar problem like this?

Sqrt decomposition technique works fine…AC in 0.33s

Solution using BIT. https://www.codechef.com/viewsolution/15528033

Finally was able to solve this after learning from the editorial about difference array. Here is my solution: [Yay! AC <3][1]
[1]: https://www.codechef.com/viewsolution/15589296

Please, someone tells how to solve this problem using fenwick tree(Binary Index Tree).
Share methods, not code. :slight_smile:

For each command, we need to count how many times it’s executed during the whole process, denoted by cnt[i]. We can iterate the commands backwards, and every time we meet a command 2 l r which is executed k times, we add k to cnt[l∼r]. When we know cnt[i] for every command i of type 1, we can easily figure out the answer by maintaining the difference array of a.
Can anyone explain this.I am completely unable to understand.