标签:++ problem stdout freopen logs const name type arch
每次x=1时,每行一个整数,表示这次旅行的开心度
对于100%的数据, n ≤ 100000,m≤200000 ,data[i]非负且小于10^9
1 #include "bits/stdc++.h" 2 #define lson rt<<1,l,m 3 #define rson rt<<1|1,m+1,r 4 using namespace std; 5 typedef long long LL; 6 const int MAX=1e5+5; 7 LL n,m; 8 LL sum[MAX<<2],flag[MAX<<2]; 9 inline LL read(){ 10 int an=0,x=1;char c=getchar(); 11 while (c<‘0‘ || c>‘9‘) {if (c==‘-‘) x=-1;c=getchar();} 12 while (c>=‘0‘ && c<=‘9‘) {an=(an<<3)+(an<<1)+c-‘0‘;c=getchar();} 13 return an*x; 14 } 15 void PushUp(int rt){ 16 sum[rt]=sum[rt<<1]+sum[rt<<1|1]; 17 flag[rt]=flag[rt<<1]&flag[rt<<1|1]; 18 } 19 void build(int rt,int l,int r){ 20 if (l==r){ 21 sum[rt]=read(); 22 if (sum[rt]<=1) flag[rt]=1; 23 else flag[rt]=0; 24 return; 25 } 26 int m=(l+r)>>1; 27 build(lson); 28 build(rson); 29 PushUp(rt); 30 } 31 void update(int rt,int l,int r,int x,int y){ 32 if (flag[rt]) return; 33 if (l==r){ 34 sum[rt]=(LL)sqrt(sum[rt]*1.0); 35 if (sum[rt]<=1) flag[rt]=1; 36 return; 37 } 38 int m=(l+r)>>1; 39 if (x<=m) update(lson,x,y); 40 if (y>m) update(rson,x,y); 41 PushUp(rt); 42 } 43 LL query(int rt,int l,int r,int x,int y){ 44 if (x<=l && r<=y) return sum[rt]; 45 LL tmp=0; 46 int m=(l+r)>>1; 47 if (x<=m) tmp+=query(lson,x,y); 48 if (y>m) tmp+=query(rson,x,y); 49 return tmp; 50 } 51 int main(){ 52 freopen ("flower.in","r",stdin);freopen ("flower.out","w",stdout); 53 int i,j,x,y,z; 54 n=read();build(1,1,n); 55 m=read(); 56 for (i=1;i<=m;i++){ 57 z=read(),x=read(),y=read(); 58 if (z==1) printf("%lld\n",query(1,1,n,x,y)); 59 else update(1,1,n,x,y); 60 } 61 return 0; 62 }
标签:++ problem stdout freopen logs const name type arch
原文地址:http://www.cnblogs.com/keximeiruguo/p/7746514.html