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.