Pagini recente » Cod sursa (job #1827557) | Cod sursa (job #1497915) | Cod sursa (job #82134) | Cod sursa (job #234390) | Cod sursa (job #1200983)
using namespace std;
#include <fstream>
ifstream fin("datorii.in");
ofstream fout("datorii.out");
const int Nmax = 15000;
int n;
int v[Nmax+5], AIB[Nmax+5];
void update(int, int) ;
int query(int) ;
int main()
{
int i, m, a, b, tip;
fin >> n >> m;
for(i = 1; i <= n; ++i) {fin >> v[i]; update(i, -v[i]);}
for( ; m; --m)
{
fin >> tip >> a >> b;
if(tip == 0) update(a, b);
else fout << query(b) - query(a-1) << '\n';
}
return 0;
}
void update(int poz, int x)
{
//s-a achitat x lei in ziua poz
v[poz] -= x;
while(poz <= n) {AIB[poz] -= x; poz += poz & -poz;}
}
int query(int poz)
{
//returneaza v[1] + v[2] + ... + v[poz]
int s = 0;
while(poz > 0) {s += AIB[poz]; poz &= poz-1;}
return s;
}