You can process queries of type 3 offline. The trick is not to go forward and adding new element, but go backward and delete element. This can be done in $$$O(N log N^2)$$$, or in $$$O(N log N)$$$ using walk on segment tree.
Query of type 1,2,4 can be processed using segment tree with lazy propagation.
Query of type 2 can be broken down to this : $$$a_p += (p - l + 1)*x \lt = \gt a_p += (p + 1)*x - l*x$$$.
You can use a different segment tree to store the sum of $$$x$$$, then $$$-l*x$$$ can be trivially stored.
But there's still query of type 3 that may potentially affect the sum $$$l..r$$$. So our segment tree shouldn't store the sum of elements from $$$l...r$$$ $$$(a_l + a_{l + 1} + ... + a_r)$$$ , but the sum of the whole range $$$l$$$..$$$r$$$, regardless of whether this whole range has been fully filled with element or not. You will need an additional $$$cnt$$$ array to store the number of added elements, to calculate $$$(p + 1)*x - l*x$$$
For query of type 1, you need an "override" lazy propagation array.
The overall time complexity will be $$$O(N log N)$$$ or $$$O(N log ^2 N)$$$, both can comfortably fit in 1s runtime.
Space complexity $$$O(N log N)$$$
Auto comment: topic has been updated by peacebringer167 (previous revision, new revision, compare).
Auto comment: topic has been updated by peacebringer167 (previous revision, new revision, compare).
thanatos not thatanos
I am in no position to give a really valuable feedback, but for me as a newbie i think the problem has a really good foundation, but the problem statment was a bit confusing for me, like are the horsemen supposed to do damage to the wall thus decreasing it, or change it's the walls value and set it to x, or increment it, it would be nice if the statment made that clear, i just made a pastebin page just to provide how an average 1000 rated user would understand the problem and i spent well over an hour on that and still didn't understand how to get the desired output. thanks for the problem and good luck with coaching ^ _ ^
I agree the statement is a quite confusing. The statement could've been more clear, and describe the queries more directly. However it's intentionally misleading :>, because my country's national Olympiad is full of misleading statements like this :>. Anyway thank you for your support!!. Love you <3
This problem is a nice one, I've enjoyed it. However, here are some possible issues of the statement:
First of all, use italic instead of TeX for horse names, it is a small problem but it makes the statement pretty hard to read for me.
Also for problems with long statements, it's best to provide a simplified statement (that is usually provided in OI style contests in my country).
In your first operation you mistyped
<=to<and that might be why it's wrong.btw, your solution will get TLE since $$$1\le n, q\le 10^5$$$, one correct solution would be
process the queries offline with a segment tree
Thank you for pointing out the typos and errors. But
A segment tree (lazy propagation) with offline queries can comfortably solve this problem in under 1s with $$$n,q \lt = 10^5$$$ though
I'll add the solutions soon :><>
Auto comment: topic has been updated by peacebringer167 (previous revision, new revision, compare).