Pagini recente » Cod sursa (job #613061) | Cod sursa (job #1772526) | Cod sursa (job #311612) | Cod sursa (job #10224) | Cod sursa (job #2502325)
#include <fstream>
#include <cctype>
#include <cstdio>
using namespace std;
FILE *fin = fopen("datorii.in", "r");
ofstream fout("datorii.out");
const int bsize = 1<<16;
int poz = bsize;
char buff[bsize];
inline char next()
{
if (poz == bsize)
{
fread(buff, 1, bsize, fin);
poz = 0;
}
return buff[poz++];
}
int nr()
{
int x = 0;
char c;
do
{
c = next();
} while (isdigit(c) == 0);
while (isdigit(c))
{
x = x * 10 + c-48;
c = next();
}
return x;
}
int arb[1<<15];
int a, b;
void update (int nod, int st, int dr)
{
if (st == dr)
arb[nod] = b;
else
{
int mij = (st+dr)>>1;
if (a <= mij)
update (nod<<1, st, mij);
else
update (nod<<1|1, mij+1, dr);
arb[nod] = arb[nod<<1] + arb[nod<<1|1];
}
}
int query(int nod, int st, int dr)
{
if (a <= st && dr <= b)
return arb[nod];
else
{
int eins = 0, zwei = 0, mij = (st+dr)>>1;
if (a <= mij)
eins = query(nod<<1, st, mij);
if (mij < b)
zwei = query(nod<<1|1, mij+1, dr);
return eins + zwei;
}
}
int main()
{
int n, i, m, v[15001], t;
n = nr();
m = nr();
for (a = 1; a<=n; a++)
{
v[a] = nr();
b = v[a];
update(1, 1, n);
}
for (i = 1; i<=m; i++)
{
t = nr();
a = nr();
b = nr();
if (t == 0)
{
v[a] = v[a] - b;
b = v[a];
update(1, 1, n);
}
else
fout << query(1, 1, n) << '\n';
}
return 0;
}