标签:des style blog http color os java io strong
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 8501 Accepted Submission(s):
1942
#include<iostream> #include<cmath> #include<cstdio> #include<memory.h> using namespace std; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define maxn 100000+10 #define ll long long ll sum[maxn<<2]; ll cnt[maxn<<2]; void pushUp(int rt) { sum[rt] = sum[rt<<1] + sum[rt<<1|1]; cnt[rt] = cnt[rt<<1] && cnt[rt<<1|1]; } void build(int l,int r,int rt) { if(l == r) { scanf("%I64d",&sum[rt]); return ; } int m = (l + r)>>1; build(lson); build(rson); pushUp(rt); } void update(int L,int R,int l,int r,int rt) { if(l == r) { sum[rt] = sqrt(sum[rt]+0.0); if(sum[rt] <= 1) cnt[rt] = 1; return ; } int m = (l + r)>>1; if(L <= m && !cnt[rt<<1]) update(L,R,lson); if(R > m && !cnt[rt<<1|1]) update(L,R,rson); pushUp(rt); } ll query(int L,int R,int l,int r,int rt) { if(L <= l && r <= R) { return sum[rt]; } ll ret = 0; int m = (l + r)>>1; if(L <= m) ret += query(L,R,lson); if(R > m) ret += query(L,R,rson); return ret; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); #endif int n,m,l,r; int step = 1,flag; while(~scanf("%d",&n)) { memset(sum,0,sizeof(sum)); memset(cnt,0,sizeof(cnt)); build(1,n,1); printf("Case #%d:\n",step++); scanf("%d",&m); while(m--) { scanf("%d%d%d",&flag,&l,&r); if(l > r) swap(l,r); if(flag == 0) update(l,r,1,n,1); else printf("%I64d\n",query(l,r,1,n,1)); } printf("\n"); } return 0; }
dengyaolong教的不用关重定向的新技能,宏 ~\(≧▽≦)/~ 我要好好努力,开开心心AC~~~~
hdu 4027 Can you answer these queries?
标签:des style blog http color os java io strong
原文地址:http://www.cnblogs.com/imLPT/p/3941501.html