SEACO - Editorial

can anyone provide an easy editorial for this problem…

1 Like

I did this problem in a different way. I used two segment trees with lazy propagation on both of them. My solution passed in 0.30 secs.
segment tree for queries - segQ

segment tree for array - segA

First, I updated segQ with a val=1 (as every operation will be executed at least once). Then I ran a loop from m-1 to 0 and updated all the queries of type 2. Like for example for the 3rd sample test case of the problem, if the query was 2 1 5, then first I got the initial value on that node by doing query on segQ to get the no. of times this operation will be executed (say x) in future then with that value I updated the operations from 1 to 5 (i.e. l and r of the query) which means operations from 1 to 5 will be called x more times so add.

Then after that I ran a second loop from 0 to m-1 but this time for queries of type 1 and updated segA with the values for that particular command on my segQ.
This is my full code

If for commands we build the difference sequence in backward order, as the editorial does, but for the array we build it in forward order, then it is sufficient to just keep the running totals (without actually restoring the corresponding sum sequences).

Here is python solution.

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. CodeChef: Practical coding for everyone

Finally was able to solve this after learning from the editorial about difference array. Here is my solution: [Yay! AC <3][1]
[1]: CodeChef: Practical coding for everyone

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

1 Like

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.

lazy propagation is an overkill here actually. Normal segtree would work. I used a segtree but now am realising that there was an even easier way using a difference array.

2 Likes

yes, i realised that while solving it. There was no way 2k people would be able to solve it using segtrees.

1 Like

it usually happens they will just rectify it soon you must wait for sometime

Honestly I didnt expect it to cross 2k when I got AC for my sqrt decomposition method.

The editorial solution is O(n+m).

1 Like

You need to use modulo arithmetic when implementing BIT.

Oh right. I misread the alternative solution.

I used that but may not be correctly

@harsh24
I have used the same approach and got 100 points. I have added explanation just above, alongwith a link to my code.

Ask me anything if required…

Hers’s the link

https://discuss.codechef.com/questions/108189/seaco-editorial/110993

Please upvote if u find that helpful…