fork download
  1. //team: iiitians
  2.  
  3. #include <stdio.h>
  4. int ans = 0,n,tree[1000002];
  5. inline void fun(int x) {
  6. if (x > n) {
  7. return ;
  8. }
  9. fun(x*2);
  10. if (tree[x] == 0) {
  11. ans++;
  12. }
  13. fun((x*2)+1);
  14. }
  15. int main() {
  16. int q;scanf("%d%d",&n,&q);
  17. int i;
  18. for (i = 0; i < n-1; i++) {
  19. int a,b;scanf("%d%d",&a,&b);
  20. }
  21. for (i = 1; i < n+1; i++) {
  22. scanf("%d",&tree[i]);
  23. }
  24. for (i = 0; i < q; i++) {
  25. char c = getchar();
  26. if (c == 'U') {
  27. int x,v;scanf("%d%d",&x,&v);
  28. tree[x] = tree[x] + v;
  29. }
  30. else if (c == 'Q') {
  31. ans = 0;
  32. int x;scanf("%d",&x);
  33. fun(x);
  34. printf("%d\n",ans);
  35. }
  36. }
  37. return 0;
  38. }
Success #stdin #stdout 0s 6200KB
stdin
10 2
1 2
1 3
1 4
2 5
2 6
2 7
6 8
6 9
6 10
1 2 3 4 5 6 7 8 9 0
Q 6
Q 5
stdout
0
1