Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef int ll;
- typedef unsigned long long ull;
- typedef pair<ll,ll>pll;
- typedef pair<ll,pair<ll,ll>>plll;
- #define F first
- #define S second
- #define sf scanf
- #define pf printf
- const int Max = 1e5+10;
- ll tree[100000];
- ll query(ll idx)
- {
- ll sum=0;
- while(idx>0)
- {
- sum+=tree[idx];
- idx -= idx & (-idx);
- }
- return sum;
- }
- void update(ll idx, ll x, ll n)
- {
- while(idx<=n)
- {
- tree[idx]+=x;
- idx += idx & (-idx);
- }
- }
- int main()
- {
- ll t,cs=1;
- sf("%d",&t);
- while(t--)
- {
- pf("Case ");
- pf("%d",cs++);
- pf(":\n");
- ll n,q;
- sf("%d %d",&n,&q);
- ll ara[n+10];
- ara[0]=0;
- for(ll i=1; i<=n; i++)
- {
- sf("%d",&ara[i]);
- update(i,ara[i],n);
- }
- while(q--)
- {
- ll a;
- sf("%d",&a);
- if(a==1)
- {
- ll p;
- sf("%d",&p);
- pf("%d\n",ara[p+1]);
- update(p+1,-ara[p+1],n);
- ara[p+1]=0;
- }
- else if(a==2)
- {
- ll p,val;
- sf("%d %d",&p,&val);
- ara[p+1]=ara[p+1]+val;
- update(p+1,val,n);
- }
- else
- {
- ll l,r;
- sf("%d %d",&l,&r);
- l++;
- r++;
- pf("%d\n",query(r)-query(l-1));
- }
- }
- for(ll i=1; i<=n; i++)
- {
- tree[i]=0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement