Mai intai trebuie sa te autentifici.
Cod sursa(job #3138447)
Utilizator | Data | 19 iunie 2023 17:11:39 | |
---|---|---|---|
Problema | Datorii | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.72 kb |
#include <bits/stdc++.h>
using namespace std;
int n, a, b, m, tip;
vector <int> BIT(100001, 0);
void update(int i, int val){
while(i<=n){
BIT[i]+=val;
i+=(i&-i);
}
}
void update1(int i, int val){
while(i<=n){
BIT[i]-=val;
i+=(i&-i);
}
}
int presum(int i){
int sum=0;
while(i>0){
sum+=BIT[i];
i-=(i&-i);
}
return sum;
}
int main(){
ifstream cin ("datorii.in");
ofstream cout ("datorii.out");
cin >> n >> m;
for(int j=1; j<=n; j++){
cin >> a;
update(j,a);
}
for(int j=1; j<=m; j++){
cin >> tip >> a >> b;
if(tip==1) cout << presum(b)-presum(a-1) << "\n";
else update1(a, b);
}
return 0;
}