标签:image asi rom tput scribe please date follow where
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 7069 Accepted Submission(s): 2635
因为右结点的第x元素下标在父结点中应该对应的是第(x+左结点的元素个数)个元素(i为右边结点的下标),可以自己模拟下,就会了,即i=(x+cnt)%5,x=(5*n+i-cnt)%5,取模是为了防止负数
每次查询时只需要返回node[1].sum[2]即可
1 #include<stdio.h> 2 #include<string.h> 3 #include<algorithm> 4 using namespace std; 5 #define ll long long 6 const int maxn = 1e5+7; 7 char str[maxn][4]; 8 int a[maxn],b[maxn]; 9 struct node 10 { 11 int l, r; 12 ll s[10]; 13 int num; 14 } t[maxn * 4]; 15 void build(int rt, int l, int r) 16 { 17 t[rt].l = l; 18 t[rt].r = r; 19 memset(t[rt].s, 0, sizeof(t[rt].s)); 20 if(l == r) 21 { 22 t[rt].num = 0; 23 return ; 24 } 25 int mid = (l + r) >> 1; 26 build(rt<<1, l, mid); 27 build(rt<<1|1, mid + 1, r); 28 t[rt].num = 0; 29 30 memset(t[rt].s, 0, sizeof(t[rt].s)); 31 32 } 33 void update(int rt, int loc, int val, int op) 34 { 35 op == 1 ? t[rt].num ++ : t[rt].num--; 36 if(t[rt].l == t[rt].r) 37 { 38 t[rt].s[0] = op * val; 39 return ; 40 } 41 int mid = (t[rt].l + t[rt].r) >> 1; 42 if(loc <= mid) 43 update(rt<<1, loc, val, op); 44 else 45 update(rt<<1|1, loc, val, op); 46 for(int i = 0; i < 5; i++) 47 { 48 t[rt].s[i] = t[rt<<1].s[i] + t[rt<<1|1].s[((i - t[rt<<1].num) % 5 + 5) % 5]; 49 } 50 } 51 52 int main() 53 { 54 55 int n; 56 while(~scanf("%d", &n)) 57 { 58 int len = 0; 59 60 for(int i = 0; i < n; i ++) 61 { 62 scanf("%s", str[i]); 63 if(str[i][0] != ‘s‘) 64 { 65 scanf("%d", &a[i]); 66 b[len ++] = a[i]; 67 } 68 } 69 sort(b,b+len); 70 len = unique(b,b+len) - b; 71 build(1,1,len); 72 for(int i = 0; i < n; i ++) 73 { 74 if(str[i][0] == ‘a‘) 75 { 76 int x=lower_bound(b,b+len,a[i])-b+1; 77 update(1, x, a[i], 1); 78 } 79 if(str[i][0] == ‘d‘) 80 { 81 int x=lower_bound(b,b+len,a[i])-b+1; 82 update(1, x, a[i], 0); 83 } 84 if(str[i][0] == ‘s‘) 85 { 86 printf("%I64d\n", t[1].s[2]); 87 } 88 } 89 90 91 } 92 return 0; 93 }
标签:image asi rom tput scribe please date follow where
原文地址:https://www.cnblogs.com/yuanlinghao/p/10849695.html