#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> void _do(T x){cerr<<x<<"\n";}
template<typename T,typename ...U> void _do(T x,U ...y){cerr<<x<<", ";_do(y...);}
#define dbg(...) cerr<<#__VA_ARGS__<<" = ";_do(__VA_ARGS__);
const ll INF=3e18;
#define MottoHayaku ios::sync_with_stdio(false);cin.tie(0);
//#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define F first
#define S second
#define pb push_back
#define uni(c) c.resize(distance(c.begin(),unique(c.begin(),c.end())))
#define unisort(c) sort(c.begin(),c.end());uni(c)
const int N=250005;
struct BIT
{
ll sz,a[N];
void upd(int x,ll val){for(;x<=sz;x+=x&-x) a[x]+=val;}
ll qry(int x)
{
ll ret=0;
for(;x;x-=x&-x) ret+=a[x];
return ret;
}
} bit;
struct SegTree1
{
ll tag[N<<2],mn[N<<2];
void givetag(ll x,ll y,int id)
{
mn[id]=min(mn[id],tag[id]+y);
tag[id]+=x;
}
void tagdown(int id)
{
givetag(tag[id],mn[id],id<<1);
givetag(tag[id],mn[id],id<<1|1);
tag[id]=mn[id]=0;
}
void upd(int l,int r,int ql,int qr,ll x,int id)
{
if(ql<=l&&r<=qr) givetag(x,x,id);
else
{
tagdown(id);
int mid=l+r>>1;
if(qr<=mid) upd(l,mid,ql,qr,x,id<<1);
else if(ql>mid) upd(mid+1,r,ql,qr,x,id<<1|1);
else
{
upd(l,mid,ql,mid,x,id<<1);
upd(mid+1,r,mid+1,qr,x,id<<1|1);
}
}
}
ll qry(int l,int r,int x,int id)
{
if(l==r) return tag[id]-mn[id];
else
{
tagdown(id);
int mid=l+r>>1;
if(x<=mid) return qry(l,mid,x,id<<1);
else return qry(mid+1,r,x,id<<1|1);
}
}
} seg1;
struct SegTree2
{
ll st[N<<2];
void upd(int l,int r,int x,ll val,int id)
{
if(l==r) st[id]+=val;
else
{
int mid=l+r>>1;
if(x<=mid) upd(l,mid,x,val,id<<1);
else upd(mid+1,r,x,val,id<<1|1);
st[id]=st[id<<1]+st[id<<1|1];
}
}
ll qry(int l,int r,ll x,int id)
{
if(l==r) return l;
else
{
int mid=l+r>>1;
if(st[id<<1]>=x) return qry(l,mid,x,id<<1);
else return qry(mid+1,r,x-st[id<<1],id<<1|1);
}
}
} seg2;
ll ans[N],r[N],color[N];//ans,modified qry
vector<pll> add[N];//{time,val}
vector<int> id[N];
signed main()
{
MottoHayaku
int n,m,q;
cin>>n>>m>>q;
bit.sz=n;
rep1(i,q)
{
ll t;
cin>>t;
ans[i]=-1;
if(t==1)
{
int l,r,c;
ll k;
cin>>l>>r>>c>>k;
color[i]=c;
seg1.upd(1,n,l,r,k,1);
add[l].pb({i,k});
if(r<n) add[r+1].pb({i,-k});
bit.upd(l,k);
bit.upd(r+1,-k);
}
else if(t==2)
{
int l,r;
ll k;
cin>>l>>r>>k;
seg1.upd(1,n,l,r,-k,1);
}
else
{
int a,b;
cin>>a>>b;
ll tmp=b-seg1.qry(1,n,a,1);
if(tmp>0)
{
ans[i]=0;
continue;
}
r[i]=bit.qry(a)+tmp;
id[a].pb(i);
}
}
rep1(i,n)
{
for(pll u:add[i]) seg2.upd(1,q,u.F,u.S,1);
for(ll u:id[i]) ans[u]=color[seg2.qry(1,q,r[u],1)];
}
rep1(i,q)
{
if(ans[i]!=-1) cout<<ans[i]<<"\n";
}
}
Compilation message
foodcourt.cpp: In member function 'void SegTree1::upd(int, int, int, int, ll, int)':
foodcourt.cpp:54:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
54 | int mid=l+r>>1;
| ~^~
foodcourt.cpp: In member function 'll SegTree1::qry(int, int, int, int)':
foodcourt.cpp:70:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
70 | int mid=l+r>>1;
| ~^~
foodcourt.cpp: In member function 'void SegTree2::upd(int, int, int, ll, int)':
foodcourt.cpp:85:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
85 | int mid=l+r>>1;
| ~^~
foodcourt.cpp: In member function 'll SegTree2::qry(int, int, ll, int)':
foodcourt.cpp:96:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
96 | int mid=l+r>>1;
| ~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
12308 KB |
Output is correct |
2 |
Correct |
8 ms |
12344 KB |
Output is correct |
3 |
Correct |
8 ms |
12252 KB |
Output is correct |
4 |
Correct |
9 ms |
12320 KB |
Output is correct |
5 |
Correct |
7 ms |
12244 KB |
Output is correct |
6 |
Correct |
7 ms |
12220 KB |
Output is correct |
7 |
Correct |
8 ms |
12244 KB |
Output is correct |
8 |
Correct |
8 ms |
12244 KB |
Output is correct |
9 |
Correct |
8 ms |
12332 KB |
Output is correct |
10 |
Correct |
8 ms |
12244 KB |
Output is correct |
11 |
Correct |
8 ms |
12340 KB |
Output is correct |
12 |
Correct |
8 ms |
12244 KB |
Output is correct |
13 |
Correct |
9 ms |
12276 KB |
Output is correct |
14 |
Correct |
8 ms |
12244 KB |
Output is correct |
15 |
Correct |
7 ms |
12220 KB |
Output is correct |
16 |
Correct |
9 ms |
12372 KB |
Output is correct |
17 |
Correct |
8 ms |
12244 KB |
Output is correct |
18 |
Correct |
8 ms |
12328 KB |
Output is correct |
19 |
Correct |
8 ms |
12372 KB |
Output is correct |
20 |
Correct |
9 ms |
12372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
12308 KB |
Output is correct |
2 |
Correct |
8 ms |
12344 KB |
Output is correct |
3 |
Correct |
8 ms |
12252 KB |
Output is correct |
4 |
Correct |
9 ms |
12320 KB |
Output is correct |
5 |
Correct |
7 ms |
12244 KB |
Output is correct |
6 |
Correct |
7 ms |
12220 KB |
Output is correct |
7 |
Correct |
8 ms |
12244 KB |
Output is correct |
8 |
Correct |
8 ms |
12244 KB |
Output is correct |
9 |
Correct |
8 ms |
12332 KB |
Output is correct |
10 |
Correct |
8 ms |
12244 KB |
Output is correct |
11 |
Correct |
8 ms |
12340 KB |
Output is correct |
12 |
Correct |
8 ms |
12244 KB |
Output is correct |
13 |
Correct |
9 ms |
12276 KB |
Output is correct |
14 |
Correct |
8 ms |
12244 KB |
Output is correct |
15 |
Correct |
7 ms |
12220 KB |
Output is correct |
16 |
Correct |
9 ms |
12372 KB |
Output is correct |
17 |
Correct |
8 ms |
12244 KB |
Output is correct |
18 |
Correct |
8 ms |
12328 KB |
Output is correct |
19 |
Correct |
8 ms |
12372 KB |
Output is correct |
20 |
Correct |
9 ms |
12372 KB |
Output is correct |
21 |
Incorrect |
7 ms |
12244 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
19164 KB |
Output is correct |
2 |
Correct |
66 ms |
19660 KB |
Output is correct |
3 |
Correct |
62 ms |
19172 KB |
Output is correct |
4 |
Correct |
66 ms |
19184 KB |
Output is correct |
5 |
Correct |
63 ms |
19736 KB |
Output is correct |
6 |
Correct |
67 ms |
19660 KB |
Output is correct |
7 |
Correct |
27 ms |
15820 KB |
Output is correct |
8 |
Correct |
26 ms |
15756 KB |
Output is correct |
9 |
Correct |
60 ms |
18896 KB |
Output is correct |
10 |
Correct |
59 ms |
19288 KB |
Output is correct |
11 |
Correct |
66 ms |
19224 KB |
Output is correct |
12 |
Correct |
61 ms |
19328 KB |
Output is correct |
13 |
Correct |
56 ms |
19532 KB |
Output is correct |
14 |
Correct |
63 ms |
20356 KB |
Output is correct |
15 |
Correct |
74 ms |
20932 KB |
Output is correct |
16 |
Correct |
78 ms |
21240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
46 ms |
16596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
12308 KB |
Output is correct |
2 |
Correct |
8 ms |
12344 KB |
Output is correct |
3 |
Correct |
8 ms |
12252 KB |
Output is correct |
4 |
Correct |
9 ms |
12320 KB |
Output is correct |
5 |
Correct |
7 ms |
12244 KB |
Output is correct |
6 |
Correct |
7 ms |
12220 KB |
Output is correct |
7 |
Correct |
8 ms |
12244 KB |
Output is correct |
8 |
Correct |
8 ms |
12244 KB |
Output is correct |
9 |
Correct |
8 ms |
12332 KB |
Output is correct |
10 |
Correct |
8 ms |
12244 KB |
Output is correct |
11 |
Correct |
8 ms |
12340 KB |
Output is correct |
12 |
Correct |
8 ms |
12244 KB |
Output is correct |
13 |
Correct |
9 ms |
12276 KB |
Output is correct |
14 |
Correct |
8 ms |
12244 KB |
Output is correct |
15 |
Correct |
7 ms |
12220 KB |
Output is correct |
16 |
Correct |
9 ms |
12372 KB |
Output is correct |
17 |
Correct |
8 ms |
12244 KB |
Output is correct |
18 |
Correct |
8 ms |
12328 KB |
Output is correct |
19 |
Correct |
8 ms |
12372 KB |
Output is correct |
20 |
Correct |
9 ms |
12372 KB |
Output is correct |
21 |
Correct |
61 ms |
19164 KB |
Output is correct |
22 |
Correct |
66 ms |
19660 KB |
Output is correct |
23 |
Correct |
62 ms |
19172 KB |
Output is correct |
24 |
Correct |
66 ms |
19184 KB |
Output is correct |
25 |
Correct |
63 ms |
19736 KB |
Output is correct |
26 |
Correct |
67 ms |
19660 KB |
Output is correct |
27 |
Correct |
27 ms |
15820 KB |
Output is correct |
28 |
Correct |
26 ms |
15756 KB |
Output is correct |
29 |
Correct |
60 ms |
18896 KB |
Output is correct |
30 |
Correct |
59 ms |
19288 KB |
Output is correct |
31 |
Correct |
66 ms |
19224 KB |
Output is correct |
32 |
Correct |
61 ms |
19328 KB |
Output is correct |
33 |
Correct |
56 ms |
19532 KB |
Output is correct |
34 |
Correct |
63 ms |
20356 KB |
Output is correct |
35 |
Correct |
74 ms |
20932 KB |
Output is correct |
36 |
Correct |
78 ms |
21240 KB |
Output is correct |
37 |
Correct |
60 ms |
19412 KB |
Output is correct |
38 |
Correct |
61 ms |
19352 KB |
Output is correct |
39 |
Correct |
23 ms |
15348 KB |
Output is correct |
40 |
Correct |
29 ms |
15860 KB |
Output is correct |
41 |
Correct |
72 ms |
19144 KB |
Output is correct |
42 |
Correct |
77 ms |
20008 KB |
Output is correct |
43 |
Correct |
69 ms |
19884 KB |
Output is correct |
44 |
Correct |
68 ms |
19628 KB |
Output is correct |
45 |
Correct |
73 ms |
19916 KB |
Output is correct |
46 |
Correct |
71 ms |
19968 KB |
Output is correct |
47 |
Correct |
38 ms |
18488 KB |
Output is correct |
48 |
Correct |
58 ms |
19364 KB |
Output is correct |
49 |
Correct |
48 ms |
18508 KB |
Output is correct |
50 |
Correct |
59 ms |
19276 KB |
Output is correct |
51 |
Correct |
83 ms |
19988 KB |
Output is correct |
52 |
Correct |
70 ms |
20016 KB |
Output is correct |
53 |
Correct |
58 ms |
20008 KB |
Output is correct |
54 |
Correct |
78 ms |
21232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
18 ms |
14680 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
12308 KB |
Output is correct |
2 |
Correct |
8 ms |
12344 KB |
Output is correct |
3 |
Correct |
8 ms |
12252 KB |
Output is correct |
4 |
Correct |
9 ms |
12320 KB |
Output is correct |
5 |
Correct |
7 ms |
12244 KB |
Output is correct |
6 |
Correct |
7 ms |
12220 KB |
Output is correct |
7 |
Correct |
8 ms |
12244 KB |
Output is correct |
8 |
Correct |
8 ms |
12244 KB |
Output is correct |
9 |
Correct |
8 ms |
12332 KB |
Output is correct |
10 |
Correct |
8 ms |
12244 KB |
Output is correct |
11 |
Correct |
8 ms |
12340 KB |
Output is correct |
12 |
Correct |
8 ms |
12244 KB |
Output is correct |
13 |
Correct |
9 ms |
12276 KB |
Output is correct |
14 |
Correct |
8 ms |
12244 KB |
Output is correct |
15 |
Correct |
7 ms |
12220 KB |
Output is correct |
16 |
Correct |
9 ms |
12372 KB |
Output is correct |
17 |
Correct |
8 ms |
12244 KB |
Output is correct |
18 |
Correct |
8 ms |
12328 KB |
Output is correct |
19 |
Correct |
8 ms |
12372 KB |
Output is correct |
20 |
Correct |
9 ms |
12372 KB |
Output is correct |
21 |
Incorrect |
7 ms |
12244 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
12308 KB |
Output is correct |
2 |
Correct |
8 ms |
12344 KB |
Output is correct |
3 |
Correct |
8 ms |
12252 KB |
Output is correct |
4 |
Correct |
9 ms |
12320 KB |
Output is correct |
5 |
Correct |
7 ms |
12244 KB |
Output is correct |
6 |
Correct |
7 ms |
12220 KB |
Output is correct |
7 |
Correct |
8 ms |
12244 KB |
Output is correct |
8 |
Correct |
8 ms |
12244 KB |
Output is correct |
9 |
Correct |
8 ms |
12332 KB |
Output is correct |
10 |
Correct |
8 ms |
12244 KB |
Output is correct |
11 |
Correct |
8 ms |
12340 KB |
Output is correct |
12 |
Correct |
8 ms |
12244 KB |
Output is correct |
13 |
Correct |
9 ms |
12276 KB |
Output is correct |
14 |
Correct |
8 ms |
12244 KB |
Output is correct |
15 |
Correct |
7 ms |
12220 KB |
Output is correct |
16 |
Correct |
9 ms |
12372 KB |
Output is correct |
17 |
Correct |
8 ms |
12244 KB |
Output is correct |
18 |
Correct |
8 ms |
12328 KB |
Output is correct |
19 |
Correct |
8 ms |
12372 KB |
Output is correct |
20 |
Correct |
9 ms |
12372 KB |
Output is correct |
21 |
Incorrect |
7 ms |
12244 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |