Pagini recente » Cod sursa (job #2806291) | Cod sursa (job #2852762) | Cod sursa (job #2267822) | Cod sursa (job #125463) | Cod sursa (job #1509100)
#include <fstream>
#define DIM 8912
#define Zero(x) x&(-x)
using namespace std;
ifstream f("baruri.in"); ofstream g("baruri.out");
int n, T, AIB[100001], p[100001];
char BUFF[8200], *now;
inline void Verif()
{
if(*now=='\0')
{
f.get(BUFF, DIM, '\0');
now=BUFF;
}
}
void Get(int &number)
{
while(*now<'0' || *now>'9')
{
now++;
Verif();
}
number=0;
while(*now>='0' && *now<='9')
{
number=number*10+*now-'0';
now++;
Verif();
}
}
inline void Update(int poz, int val)
{
p[poz]+=val;
for(; poz<=n; poz+=Zero(poz)) AIB[poz]+=val;
}
inline int Calc(int poz)
{
int s=0;
for(; poz; poz-=Zero(poz)) s+=AIB[poz];
return s;
}
int main()
{
now=BUFF;
Verif();
Get(T);
for(int k=1; k<=T; k++)
{
Get(n);
for(int v, i=1; i<=n; i++)
{
Get(v); Update(i, v);
p[i]=v;
}
int nr;
Get(nr);
int t, x, b, b2, d;
while(nr--)
{
Get(t);
if(t==0)
{
Get(b); Get(d);
g<<Calc(b+d>n?n:b+d) - Calc(b-d-1<1?0:b-d-1) - p[b];
}
else if(t==1)
{
Get(x); Get(b);
Update(b, x);
}
else if(t==2)
{
Get(x); Get(b);
Update(b, -x);
}
else
{
Get(x); Get(b); Get(b2);
Update(b2, x); Update(b, -x);
}
}
}
return 0;
}