Pagini recente » Cod sursa (job #226097) | Cod sursa (job #2933429) | Cod sursa (job #1669874) | Cod sursa (job #690650) | Cod sursa (job #2564792)
#include <fstream>
using namespace std;
ifstream fin("aib.in");
ofstream fout("aib.out");
int n, m, aib[100005];
void update(int x, int poz) {
while(poz <= n) {
aib[poz] += x;
poz += (poz & -poz);
}
}
int query(int poz) {
int res = 0;
while(poz > 0) {
res += aib[poz];
poz -= (poz & -poz);
}
return res;
}
void citire() {
fin >> n >> m;
int x;
for(int i = 1; i <= n; i++) {
fin >> x;
update(x, i);
}
}
int main() {
citire();
int t, a, b;
while(m--) {
fin >> t;
if(t == 2) {
fin >> a;
fout << 1 << '\n';
} else {
fin >> a >> b;
if(t == 0)
update(b, a);
else
fout << query(b)-query(a-1) << '\n';
}
}
}