Submission #553068

# Submission time Handle Problem Language Result Execution time Memory
553068 2022-04-24T14:58:27 Z BJoozz Food Court (JOI21_foodcourt) C++17
68 / 100
384 ms 36304 KB
#define X first
#define Y second
#define pb push_back

#include<bits/stdc++.h>
using namespace std;
#define int long long
void maxx(int &a,int b){if(b>a) a=b;}
using ll = long long;
void minn(ll &a,ll b){if(b<a) a=b;}
//int down(const int &id){return id^1;}
//int upd(const int &id){return id;}
const int MAX=250000+4,mod=1e9+7;
const ll inf=1e15+3;
using ii =pair < int , int >;
vector < int > pr[MAX];
vector < ii >ad[MAX];
int C[MAX],K[MAX];
int SS[MAX*4],lz[MAX*4];
int ST[MAX];
int nx,val,n,m,Q,res;
void upd(int id,int l,int r){
    if(l==r){
        SS[id]+=val;lz[id]+=val;
        if(C[l])ST[id]+=val;
        return;
    }
    int mid=l+r>>1;
    if(lz[id]){
        lz[id<<1]+=lz[id];lz[id<<1|1]+=lz[id];
        SS[id<<1]+=lz[id];SS[id<<1|1]+=lz[id];
        lz[id]=0;
    }
    if(nx<=mid){
        SS[id<<1|1]+=val;lz[id<<1|1]+=val;
        upd(id<<1,l,mid);
    }
    else upd(id<<1|1,mid+1,r);
    ST[id]=ST[id<<1]+ST[id<<1|1];
    SS[id]=min(SS[id<<1],SS[id<<1|1]);
}
void get(int id,int l,int r){
    if(l==r){
        //cout<<"here "<<nx<<' '<<id<<' '<<l<<' '<<r<<' '<<SS[id]<<'\n';
        val=SS[id];return;
    }
    int mid=l+r>>1;
    if(lz[id]){
        lz[id<<1]+=lz[id];lz[id<<1|1]+=lz[id];
        SS[id<<1]+=lz[id];SS[id<<1|1]+=lz[id];
        lz[id]=0;
    }
    if(nx<=mid)get(id<<1,l,mid);
    else{
        minn(res,SS[id<<1]);
        get(id<<1|1,mid+1,r);
    }
    //SS[id]=min(SS[id<<1],SS[id<<1|1]);
}
void leo(int id,int l,int r){
    if(r<=nx){
        if(val>=ST[id]) {val-=ST[id];return;}
        if(l==r) {res=l;return;}
        int mid=l+r>>1;
        if(ST[id<<1|1]<=val) {
            val-=ST[id<<1|1];leo(id<<1,l,mid);
        }
        else leo(id<<1|1,mid+1,r);
        return;
    }
    int mid=l+r>>1;
    if(nx<=mid)leo(id<<1,l,mid);
    else{
        leo(id<<1|1,mid+1,r);
        if(!res) leo(id<<1,l,mid);
    }
    //SS[id]=min(SS[id<<1],SS[id<<1|1]);
}
void upd(int x){
    nx=x;val=K[x];//cout<<"upd "<<x<<' '<<K[x]<<'\n';
    K[x]=-K[x];
    upd(1,1,Q);
}

int get(int x,int lim){
    //cout<<x<<' '<<lim<<'\n';
    nx=x;res=0;
    get(1,1,Q);
    //cout<<val<<' '<<res<<'\n';
    if(val-res<lim) return 0;
    val=val-res-lim;res=0;
    leo(1,1,Q);
    //cout<<x<<' '<<lim<<' '<<res<<'\n';
    return C[res];
}
int ans[MAX];
signed main(){
    ///g++ grader.cpp .cpp -std=c++14 -O2 -Wl,--stack,10485760
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("JOI21_foodcourt.inp","r",stdin);//freopen("JOI21_foodcourt.out","w",stdout);
    cin>>n>>m>>Q;
    for(int i=1,t,x,y;i<=Q;i++){
        cin>>t>>x>>y;
        if(t==3)ad[x].pb(ii(i,y));
        else{
            ans[i]=-1;
            if(t==1){
                cin>>C[i]>>K[i];
                pr[x].pb(i);
                pr[y+1].pb(i);
            }
            else{
                cin>>K[i];K[i]=-K[i];
                pr[x].pb(i);
                pr[y+1].pb(i);
            }
        }
    }
    for(int i=1;i<=n;i++){
        for(int u:pr[i])
            upd(u);
        for(ii u:ad[i]){
            ans[u.X]=get(u.X,u.Y);
        }
    }
    for(int i=1;i<=Q;i++) if(ans[i]!=-1)cout<<ans[i]<<'\n';

}

