A few days ago, I was solving a contest, where I found a problem, that I couldn't solve there.
You have got an array, size of N < = 105, and you are recieving up to M<=10^5 queries of the three types:
1 l r d -- increase every element at the segment [l;r] by t, i.e. X + = t
2 l r -- square root every element at the segment and round all of them down, X = [sqrt(X)]
3 l r -- get the sum at the segment
I tried several approaches, but none worked. If someone has some good idea, give me a clue.
p.s. messing around with the CF post editor :(
Edit: Sorry, forgot to mention: each X < = 105
Auto comment: topic has been translated by DeWitt (original revision, translated revision, compare)
Could you share the problem link?
Ignore: this one has interval adding
https://official.contest.yandex.ru/uacamp-online-2016/contest/2872/problems/H4/ I'm not sure whether you are able to enter the contest, so the statement:
I found almost the same problem in hdoj.
http://acm.split.hdu.edu.cn/showproblem.php?pid=5828
However,the author's solution can't pass all tests after data enhancement.I found most accepted solution before data enhancement used this way:
1.build a segtree to store the sum,maximum and minimum value in an interval.
2.increase and get sum operation equals to normal segtree operations.
3.In an interval,if maximum value equals to the minimum value,the sqrt operation only covers interval by the same value.
4.If sqrt(maximum)-sqrt(minimum)==1 ,the sqrt operation equals to subtraction operation.
5.If sqrt(maximum)-sqrt(minimum)==0 ,the sqrt operation equals to interval cover.
6.else just recursion down.Due to the number of times need to get a number sqrted to 1 is small,the efficient is not too slow.
Here is one of the code passed before data enhancement.
/*****************************************************/
You forgot to mention that for step 4 we need maximum == minimum + 1
Auto comment: topic has been updated by DeWitt (previous revision, new revision, compare).