Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- #include <stdio.h>
- #include <cstring>
- #include <vector>
- #include <algorithm>
- #include <utility>
- #include <queue>
- #include <map>
- #include <stack>
- #include <cmath>
- #include <set>
- #include <ctype.h>
- #include <bitset>
- #include <iomanip>
- #define INF 0x3F3F3F3F
- #define rep(i, a, b) for (int i = int(a); i < int(b); i++)
- #define pb push_back
- #define pi 3.1415926535897932384626433832795028841971
- #define debug(x) if(1) cout << __LINE__ <<"| "<< #x " = " << (x) << endl;
- #define debug2(x,y) if(1) cout << __LINE__ <<"| "<< #x " = " << (x) \
- <<", " << #y " = " << (y) << endl;
- #define all(S) (S).begin(), (S).end()
- #define F first
- #define S second
- #define EPS 1e-9
- #define mp make_pair
- // freopen("in.txt", "r", stdin);
- // freopen("out.txt", "w", stdout);
- using namespace std;
- typedef long long ll;
- typedef pair < int, int > ii;
- int N, BIT[520000];
- void update(int x, int v){
- while(x <= N)
- {
- BIT[x] += v;
- x += x&-x;
- }
- }
- int query(int x) {
- int ans = 0;
- while(x > 0) {
- ans += BIT[x];
- x -= x&-x;
- }
- return ans;
- }
- int main(){
- int x;
- char op;
- int v[100005];
- memset(BIT, 0, sizeof(BIT));
- while(cin >> N)
- {
- rep(i,1,N+1)
- {
- cin >> v[i];
- update(i,v[i]); // inicializando pos i com v[i]
- }
- while(cin >> op)
- {
- cin >> x;
- if(op == 'a')
- update(x,-v[x]); // setando pos x com 0
- else
- cout << query(x-1) << "\n"; // soma atrás da pos x
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement