This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<ll,ll>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxN=3e5;
const ll inf=1e18;
const ll mod=1e9+7;
struct node
{
ll sum,pre;
node()
{
sum=0,pre=0;
}
node operator+(const node&o)
{
node ans;
ans.sum=sum+o.sum;
ans.pre=min(pre,sum+o.pre);
return ans;
}
}st[4*maxN];
ll q;
void update(ll pos,ll val,ll id=1,ll l=1,ll r=q)
{
if(l==r)
{
st[id].sum+=val;
st[id].pre=min(st[id].sum,0ll);
return;
}
ll mid=l+r>>1;
if(pos<=mid) update(pos,val,id*2,l,mid);
else update(pos,val,id*2+1,mid+1,r);
st[id]=st[id*2]+st[id*2+1];
}
node get(ll i,ll j,ll id=1,ll l=1,ll r=q)
{
if(j<l||r<i) return node();
if(i<=l&&r<=j) return st[id];
ll mid=l+r>>1;
return get(i,j,id*2,l,mid)+get(i,j,id*2+1,mid+1,r);
}
ll seg[4*maxN];
void upd(ll pos,ll val,ll id=1,ll l=1,ll r=q)
{
if(l==r)
{
seg[id]+=val;
return;
}
ll mid=l+r>>1;
if(pos<=mid) upd(pos,val,id*2,l,mid);
else upd(pos,val,id*2+1,mid+1,r);
seg[id]=seg[id*2]+seg[id*2+1];
}
ll gt(ll i,ll j,ll id=1,ll l=1,ll r=q)
{
if(j<l||r<i) return 0;
if(i<=l&&r<=j) return seg[id];
ll mid=l+r>>1;
return gt(i,j,id*2,l,mid)+gt(i,j,id*2+1,mid+1,r);
}
ll quer(ll x)
{
ll l=1,r=q,id=1;
while(true)
{
ll mid=l+r>>1;
if(l==r) return l;
if(x>seg[id*2])
{
x-=seg[id*2];
id=id*2+1;
l=mid+1;
}
else
{
id=id*2;
r=mid;
}
}
}
ll n,m,c[maxN];
vector<pli>in[maxN],add[maxN],vec[maxN];
ll ans[maxN];
ll vc[maxN];
void solve()
{
cin >> n >> m >> q;
for(int i=1;i<=q;i++)
{
ll t;
cin >> t;
vc[i]=t;
if(t==1)
{
ll l,r,k;
cin >> l >> r >> c[i] >> k;
in[l].pb({i,k});
in[r+1].pb({i,-k});
add[l].pb({i,k});
add[r+1].pb({i,-k});
}
else if(t==2)
{
ll l,r,k;
cin >> l >> r >> k;
in[l].pb({i,-k});
in[r+1].pb({i,k});
}
else
{
ll a,b;
cin >> a >> b;
vec[a].pb({i,b});
}
}
for(int i=1;i<=n;i++)
{
for(auto zz:in[i])
{
update(zz.fi,zz.se);
}
for(auto zz:add[i])
{
upd(zz.fi,zz.se);
}
for(auto zz:vec[i])
{
auto cc=get(1,zz.fi);
ll con=cc.sum-cc.pre;
if(con>=zz.se)
{
ll dm=gt(1,zz.fi)-(con-zz.se);
ans[zz.fi]=c[quer(dm)];
}
else
{
ans[zz.fi]=0;
}
}
}
for(int i=1;i<=q;i++)
{
if(vc[i]==3)
{
cout << ans[i]<<'\n';
}
}
}
int main()
{
fastio
//freopen(TASKNAME".INP","r",stdin);
//freopen(TASKNAME".OUT","w",stdout);
solve();
}
Compilation message (stderr)
foodcourt.cpp: In function 'void update(ll, ll, ll, ll, ll)':
foodcourt.cpp:37:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
37 | ll mid=l+r>>1;
| ~^~
foodcourt.cpp: In function 'node get(ll, ll, ll, ll, ll)':
foodcourt.cpp:46:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
46 | ll mid=l+r>>1;
| ~^~
foodcourt.cpp: In function 'void upd(ll, ll, ll, ll, ll)':
foodcourt.cpp:57:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
57 | ll mid=l+r>>1;
| ~^~
foodcourt.cpp: In function 'll gt(ll, ll, ll, ll, ll)':
foodcourt.cpp:66:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
66 | ll mid=l+r>>1;
| ~^~
foodcourt.cpp: In function 'll quer(ll)':
foodcourt.cpp:74:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
74 | ll mid=l+r>>1;
| ~^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |