Advertisement
Guest User

Untitled

a guest
May 24th, 2015
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.71 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <stdio.h>
  4. #include <cstring>
  5. #include <vector>
  6. #include <algorithm>
  7. #include <utility>
  8. #include <queue>
  9. #include <map>
  10. #include <stack>
  11. #include <cmath>
  12. #include <set>
  13. #include <ctype.h>
  14. #include <bitset>
  15. #include <iomanip>
  16.  
  17. #define INF 0x3F3F3F3F
  18. #define rep(i, a, b) for (int i = int(a); i < int(b); i++)
  19. #define pb push_back
  20. #define pi 3.1415926535897932384626433832795028841971
  21. #define debug(x) if(1) cout << __LINE__ <<"| "<< #x " = " << (x) << endl;
  22. #define debug2(x,y) if(1) cout << __LINE__ <<"| "<< #x " = " << (x) \
  23. <<", " << #y " = " << (y) << endl;
  24. #define all(S) (S).begin(), (S).end()
  25. #define F first
  26. #define S second
  27. #define EPS 1e-9
  28. #define mp make_pair
  29.  
  30. // freopen("in.txt", "r", stdin);
  31. // freopen("out.txt", "w", stdout);
  32.  
  33. using namespace std;
  34.  
  35. typedef long long ll;
  36. typedef pair < int, int >  ii;
  37.  
  38. int N, BIT[520000];
  39.  
  40. void update(int x, int v){
  41.     while(x <= N)
  42.     {
  43.         BIT[x] += v;
  44.         x += x&-x;
  45.     }
  46. }
  47.  
  48. int query(int x) {
  49.     int ans = 0;
  50.     while(x > 0) {
  51.         ans += BIT[x];
  52.         x -= x&-x;
  53.     }
  54.     return ans;
  55. }
  56.  
  57.  
  58. int main(){
  59.  
  60.     int  x;
  61.     char op;
  62.     int v[100005];
  63.      
  64.     memset(BIT, 0, sizeof(BIT));
  65.      
  66.     while(cin >> N)
  67.     {    
  68.         rep(i,1,N+1)
  69.         {
  70.             cin >> v[i];  
  71.             update(i,v[i]); // inicializando pos i com v[i]
  72.         }  
  73.          
  74.         while(cin >> op)
  75.         {
  76.             cin >> x;
  77.             if(op == 'a')
  78.                 update(x,-v[x]); // setando pos x com 0
  79.             else
  80.                 cout << query(x-1) << "\n"; // soma atrás da pos x
  81.         }  
  82.     }
  83.  
  84.     return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement