Pagini recente » Cod sursa (job #263022) | Cod sursa (job #2485996) | Cod sursa (job #450102) | Cod sursa (job #746001) | Cod sursa (job #1339021)
// datorii
#include <iostream>
#include <fstream>
#define NMax 15005
using namespace std;
ifstream f("datorii.in");
ofstream g("datorii.out");
int n, m;
int B[NMax];
inline int lastZeros(int x) {
for (int i=0;i<20;i++)
if (x & (1<<i))
return i;
return 0;
}
int query(int pos) {
int sum = 0;
while (pos >= 1) {
sum+=B[pos];
pos -= (1<<lastZeros(pos));
}
return sum;
}
void update(int value, int pos) {
while (pos <= n) {
B[pos]+=value;
pos += (1<<lastZeros(pos));
}
}
void read() {
f>>n>>m;
for (int i=1;i<=n;i++) {
int x; f>>x;
update(x,i);
}
for (int i=1;i<=m;i++) {
int type; f>>type;
if (type == 0) {
int t,v;
f>>t>>v;
update(-v, t);
} else if (type == 1) {
int p,q;
f>>p>>q;
// Query
g<<query(q)-query(p-1)<<'\n';
}
}
}
int main() {
read();
f.close(); g.close();
return 0;
}