[Bzoj3038] 7 Fenzhong God made the theme of 2

Consider each open position up to about six times would be over, and then the operation does not make sense, so the tree line and maintenance intervals and a flag indicating whether all are 1, and then to modify, if not the range of 1 to mark violence continues, 1 would not operate, complexity is $ (6nlogn) o $

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define N 100005
 4 #define ll long long
 5 #define L (k<<1)
 6 #define R (L+1)
 7 #define mid (l+r>>1)
 8 int n,m,p,l,r,laz[N<<2];
 9 ll f[N<<2];
10 void up(int k){
11     laz[k]=(laz[L]&laz[R]);
12     f[k]=f[L]+f[R]; 
13 }
14 void build(int k,int l,int r){
15     if (l==r){
16         scanf("%lld",&f[k]);
17         if (f[k]==1)laz[k]=1;
18         return;
19     }
20     build(L,l,mid);
21     build(R,mid+1,r);
22     up(k);
23 }
24 void update(int k,int l,int r,int x,int y){
25     if ((l>y)||(x>r))return;
26     if ((x<=l)&&(r<=y)&&(laz[k]))return;
27     if (l==r){
28         f[k]=(ll)sqrt(f[k]);
29         if (f[k]==1)laz[k]=1;
30         return;
31     }
32     update(L,l,mid,x,y);
33     update(R,mid+1,r,x,y);
34     up(k);
35 }
36 ll query(int k,int l,int r,int x,int y){
37     if ((l>y)||(x>r))return 0;
38     if ((x<=l)&&(r<=y))return f[k];
39     return query(L,l,mid,x,y)+query(R,mid+1,r,x,y);
40 }
41 int main(){
42     scanf("%d",&n);
43     build(1,1,n);
44     scanf("%d",&m);
45     for(int i=1;i<=m;i++){
46         scanf("%d%d%d",&p,&l,&r);
47         if (l>r)swap(l,r);
48         if (!p)update(1,1,n,l,r);
49         else printf("%lld\n",query(1,1,n,l,r));
50     }
51 }
View Code

 

Guess you like

Origin www.cnblogs.com/PYWBKTDA/p/11828868.html