Compilation message

foodcourt.cpp: In function 'void upd(long long int, long long int, long long int)':
foodcourt.cpp:29:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   29 |     int mid=l+r>>1;
      |             ~^~
foodcourt.cpp: In function 'void get(long long int, long long int, long long int)':
foodcourt.cpp:48:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   48 |     int mid=l+r>>1;
      |             ~^~
foodcourt.cpp: In function 'void leo(long long int, long long int, long long int)':
foodcourt.cpp:65:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   65 |         int mid=l+r>>1;
      |                 ~^~
foodcourt.cpp:72:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   72 |     int mid=l+r>>1;
      |             ~^~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12244 KB Output is correct
2 Correct 8 ms 12292 KB Output is correct
3 Correct 8 ms 12212 KB Output is correct
4 Correct 8 ms 12288 KB Output is correct
5 Correct 7 ms 12244 KB Output is correct
6 Correct 7 ms 12244 KB Output is correct
7 Correct 8 ms 12244 KB Output is correct
8 Correct 9 ms 12244 KB Output is correct
9 Correct 7 ms 12340 KB Output is correct
10 Correct 7 ms 12244 KB Output is correct
11 Correct 10 ms 12244 KB Output is correct
12 Correct 10 ms 12244 KB Output is correct
13 Correct 8 ms 12272 KB Output is correct
14 Correct 8 ms 12336 KB Output is correct
15 Correct 8 ms 12208 KB Output is correct
16 Correct 9 ms 12344 KB Output is correct
17 Correct 8 ms 12244 KB Output is correct
18 Correct 9 ms 12320 KB Output is correct
19 Correct 9 ms 12244 KB Output is correct
20 Correct 7 ms 12244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12244 KB Output is correct
2 Correct 8 ms 12292 KB Output is correct
3 Correct 8 ms 12212 KB Output is correct
4 Correct 8 ms 12288 KB Output is correct
5 Correct 7 ms 12244 KB Output is correct
6 Correct 7 ms 12244 KB Output is correct
7 Correct 8 ms 12244 KB Output is correct
8 Correct 9 ms 12244 KB Output is correct
9 Correct 7 ms 12340 KB Output is correct
10 Correct 7 ms 12244 KB Output is correct
11 Correct 10 ms 12244 KB Output is correct
12 Correct 10 ms 12244 KB Output is correct
13 Correct 8 ms 12272 KB Output is correct
14 Correct 8 ms 12336 KB Output is correct
15 Correct 8 ms 12208 KB Output is correct
16 Correct 9 ms 12344 KB Output is correct
17 Correct 8 ms 12244 KB Output is correct
18 Correct 9 ms 12320 KB Output is correct
19 Correct 9 ms 12244 KB Output is correct
20 Correct 7 ms 12244 KB Output is correct
21 Correct 8 ms 12244 KB Output is correct
22 Correct 9 ms 12340 KB Output is correct
23 Correct 8 ms 12316 KB Output is correct
24 Correct 9 ms 12336 KB Output is correct
25 Correct 9 ms 12244 KB Output is correct
26 Correct 8 ms 12328 KB Output is correct
27 Correct 9 ms 12340 KB Output is correct
28 Correct 10 ms 12364 KB Output is correct
29 Correct 9 ms 12276 KB Output is correct
30 Correct 9 ms 12244 KB Output is correct
31 Correct 8 ms 12264 KB Output is correct
32 Correct 8 ms 12372 KB Output is correct
33 Correct 7 ms 12244 KB Output is correct
34 Correct 8 ms 12372 KB Output is correct
35 Correct 8 ms 12340 KB Output is correct
36 Correct 8 ms 12348 KB Output is correct
37 Correct 8 ms 12244 KB Output is correct
38 Correct 11 ms 12340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 82 ms 19428 KB Output is correct
2 Correct 75 ms 19380 KB Output is correct
3 Correct 80 ms 19456 KB Output is correct
4 Correct 80 ms 19388 KB Output is correct
5 Correct 91 ms 19404 KB Output is correct
6 Correct 86 ms 19400 KB Output is correct
7 Correct 32 ms 18364 KB Output is correct
8 Correct 41 ms 18272 KB Output is correct
9 Correct 82 ms 19052 KB Output is correct
10 Correct 88 ms 19404 KB Output is correct
11 Correct 78 ms 19100 KB Output is correct
12 Correct 84 ms 19348 KB Output is correct
13 Correct 64 ms 18840 KB Output is correct
14 Correct 98 ms 20108 KB Output is correct
15 Correct 77 ms 20012 KB Output is correct
16 Correct 90 ms 20232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 384 ms 36304 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12244 KB Output is correct
2 Correct 8 ms 12292 KB Output is correct
3 Correct 8 ms 12212 KB Output is correct
4 Correct 8 ms 12288 KB Output is correct
5 Correct 7 ms 12244 KB Output is correct
6 Correct 7 ms 12244 KB Output is correct
7 Correct 8 ms 12244 KB Output is correct
8 Correct 9 ms 12244 KB Output is correct
9 Correct 7 ms 12340 KB Output is correct
10 Correct 7 ms 12244 KB Output is correct
11 Correct 10 ms 12244 KB Output is correct
12 Correct 10 ms 12244 KB Output is correct
13 Correct 8 ms 12272 KB Output is correct
14 Correct 8 ms 12336 KB Output is correct
15 Correct 8 ms 12208 KB Output is correct
16 Correct 9 ms 12344 KB Output is correct
17 Correct 8 ms 12244 KB Output is correct
18 Correct 9 ms 12320 KB Output is correct
19 Correct 9 ms 12244 KB Output is correct
20 Correct 7 ms 12244 KB Output is correct
21 Correct 82 ms 19428 KB Output is correct
22 Correct 75 ms 19380 KB Output is correct
23 Correct 80 ms 19456 KB Output is correct
24 Correct 80 ms 19388 KB Output is correct
25 Correct 91 ms 19404 KB Output is correct
26 Correct 86 ms 19400 KB Output is correct
27 Correct 32 ms 18364 KB Output is correct
28 Correct 41 ms 18272 KB Output is correct
29 Correct 82 ms 19052 KB Output is correct
30 Correct 88 ms 19404 KB Output is correct
31 Correct 78 ms 19100 KB Output is correct
32 Correct 84 ms 19348 KB Output is correct
33 Correct 64 ms 18840 KB Output is correct
34 Correct 98 ms 20108 KB Output is correct
35 Correct 77 ms 20012 KB Output is correct
36 Correct 90 ms 20232 KB Output is correct
37 Correct 79 ms 19536 KB Output is correct
38 Correct 71 ms 19148 KB Output is correct
39 Correct 29 ms 17948 KB Output is correct
40 Correct 34 ms 18324 KB Output is correct
41 Correct 95 ms 19520 KB Output is correct
42 Correct 81 ms 20036 KB Output is correct
43 Correct 86 ms 20028 KB Output is correct
44 Correct 89 ms 19792 KB Output is correct
45 Correct 89 ms 20040 KB Output is correct
46 Correct 81 ms 20024 KB Output is correct
47 Correct 40 ms 19128 KB Output is correct
48 Correct 63 ms 19472 KB Output is correct
49 Correct 48 ms 18548 KB Output is correct
50 Correct 75 ms 19420 KB Output is correct
51 Correct 88 ms 20048 KB Output is correct
52 Correct 77 ms 20092 KB Output is correct
53 Correct 55 ms 19180 KB Output is correct
54 Correct 69 ms 20252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 19196 KB Output is correct
2 Correct 94 ms 19380 KB Output is correct
3 Correct 109 ms 19532 KB Output is correct
4 Correct 55 ms 19076 KB Output is correct
5 Correct 71 ms 19916 KB Output is correct
6 Correct 86 ms 20756 KB Output is correct
7 Correct 37 ms 18892 KB Output is correct
8 Correct 43 ms 18736 KB Output is correct
9 Correct 59 ms 19724 KB Output is correct
10 Correct 66 ms 18544 KB Output is correct
11 Correct 71 ms 20088 KB Output is correct
12 Correct 64 ms 20060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12244 KB Output is correct
2 Correct 8 ms 12292 KB Output is correct
3 Correct 8 ms 12212 KB Output is correct
4 Correct 8 ms 12288 KB Output is correct
5 Correct 7 ms 12244 KB Output is correct
6 Correct 7 ms 12244 KB Output is correct
7 Correct 8 ms 12244 KB Output is correct
8 Correct 9 ms 12244 KB Output is correct
9 Correct 7 ms 12340 KB Output is correct
10 Correct 7 ms 12244 KB Output is correct
11 Correct 10 ms 12244 KB Output is correct
12 Correct 10 ms 12244 KB Output is correct
13 Correct 8 ms 12272 KB Output is correct
14 Correct 8 ms 12336 KB Output is correct
15 Correct 8 ms 12208 KB Output is correct
16 Correct 9 ms 12344 KB Output is correct
17 Correct 8 ms 12244 KB Output is correct
18 Correct 9 ms 12320 KB Output is correct
19 Correct 9 ms 12244 KB Output is correct
20 Correct 7 ms 12244 KB Output is correct
21 Correct 8 ms 12244 KB Output is correct
22 Correct 9 ms 12340 KB Output is correct
23 Correct 8 ms 12316 KB Output is correct
24 Correct 9 ms 12336 KB Output is correct
25 Correct 9 ms 12244 KB Output is correct
26 Correct 8 ms 12328 KB Output is correct
27 Correct 9 ms 12340 KB Output is correct
28 Correct 10 ms 12364 KB Output is correct
29 Correct 9 ms 12276 KB Output is correct
30 Correct 9 ms 12244 KB Output is correct
31 Correct 8 ms 12264 KB Output is correct
32 Correct 8 ms 12372 KB Output is correct
33 Correct 7 ms 12244 KB Output is correct
34 Correct 8 ms 12372 KB Output is correct
35 Correct 8 ms 12340 KB Output is correct
36 Correct 8 ms 12348 KB Output is correct
37 Correct 8 ms 12244 KB Output is correct
38 Correct 11 ms 12340 KB Output is correct
39 Correct 82 ms 19428 KB Output is correct
40 Correct 75 ms 19380 KB Output is correct
41 Correct 80 ms 19456 KB Output is correct
42 Correct 80 ms 19388 KB Output is correct
43 Correct 91 ms 19404 KB Output is correct
44 Correct 86 ms 19400 KB Output is correct
45 Correct 32 ms 18364 KB Output is correct
46 Correct 41 ms 18272 KB Output is correct
47 Correct 82 ms 19052 KB Output is correct
48 Correct 88 ms 19404 KB Output is correct
49 Correct 78 ms 19100 KB Output is correct
50 Correct 84 ms 19348 KB Output is correct
51 Correct 64 ms 18840 KB Output is correct
52 Correct 98 ms 20108 KB Output is correct
53 Correct 77 ms 20012 KB Output is correct
54 Correct 90 ms 20232 KB Output is correct
55 Correct 79 ms 19536 KB Output is correct
56 Correct 71 ms 19148 KB Output is correct
57 Correct 29 ms 17948 KB Output is correct
58 Correct 34 ms 18324 KB Output is correct
59 Correct 95 ms 19520 KB Output is correct
60 Correct 81 ms 20036 KB Output is correct
61 Correct 86 ms 20028 KB Output is correct
62 Correct 89 ms 19792 KB Output is correct
63 Correct 89 ms 20040 KB Output is correct
64 Correct 81 ms 20024 KB Output is correct
65 Correct 40 ms 19128 KB Output is correct
66 Correct 63 ms 19472 KB Output is correct
67 Correct 48 ms 18548 KB Output is correct
68 Correct 75 ms 19420 KB Output is correct
69 Correct 88 ms 20048 KB Output is correct
70 Correct 77 ms 20092 KB Output is correct
71 Correct 55 ms 19180 KB Output is correct
72 Correct 69 ms 20252 KB Output is correct
73 Correct 81 ms 19196 KB Output is correct
74 Correct 94 ms 19380 KB Output is correct
75 Correct 109 ms 19532 KB Output is correct
76 Correct 55 ms 19076 KB Output is correct
77 Correct 71 ms 19916 KB Output is correct
78 Correct 86 ms 20756 KB Output is correct
79 Correct 37 ms 18892 KB Output is correct
80 Correct 43 ms 18736 KB Output is correct
81 Correct 59 ms 19724 KB Output is correct
82 Correct 66 ms 18544 KB Output is correct
83 Correct 71 ms 20088 KB Output is correct
84 Correct 64 ms 20060 KB Output is correct
85 Correct 107 ms 19992 KB Output is correct
86 Correct 116 ms 20608 KB Output is correct
87 Correct 66 ms 19984 KB Output is correct
88 Correct 76 ms 20640 KB Output is correct
89 Correct 51 ms 18440 KB Output is correct
90 Correct 73 ms 20628 KB Output is correct
91 Correct 81 ms 19500 KB Output is correct
92 Correct 71 ms 19280 KB Output is correct
93 Correct 97 ms 20556 KB Output is correct
94 Correct 76 ms 20392 KB Output is correct
95 Correct 89 ms 20364 KB Output is correct
96 Correct 80 ms 20588 KB Output is correct
97 Correct 114 ms 20548 KB Output is correct
98 Correct 84 ms 19668 KB Output is correct
99 Correct 50 ms 19472 KB Output is correct
100 Correct 50 ms 19052 KB Output is correct
101 Correct 63 ms 20108 KB Output is correct
102 Correct 63 ms 20520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12244 KB Output is correct
2 Correct 8 ms 12292 KB Output is correct
3 Correct 8 ms 12212 KB Output is correct
4 Correct 8 ms 12288 KB Output is correct
5 Correct 7 ms 12244 KB Output is correct
6 Correct 7 ms 12244 KB Output is correct
7 Correct 8 ms 12244 KB Output is correct
8 Correct 9 ms 12244 KB Output is correct
9 Correct 7 ms 12340 KB Output is correct
10 Correct 7 ms 12244 KB Output is correct
11 Correct 10 ms 12244 KB Output is correct
12 Correct 10 ms 12244 KB Output is correct
13 Correct 8 ms 12272 KB Output is correct
14 Correct 8 ms 12336 KB Output is correct
15 Correct 8 ms 12208 KB Output is correct
16 Correct 9 ms 12344 KB Output is correct
17 Correct 8 ms 12244 KB Output is correct
18 Correct 9 ms 12320 KB Output is correct
19 Correct 9 ms 12244 KB Output is correct
20 Correct 7 ms 12244 KB Output is correct
21 Correct 8 ms 12244 KB Output is correct
22 Correct 9 ms 12340 KB Output is correct
23 Correct 8 ms 12316 KB Output is correct
24 Correct 9 ms 12336 KB Output is correct
25 Correct 9 ms 12244 KB Output is correct
26 Correct 8 ms 12328 KB Output is correct
27 Correct 9 ms 12340 KB Output is correct
28 Correct 10 ms 12364 KB Output is correct
29 Correct 9 ms 12276 KB Output is correct
30 Correct 9 ms 12244 KB Output is correct
31 Correct 8 ms 12264 KB Output is correct
32 Correct 8 ms 12372 KB Output is correct
33 Correct 7 ms 12244 KB Output is correct
34 Correct 8 ms 12372 KB Output is correct
35 Correct 8 ms 12340 KB Output is correct
36 Correct 8 ms 12348 KB Output is correct
37 Correct 8 ms 12244 KB Output is correct
38 Correct 11 ms 12340 KB Output is correct
39 Correct 82 ms 19428 KB Output is correct
40 Correct 75 ms 19380 KB Output is correct
41 Correct 80 ms 19456 KB Output is correct
42 Correct 80 ms 19388 KB Output is correct
43 Correct 91 ms 19404 KB Output is correct
44 Correct 86 ms 19400 KB Output is correct
45 Correct 32 ms 18364 KB Output is correct
46 Correct 41 ms 18272 KB Output is correct
47 Correct 82 ms 19052 KB Output is correct
48 Correct 88 ms 19404 KB Output is correct
49 Correct 78 ms 19100 KB Output is correct
50 Correct 84 ms 19348 KB Output is correct
51 Correct 64 ms 18840 KB Output is correct
52 Correct 98 ms 20108 KB Output is correct
53 Correct 77 ms 20012 KB Output is correct
54 Correct 90 ms 20232 KB Output is correct
55 Incorrect 384 ms 36304 KB Output isn't correct
56 Halted 0 ms 0 KB -