#include<bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define pii pair<ll,ll>
using namespace std;
const int N=250005,mod=1e9+7;
int t,n,m,q,g[N],ans[N];
ll tree[4*N],add[4*N],cnt[N],tr[4*N];
pii lazy[4*N];
vector<int> t1;
vector<pair<ll,int> > st[N],en[N],x[N];
void update2(int u,int ind,int l,int r,int val) {
if(l>ind || r<ind) return;
if(l==r) {
tr[u]+=val;
return;
}
int mid = (l+r)/2;
update2(2*u,ind,l,mid,val);
update2(2*u+1,ind,mid+1,r,val);
tr[u] = tr[2*u] + tr[2*u+1];
}
int getans2(int u,int l,int r,int c) {
if(l==r) return l;
int mid = (l+r)/2;
if(tr[2*u] >= c) return getans2(2*u,l,mid,c);
else return getans2(2*u+1,mid+1,r,c - tr[2*u]);
}
int getans1(int u,int start,int end,int l,int r){
if(l>end || r<start) return 0;
if(start<=l && r<=end) return tr[u];
int mid = (l+r)/2;
return getans1(2*u,start,end,l,mid) + getans1(2*u+1,start,end,mid+1,r);
}
void upd(pii &a,pii b){
if(a.s >= b.f) {
a.s = a.s - b.f + b.s;
}
else {
a.f += b.f - a.s;
a.s = b.s;
}
}
void update(int u,int start,int end,int l,int r,int val) {
if(lazy[u].f||lazy[u].s) {
tree[u] = max(tree[u]-lazy[u].f,0ll) + lazy[u].s;
if(l!=r){
upd(lazy[2*u],lazy[u]);
upd(lazy[2*u+1],lazy[u]);
}
lazy[u] = {0,0};
}
if(l>end || r<start) return;
if(start<=l && r<=end) {
if(val>0) lazy[u].s = val;
else lazy[u].f = -val;
tree[u] = max(tree[u]-lazy[u].f,0ll) + lazy[u].s;
if(l!=r){
upd(lazy[2*u],lazy[u]);
upd(lazy[2*u+1],lazy[u]);
}
lazy[u] = {0,0};
return;
}
int mid = (l+r)/2;
update(2*u,start,end,l,mid,val);
update(2*u+1,start,end,mid+1,r,val);
}
ll getans(int u,int ind,int l,int r) {
if(lazy[u].f||lazy[u].s) {
tree[u] = max(tree[u]-lazy[u].f,0ll) + lazy[u].s;
if(l!=r){
upd(lazy[2*u],lazy[u]);
upd(lazy[2*u+1],lazy[u]);
}
lazy[u] = {0,0};
}
if(l>ind || r<ind) return 0;
if(l==r) return tree[u];
int mid = (l+r)/2;
return getans(2*u,ind,l,mid) + getans(2*u+1,ind,mid+1,r);
}
main(){
ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>n>>m>>q;
for(int i=1;i<=q;i++){
int t,l,r,c,k;
cin>>t;
if(t==1) {
cin>>l>>r>>c>>k;
g[i] = c;
st[l].push_back({i,k});
en[r].push_back({i,k});
update(1,l,r,1,n,k);
t1.push_back(i);
}
else if(t==2){
cin>>l>>r>>k;
update(1,l,r,1,n,-k);
}
else {
ll a,c;
cin>>a>>c;
x[a].push_back({c,i});
cnt[i] = getans(1,a,1,n);
}
}
for(int i=1;i<=n;i++) {
for(int j=0;j<st[i].size();j++) {
update2(1,st[i][j].f,1,q,st[i][j].s);// cout<<"++"<<st[i][j].f<<"__"<<st[i][j].s<<endl;
}
for(int j=0;j<x[i].size();j++) {
int ind = x[i][j].s;
ll c = getans1(1,1,ind,1,q);
if(cnt[ind] < x[i][j].f) {
ans[ind] = -1;
continue;
}
else {
ans[ind] = g[getans2(1,1,q,c - (cnt[ind] - x[i][j].f+1)+1)];
// cout<<ind<<" "<<c<<"__"<<getans2(1,1,q,c-(cnt[ind]-x[i][j].f+1)+1)<<endl;
}
}
for(int j=0;j<en[i].size();j++){
update2(1,en[i][j].f,1,q,-en[i][j].s);
}
}
for(int i=1;i<=q;i++) {
if(ans[i]) cout<<max(0,ans[i])<<" ";
}
}
Compilation message
foodcourt.cpp:85:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
85 | main(){
| ^~~~
foodcourt.cpp: In function 'int main()':
foodcourt.cpp:114:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
114 | for(int j=0;j<st[i].size();j++) {
| ~^~~~~~~~~~~~~
foodcourt.cpp:117:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
117 | for(int j=0;j<x[i].size();j++) {
| ~^~~~~~~~~~~~
foodcourt.cpp:130:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
130 | for(int j=0;j<en[i].size();j++){
| ~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
18124 KB |
Output is correct |
2 |
Correct |
13 ms |
18124 KB |
Output is correct |
3 |
Correct |
12 ms |
18124 KB |
Output is correct |
4 |
Correct |
13 ms |
18124 KB |
Output is correct |
5 |
Correct |
11 ms |
18068 KB |
Output is correct |
6 |
Correct |
11 ms |
18124 KB |
Output is correct |
7 |
Correct |
13 ms |
18204 KB |
Output is correct |
8 |
Correct |
13 ms |
18208 KB |
Output is correct |
9 |
Correct |
13 ms |
18124 KB |
Output is correct |
10 |
Correct |
13 ms |
18124 KB |
Output is correct |
11 |
Correct |
13 ms |
18124 KB |
Output is correct |
12 |
Correct |
14 ms |
18124 KB |
Output is correct |
13 |
Correct |
13 ms |
18196 KB |
Output is correct |
14 |
Correct |
13 ms |
18196 KB |
Output is correct |
15 |
Correct |
13 ms |
18064 KB |
Output is correct |
16 |
Correct |
13 ms |
18128 KB |
Output is correct |
17 |
Correct |
14 ms |
18124 KB |
Output is correct |
18 |
Correct |
14 ms |
18124 KB |
Output is correct |
19 |
Correct |
14 ms |
18200 KB |
Output is correct |
20 |
Correct |
14 ms |
18252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
18124 KB |
Output is correct |
2 |
Correct |
13 ms |
18124 KB |
Output is correct |
3 |
Correct |
12 ms |
18124 KB |
Output is correct |
4 |
Correct |
13 ms |
18124 KB |
Output is correct |
5 |
Correct |
11 ms |
18068 KB |
Output is correct |
6 |
Correct |
11 ms |
18124 KB |
Output is correct |
7 |
Correct |
13 ms |
18204 KB |
Output is correct |
8 |
Correct |
13 ms |
18208 KB |
Output is correct |
9 |
Correct |
13 ms |
18124 KB |
Output is correct |
10 |
Correct |
13 ms |
18124 KB |
Output is correct |
11 |
Correct |
13 ms |
18124 KB |
Output is correct |
12 |
Correct |
14 ms |
18124 KB |
Output is correct |
13 |
Correct |
13 ms |
18196 KB |
Output is correct |
14 |
Correct |
13 ms |
18196 KB |
Output is correct |
15 |
Correct |
13 ms |
18064 KB |
Output is correct |
16 |
Correct |
13 ms |
18128 KB |
Output is correct |
17 |
Correct |
14 ms |
18124 KB |
Output is correct |
18 |
Correct |
14 ms |
18124 KB |
Output is correct |
19 |
Correct |
14 ms |
18200 KB |
Output is correct |
20 |
Correct |
14 ms |
18252 KB |
Output is correct |
21 |
Incorrect |
14 ms |
18200 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
116 ms |
25720 KB |
Output is correct |
2 |
Correct |
136 ms |
26200 KB |
Output is correct |
3 |
Correct |
122 ms |
25764 KB |
Output is correct |
4 |
Correct |
122 ms |
25648 KB |
Output is correct |
5 |
Correct |
121 ms |
26168 KB |
Output is correct |
6 |
Correct |
134 ms |
26208 KB |
Output is correct |
7 |
Correct |
46 ms |
21916 KB |
Output is correct |
8 |
Correct |
48 ms |
21808 KB |
Output is correct |
9 |
Correct |
123 ms |
25272 KB |
Output is correct |
10 |
Correct |
114 ms |
25644 KB |
Output is correct |
11 |
Correct |
115 ms |
25540 KB |
Output is correct |
12 |
Correct |
114 ms |
25676 KB |
Output is correct |
13 |
Correct |
103 ms |
25960 KB |
Output is correct |
14 |
Correct |
144 ms |
26412 KB |
Output is correct |
15 |
Correct |
135 ms |
27044 KB |
Output is correct |
16 |
Correct |
130 ms |
27052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
598 ms |
46000 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
18124 KB |
Output is correct |
2 |
Correct |
13 ms |
18124 KB |
Output is correct |
3 |
Correct |
12 ms |
18124 KB |
Output is correct |
4 |
Correct |
13 ms |
18124 KB |
Output is correct |
5 |
Correct |
11 ms |
18068 KB |
Output is correct |
6 |
Correct |
11 ms |
18124 KB |
Output is correct |
7 |
Correct |
13 ms |
18204 KB |
Output is correct |
8 |
Correct |
13 ms |
18208 KB |
Output is correct |
9 |
Correct |
13 ms |
18124 KB |
Output is correct |
10 |
Correct |
13 ms |
18124 KB |
Output is correct |
11 |
Correct |
13 ms |
18124 KB |
Output is correct |
12 |
Correct |
14 ms |
18124 KB |
Output is correct |
13 |
Correct |
13 ms |
18196 KB |
Output is correct |
14 |
Correct |
13 ms |
18196 KB |
Output is correct |
15 |
Correct |
13 ms |
18064 KB |
Output is correct |
16 |
Correct |
13 ms |
18128 KB |
Output is correct |
17 |
Correct |
14 ms |
18124 KB |
Output is correct |
18 |
Correct |
14 ms |
18124 KB |
Output is correct |
19 |
Correct |
14 ms |
18200 KB |
Output is correct |
20 |
Correct |
14 ms |
18252 KB |
Output is correct |
21 |
Correct |
116 ms |
25720 KB |
Output is correct |
22 |
Correct |
136 ms |
26200 KB |
Output is correct |
23 |
Correct |
122 ms |
25764 KB |
Output is correct |
24 |
Correct |
122 ms |
25648 KB |
Output is correct |
25 |
Correct |
121 ms |
26168 KB |
Output is correct |
26 |
Correct |
134 ms |
26208 KB |
Output is correct |
27 |
Correct |
46 ms |
21916 KB |
Output is correct |
28 |
Correct |
48 ms |
21808 KB |
Output is correct |
29 |
Correct |
123 ms |
25272 KB |
Output is correct |
30 |
Correct |
114 ms |
25644 KB |
Output is correct |
31 |
Correct |
115 ms |
25540 KB |
Output is correct |
32 |
Correct |
114 ms |
25676 KB |
Output is correct |
33 |
Correct |
103 ms |
25960 KB |
Output is correct |
34 |
Correct |
144 ms |
26412 KB |
Output is correct |
35 |
Correct |
135 ms |
27044 KB |
Output is correct |
36 |
Correct |
130 ms |
27052 KB |
Output is correct |
37 |
Correct |
120 ms |
25412 KB |
Output is correct |
38 |
Correct |
110 ms |
25456 KB |
Output is correct |
39 |
Correct |
42 ms |
21540 KB |
Output is correct |
40 |
Correct |
48 ms |
21832 KB |
Output is correct |
41 |
Correct |
128 ms |
25212 KB |
Output is correct |
42 |
Correct |
124 ms |
25668 KB |
Output is correct |
43 |
Correct |
130 ms |
25652 KB |
Output is correct |
44 |
Correct |
124 ms |
25356 KB |
Output is correct |
45 |
Correct |
137 ms |
25924 KB |
Output is correct |
46 |
Correct |
132 ms |
25700 KB |
Output is correct |
47 |
Correct |
75 ms |
25240 KB |
Output is correct |
48 |
Correct |
118 ms |
25668 KB |
Output is correct |
49 |
Correct |
96 ms |
24860 KB |
Output is correct |
50 |
Correct |
115 ms |
25352 KB |
Output is correct |
51 |
Correct |
131 ms |
25648 KB |
Output is correct |
52 |
Correct |
134 ms |
25684 KB |
Output is correct |
53 |
Correct |
104 ms |
26176 KB |
Output is correct |
54 |
Correct |
151 ms |
27072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
133 ms |
26188 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
18124 KB |
Output is correct |
2 |
Correct |
13 ms |
18124 KB |
Output is correct |
3 |
Correct |
12 ms |
18124 KB |
Output is correct |
4 |
Correct |
13 ms |
18124 KB |
Output is correct |
5 |
Correct |
11 ms |
18068 KB |
Output is correct |
6 |
Correct |
11 ms |
18124 KB |
Output is correct |
7 |
Correct |
13 ms |
18204 KB |
Output is correct |
8 |
Correct |
13 ms |
18208 KB |
Output is correct |
9 |
Correct |
13 ms |
18124 KB |
Output is correct |
10 |
Correct |
13 ms |
18124 KB |
Output is correct |
11 |
Correct |
13 ms |
18124 KB |
Output is correct |
12 |
Correct |
14 ms |
18124 KB |
Output is correct |
13 |
Correct |
13 ms |
18196 KB |
Output is correct |
14 |
Correct |
13 ms |
18196 KB |
Output is correct |
15 |
Correct |
13 ms |
18064 KB |
Output is correct |
16 |
Correct |
13 ms |
18128 KB |
Output is correct |
17 |
Correct |
14 ms |
18124 KB |
Output is correct |
18 |
Correct |
14 ms |
18124 KB |
Output is correct |
19 |
Correct |
14 ms |
18200 KB |
Output is correct |
20 |
Correct |
14 ms |
18252 KB |
Output is correct |
21 |
Incorrect |
14 ms |
18200 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
18124 KB |
Output is correct |
2 |
Correct |
13 ms |
18124 KB |
Output is correct |
3 |
Correct |
12 ms |
18124 KB |
Output is correct |
4 |
Correct |
13 ms |
18124 KB |
Output is correct |
5 |
Correct |
11 ms |
18068 KB |
Output is correct |
6 |
Correct |
11 ms |
18124 KB |
Output is correct |
7 |
Correct |
13 ms |
18204 KB |
Output is correct |
8 |
Correct |
13 ms |
18208 KB |
Output is correct |
9 |
Correct |
13 ms |
18124 KB |
Output is correct |
10 |
Correct |
13 ms |
18124 KB |
Output is correct |
11 |
Correct |
13 ms |
18124 KB |
Output is correct |
12 |
Correct |
14 ms |
18124 KB |
Output is correct |
13 |
Correct |
13 ms |
18196 KB |
Output is correct |
14 |
Correct |
13 ms |
18196 KB |
Output is correct |
15 |
Correct |
13 ms |
18064 KB |
Output is correct |
16 |
Correct |
13 ms |
18128 KB |
Output is correct |
17 |
Correct |
14 ms |
18124 KB |
Output is correct |
18 |
Correct |
14 ms |
18124 KB |
Output is correct |
19 |
Correct |
14 ms |
18200 KB |
Output is correct |
20 |
Correct |
14 ms |
18252 KB |
Output is correct |
21 |
Incorrect |
14 ms |
18200 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |