Description Input Output
Each time x=1, an integer per line indicates the pleasure of this trip
Sample Input4
1 100 5 5
5
1 1 2
2 1 2
1 1 2
2 2 3
1 1 4
Sample Output101
11
11 "Analysis" start with a look at the line tree that can be done. Later look at the puzzle with a tree array instantaneous seconds ... orzzz, notice that any int can change to 1 in a very small number of times, so the direct violence single point modification will become 1 of the number of the parent set to its right. Note that there may be a lot of 0 in the input .... Direct write optimization is not good for T.
1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <cstring>5#include <vector>6#include <utility>7#include <iomanip>8#include <string>9#include <cmath>Ten#include <queue> One#include <map> A - Const intMAXN =100000+Ten; - Const intMAX =30000+Ten; the using namespacestd; -typedefLong Longll; - intN; - ll C[MAXN]; + intDATA[MAXN], PARENT[MAXN]; - + intSQRT (intx) {return(int) Floor (sqrt (Double) x *1.0));} A intLowbit (intx) {returnX &-x;} at voidAddintXintval) { - while(x <=N) { -C[X] + =Val; -X + =lowbit (x); - } - return; in } -ll sum (intx) { toll cnt =0; + while(X >0){ -CNT + =C[x]; theX-=lowbit (x); * } $ returnCNT;Panax Notoginseng } - intFindintx) {returnPARENT[X] = = x? X:PARENT[X] =find (Parent[x]);} the voidinit () { +memset (C,0,sizeof(C)); Ascanf"%d", &n); the for(inti =1; I <= N; i++){ +scanf"%d", &data[i]); - Add (i, data[i]); $Parent[i] =i; $ if(Data[i] = =1|| Data[i] = =0) Parent[i] = i +1; - } -Parent[n +1] = n +1; the } - voidWork () {Wuyi intQ; thescanf"%d", &q); - for(inti =1; I <= Q; i++){ Wu intT, x, y; -scanf"%d%d%d", &t, &x, &y); About if(T = =1) printf ("%lld\n", sum (y)-sum (X-1)); $ Else{ - for(inti = x; I <= y; i = find (i +1)){ - intTMP =Data[i]; -Data[i] =SQRT (Data[i]); AAdd (i, data[i]-tmp); + if(Data[i] <=1) Parent[i] = find (i +1); the } - } $ } the } the the intMain () { the intT; - #ifdef LOCAL inFreopen ("Data.txt","R", stdin); theFreopen ("OUT.txt","W", stdout); the #endif About init (); the Work (); the return 0; the}
View Code
"BZOJ3211" "and check set + Tree array" Flower Gods travel around the world