Cod sursa(job #2441408)
Utilizator | Ursu Ianis Vlad uvIanis | Data | 20 iulie 2019 13:59:49 |
---|---|---|---|
Problema | Datorii | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.37 kb |
#include <fstream>
int n, m, c, x, y, i, j, s, t[15001];std::ifstream f("datorii.in"); std::ofstream o("datorii.out");int main(){f>>n>>m;for(i=1; i<=n; i++){f>>x; for(j=i; j<=n; j += (j&-j)) t[j]+=x;}for(i=1; i<=m; i++){f>>c>>x>>y;if(c) {s = 0;for(j=y; j>0; j-= (j&-j)) s+= t[j];for(j=x-1; j>0; j-=(j&-j)) s -= t[j];o<<s<<"\n";} else{for(j=x; j<=n; j += (j&-j)) t[j]-=y;}}}