Created
March 8, 2014 04:46
-
-
Save fferegrino/9425502 to your computer and use it in GitHub Desktop.
Funny Marbles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
long long ac [1000001]; | |
void update(int ix, int val, int n){ | |
int nv = val; | |
for(; ix < n + 1; ix += (ix & -ix)) | |
ac[ix] += val; | |
} | |
long long query(int ix){ | |
long long r = 0; | |
while(ix){ | |
r += ac[ix]; | |
ix -= (ix & -ix); | |
} | |
return r; | |
} | |
int main(){ | |
int N, Q, a, i, j; | |
char opt; | |
cin >> N; | |
cin >> Q; | |
for(int i = 1; i < N +1; i++){ | |
cin >> a; | |
update(i, a, N); | |
} | |
while(Q--){ | |
cin >> opt; | |
cin >> i; | |
cin >> j; | |
if(opt == 'S') | |
cout << query(j+1) - query(i) << endl; | |
else | |
update(i+1,(opt == 'T' ? -j : j),N); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment