Pagini recente » Cod sursa (job #1890383) | Cod sursa (job #2601298) | Cod sursa (job #2873939) | Borderou de evaluare (job #1330650) | Cod sursa (job #2322179)
#include <bits/stdc++.h>
#define maxn 15000
#define maxl2 14
using namespace std;
struct ait {int st, dr, sum, ind;};
int v[maxn+5];
ait aint[maxn*maxl2+5];
vector <ait> qu;
int lst[maxn+5];
void pb ( int s, int d, int m, int i )
{
ait x;
x.st = s; x.dr = d; x.sum = m; x.ind = i;
if ( x.st <= x.dr )
qu.push_back ( x );
if ( x.st == x.dr )
lst[s] = i;
}
int main ()
{
ifstream fin ( "datorii.in" );
ofstream fout ( "datorii.out" );
int n, m;
fin >> n >> m;
int i;
for ( i = 1; i <= n; i++ )
fin >> v[i];
int lo = 0, mid;
pb ( 1, n, 0, 1 );
while ( lo < qu.size() )
{
aint[qu[lo].ind] = qu[lo];
mid = ( qu[lo].st + qu[lo].dr ) / 2;
if ( qu[lo].st < qu[lo].dr )
{
pb ( qu[lo].st, mid, 0, qu[lo].ind * 2 );
pb ( mid + 1, qu[lo].dr, 0, qu[lo].ind * 2 + 1 );
}
lo++;
}
int nod;
for ( i = 1; i <= n; i++ )
for ( nod = lst[i]; nod > 0; nod /= 2 )
aint[nod].sum += v[i];
int id, a, b, oth, s;
for ( ; m > 0; m-- )
{
fin >> id >> a >> b;
if ( id == 0 )
{
nod = lst[a];
aint[nod].sum -= b;
for ( ; nod > 1; nod /= 2 )
{
oth = nod + 1;
if ( nod % 2 == 1 ) oth = nod - 1;
aint[nod/2].sum = aint[nod].sum + aint[oth].sum;
}
}
else
{
s = 0;
while ( a <= b )
{
nod = lst[a];
while ( nod > 1 && aint[nod/2].st == a && aint[nod/2].dr <= b )
nod /= 2;
s += aint[nod].sum;
a = aint[nod].dr + 1;
}
fout << s << '\n';
}
}
fin.close ();
fout.close ();
return 0;
}