标签:+= string can case str include mat class col
#include<iostream> #include<cstring> #include<cstdio> #include<math.h> #include<algorithm> using namespace std; typedef long long ll; const int N=1e5+10; ll a[N]; int n,m; int op,l,r; struct node { ll l,r; ll sum; }tr[N*4]; void build(int root,int l, int r) { tr[root]={l,r}; tr[root].sum=0; if(l==r) { tr[root].sum=a[l]; return; } int mid=l+r>>1; build(root<<1,l,mid); build(root<<1|1,mid+1,r); tr[root].sum=tr[root<<1].sum+tr[root<<1|1].sum; } void update(int root,int l,int r) { if(l>tr[root].r||tr[root].l>r) return; if (tr[root].sum==(tr[root].r-tr[root].l + 1)) return; if (tr[root].l==tr[root].r) { tr[root].sum=sqrt(tr[root].sum); return; } int mid=tr[root].l+tr[root].r>>1; update(root<<1,l,r); update(root<<1|1,l,r); tr[root].sum=tr[root<<1].sum+tr[root<<1|1].sum; } ll Query(int root,int l,int r) { if (l>tr[root].r||tr[root].l>r) return 0; if (l<=tr[root].l&&tr[root].r<=r) return tr[root].sum; int mid=tr[root].l+tr[root].r>>1; ll res=0; res+=Query(root<<1,l,r); res+=Query(root<<1|1,l,r); return res; } int main() { int cnt=0; while(~scanf("%d",&n)) { printf("Case #%d:\n",++cnt); for (int i=1;i<=n;i++) scanf("%lld",&a[i]); scanf("%d",&m); build(1,1,n); while (m--) { scanf("%d%d%d",&op,&l,&r); if(l>r) swap(l,r); if(op==0) update(1,l,r); else printf("%lld\n",Query(1,l,r)); } printf("\n"); } return 0; }
Can you answer these queries? HDU - 4027 有点坑
标签:+= string can case str include mat class col
原文地址:https://www.cnblogs.com/QingyuYYYYY/p/12293982.html