2492 God-made questions for seven minutes 2
time limit: 1 sspace limit: 64000 KBtopic rank: Master Master Title Description
Description
Xlk that "God made the seven minutes of the problem" is not very enjoyable, so there is the second part.
"In the first minute, X says, to have a sequence, a positive integer sequence is given."
The second minute, L said, to be able to modify, so there is a number of each number in the square (the next rounding) operation.
The third minute, K said, to be able to query, so there is to seek a number of operations.
Four minutes, Rainbow Meow said, if Noip difficulty, so there is the data range.
Five minutes, the poet said, to have rhyme, so there is time limit and memory limit.
Six minutes, and the snow said, to save things, so there is a guarantee in the process and the final result does not exceed the 64-bit signed integer type of the range of the limit.
The first seven minutes, the problem was finally finished, however, the god of the cows do not want to write the problem of the program. "
--seven minutes of God's problems • Part II
So this sacred mission is yours.
Enter a description
Input Description
The first line is an integer n, which represents the number of numbers in the sequence.
The second row n positive integers that represent the number in the initial state of the sequence.
The third line, an integer m, indicates that there is an M operation.
The next m line is three integers per line k,l,r,k=0 for each number in [l,r] squared (rounded down), and K=1 is asking for the sum of each number in [L,r].
UPD: Note that the data may be l>r, so in this case, swap L and R.
Output description
Output Description
For the inquiry operation, each line outputs an answer.
Sample input
Sample Input
10
1 2 3 4 5 6 7 8 9 10
5
0 1 10
1 1 10
1 1 5
0 5 8
1 4 8
Sample output
Sample Output
19
7
6
Data range and Tips
Data Size & Hint
For 30% of the data, 1<=n,m<=1000, the number in the series does not exceed 32767.
For 100% of the data, 1<=n,m<=100000,1<=l,r<=n, the number in the sequence is greater than 0, and no more than 1e12.
Note that L may be greater than r, and in this case please exchange l,r.
Exercises
To add optimizations.
Code:
1 /*2 optimization is if a node value of 0 or 1 is no longer updated;3 if the son of a tree is no longer updated, it is no longer updated4 */5 #defineMAXN 100000*2+1006#include <cstdio>7#include <cmath>8#include <iostream>9#include <algorithm>Ten One using namespacestd; A - structSS - { the intl; - intR; - intls; - intrs; + intBoo; - Long Longsum; + }TR[MAXN]; A at intN,m,cnt=0; - - voidXds_built (intLintR) - { - inti=i+CNT; -tr[k].ls=l; intr[k].rs=R; - if(r-l==1) to { +scanf"%lld",&tr[k].sum); - if(tr[k].sum<2) tr[k].boo=1; the return; * } $tr[k].l=cnt+1;Panax NotoginsengXds_built (L, (l+r) >>1); -tr[k].r=cnt+1; theXds_built (l+r) >>1, R); +tr[k].sum=tr[tr[k].l].sum+tr[tr[k].r].sum; A if(Tr[tr[k].l].boo&&tr[tr[k].r].boo) tr[k].boo=1; the } + - voidXds_change (intKintLintR) $ { $ if(Tr[k].boo)return; - if(tr[k].rs-tr[k].ls==1) - { theTR[K].SUM=SQRT (Double(Tr[k].sum)); - if(tr[k].sum<2) tr[k].boo=1;Wuyi return; the } - intLl=tr[k].ls,rr=tr[k].rs; Wu if(l< (LL+RR) >>1)) Xds_change (Tr[k].l,l,min (LL+RR) >>1, R)); - if(R> (LL+RR) >>1)) Xds_change (Tr[k].r,max (LL+RR) >>1, L), R); Abouttr[k].boo=tr[tr[k].l].boo&Tr[tr[k].r].boo; $tr[k].sum=tr[tr[k].l].sum+tr[tr[k].r].sum; - } - - Long LongXds_sum (intKintLintR) A { + if(L<=TR[K].LS&&TR[K].RS<=R)returntr[k].sum; the intLl=tr[k].ls,rr=tr[k].rs; - Long Longans=0; $ if(l< (LL+RR) >>1)) ans+=xds_sum (tr[k].l,l,r); the if(R> (LL+RR) >>1)) ans+=xds_sum (TR[K].R,L,R); the returnans; the } the - intMain () in { thescanf"%d",&n); theXds_built (1, n+1); Aboutscanf"%d",&m); the for(intI=1; i<=m;i++) the { the Long LongX,l,r; +scanf"%lld%lld%lld",&x,&l,&R); - if(l>r) Swap (L,R); the if(!x)BayiXds_change (1, l,r+1); the Else theprintf"%lld\n", Xds_sum (1, l,r+1)); - } - return 0; the } the
C + + Path Step--line tree (seven minutes of God-made questions 2)