标签:loading 历史 class its using ace val print ref
AC_Code:
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int maxn=1e6+10; 5 const int mod=1e9+9; 6 7 struct Tree{ 8 int l,r,v; 9 }tree[maxn*40]; 10 11 int root[maxn],tot; 12 int n,m; 13 14 int build(int l,int r){ 15 int p=++tot; 16 if( l==r ){ 17 scanf("%d",&tree[p].v); 18 return p; 19 } 20 int mid=(l+r)>>1; 21 tree[p].l=build(l,mid); tree[p].r=build(mid+1,r); 22 tree[p].v=tree[tree[p].l].v+tree[tree[p].r].v; 23 return p; 24 } 25 26 int query(int p,int l,int r,int loc){ 27 if( l==r ) return tree[p].v; 28 int mid=(l+r)>>1; 29 if( loc<=mid ) return query(tree[p].l,l,mid,loc); 30 else return query(tree[p].r,mid+1,r,loc); 31 } 32 33 int update(int now,int l,int r,int x,int value){ 34 int p=++tot; 35 tree[p]=tree[now]; 36 if( l==r ){ 37 tree[p].v=value; 38 return p; 39 } 40 int mid=(l+r)>>1; 41 if( x<=mid ) 42 tree[p].l=update(tree[now].l,l,mid,x,value); 43 else 44 tree[p].r=update(tree[now].r,mid+1,r,x,value); 45 tree[p].v=tree[tree[p].l].v+tree[tree[p].r].v; 46 return p; 47 } 48 49 int main() 50 { 51 scanf("%d%d",&n,&m); 52 root[0]=build(1,n); 53 for(int i=1;i<=m;i++){ 54 int v,p,loc,value; 55 scanf("%d%d%d",&v,&p,&loc); 56 if( p==1 ){ 57 scanf("%d",&value); 58 root[i]=update(root[v],1,n,loc,value); 59 } 60 else{ 61 printf("%d\n",query(root[v],1,n,loc)); 62 root[i]=root[v]; 63 } 64 } 65 return 0; 66 }
标签:loading 历史 class its using ace val print ref
原文地址:https://www.cnblogs.com/wsy107316/p/13362490.html