Topic Link: Portal
The main topic: there is an array of length n, there are m operations, each operation input v x y,v==0 when the number in the X~y interval is open squared and rounded down, v==1 the sum of all the numbers in the X~y interval.
Topic Idea: Long long range of the number of open square not more than 7 times will become 1, so we update when we just look at the X~y interval and is not equal to the length of the interval (all the numbers in the interval is 1), yes
Do not update the direct return, otherwise continue to update downward, this problem pits in the X, y size is not sure, need their own judgment processing (QAQ), here tle half day
This problem gives me a bigger harvest is that line tree does not need to use a struct, directly with the array simulation on the line, convenient and efficient, new skills get. icpc,fighting!
#include <iostream>#include<cstdio>#include<cstdlib>#include<cmath>#include<algorithm>#include<cstring>#include<stack>#include<cctype>#include<queue>#include<string>#include<vector>#include<Set>#include<map>#include<climits>#defineLson Root<<1,l,mid#defineRson Root<<1|1,mid+1,r#defineFi first#defineSe Second#definePing (x, y) ((x-y) * (x-y))#defineMST (x, y) memset (x,y,sizeof (x))#defineMCP (x, y) memcpy (x,y,sizeof (y))#defineMin (x, y) (x<y?x:y)#defineMax (x, y) (x>y?x:y)using namespacestd;#defineGamma 0.5772156649015328606065120#defineMOD 100000007#defineINF 0x3f3f3f3f#defineN 100005#defineMAXN 10001000typedefLong LongLl;typedef pair<int,int>PII; LL Node[n<<2];intx, y;voidBuildintRootintLintR) { if(l==R) {scanf ("%lld",&Node[root]); return; } intMid=l+r>>1; Build (Lson); Build (Rson); Node[root]=node[root<<1]+node[root<<1|1];}voidAddintRootintLintR) { if(x<=l&&r<=y&&node[root]==r-l+1)return; if(L==R) {node[root]=sqrt (node[root]);return;} intMid=l+r>>1; if(y<=mid) Add (Lson); Else if(x>mid) Add (Rson); Else{Add (Lson); Add (Rson); } Node[root]=node[root<<1]+node[root<<1|1];} LL Query (intRootintLintR) { if(x<=l&&r<=y)returnNode[root]; intMid=l+r>>1; if(Y<=mid)returnquery (Lson); Else if(X>mid)returnquery (Rson); Else returnQuery (Lson) +query (Rson);}intMain () {intN,m,i,j,v,group,case=0; LL ans; while(~SCANF ("%d",&Group)) {printf ("Case #%d:\n",++Case ); Build (1,1, group); scanf ("%d",&m); for(i=0; i<m;++i) {scanf ("%d%d%d",&v,&x,&y); if(x>y) x^=y^=x^=y; if(!v) Add (1,1, group); Elseprintf"%lld\n", Query (1,1, group)); } printf ("\ n"); } return 0;}
HDU4027 (Can You answer these queries?)