답안 #905243

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
905243 2024-01-12T21:07:32 Z alexander707070 푸드 코트 (JOI21_foodcourt) C++14
14 / 100
1000 ms 115028 KB
#include<bits/stdc++.h>
#define MAXN 500007
using namespace std;

struct event{
    int c,tim;
    long long k;
};

const long long inf=1e17;

int n,m,q,type,l,r;
long long s,t;

long long minsz[4*MAXN],lazy[4*MAXN],maxsz[4*MAXN];
int c[MAXN];

vector< event > tree[4*MAXN];
vector<long long> pref[4*MAXN];

void update(int v,int l,int r,int ll,int rr,event news){
    if(ll>rr)return;
    if(l==ll and r==rr){
        tree[v].push_back(news);

        if(pref[v].empty())pref[v].push_back(news.k);
        else pref[v].push_back(pref[v].back()+news.k);

        return;
    }else{
        int tt=(l+r)/2;
        update(2*v,l,tt,ll,min(tt,rr),news);
        update(2*v+1,tt+1,r,max(tt+1,ll),rr,news);
    }
}

void psh(int v){
    minsz[2*v]+=lazy[v];
    maxsz[2*v]+=lazy[v];

    minsz[2*v]=max(minsz[2*v],0LL);
    maxsz[2*v]=max(maxsz[2*v],0LL);

    minsz[2*v+1]+=lazy[v];
    maxsz[2*v+1]+=lazy[v];

    minsz[2*v+1]=max(minsz[2*v+1],0LL);
    maxsz[2*v+1]=max(maxsz[2*v+1],0LL);

    lazy[2*v]+=lazy[v];
    lazy[2*v+1]+=lazy[v];

    lazy[v]=0;
}

void add(int v,int l,int r,int ll,int rr,long long val){
    if(ll>rr)return;
    if(l==ll and r==rr){
        minsz[v]+=val;
        maxsz[v]+=val;

        lazy[v]+=val;
    }else{
        psh(v);
        int tt=(l+r)/2;
        add(2*v,l,tt,ll,min(tt,rr),val);
        add(2*v+1,tt+1,r,max(tt+1,ll),rr,val);

        minsz[v]=min(minsz[2*v],minsz[2*v+1]);
        maxsz[v]=max(maxsz[2*v],maxsz[2*v+1]);
    }
}

void rem(int v,int l,int r,int ll,int rr,long long val){
    if(ll>rr)return;

    if(l==ll and r==rr and minsz[v]>=val){
        minsz[v]-=val;
        lazy[v]-=val;
        return;
    }

    if(l==ll and r==rr and maxsz[v]<val){
        minsz[v]=maxsz[v]=0;
        lazy[v]=-inf;
        return;
    }

    psh(v);
    int tt=(l+r)/2;
    rem(2*v,l,tt,ll,min(tt,rr),val);
    rem(2*v+1,tt+1,r,max(tt+1,ll),rr,val);

    minsz[v]=min(minsz[2*v],minsz[2*v+1]);
    maxsz[v]=max(maxsz[2*v],maxsz[2*v+1]);
}

long long getsz(int v,int l,int r,int pos){
    if(l==r)return minsz[v];

    psh(v);
    int tt=(l+r)/2;
    if(pos<=tt)return getsz(2*v,l,tt,pos);
    else getsz(2*v+1,tt+1,r,pos);
}

long long calc(int v,int qr){
    long long res=0;

    for(int i=tree[v].size()-1;i>=0 and tree[v][i].tim>=qr;i--){
        res+=tree[v][i].k;
    }
    return res;
}

long long howmany(int v,int l,int r,int pos,int qr){
    if(l==r){
        return calc(v,qr);
    }else{
        int tt=(l+r)/2;
        if(pos<=tt)return howmany(2*v,l,tt,pos,qr) + calc(v,qr);
        else return howmany(2*v+1,tt+1,r,pos,qr) + calc(v,qr);
    }
}

int bin(int s,long long t){
    int l=0,r=q+1,tt;
    while(l+1<r){
        tt=(l+r)/2;
        if(howmany(1,1,n,s,tt)>=t){
            l=tt;
        }else{
            r=tt;
        }
    }

    return c[l];
}

int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    cin>>n>>m>>q;
    
    for(int i=1;i<=q;i++){
        cin>>type;
        if(type==1){
            cin>>l>>r>>s>>t;
            c[i]=s;

            //add(1,1,n,l,r,t);
            for(int i=l;i<=r;i++){
                minsz[i]+=t;
            }

            update(1,1,n,l,r,{s,i,t});
        }else if(type==2){
            cin>>l>>r>>s;
            //rem(1,1,n,l,r,s);
            for(int i=l;i<=r;i++){
                minsz[i]=max(minsz[i]-s,0LL);
            }
        }else{
            cin>>s>>t;
            if(minsz[s]<t)cout<<"0\n";
            else cout<<bin(s,minsz[s]-t+1)<<"\n";
        }
    }

    return 0;
}

Compilation message

foodcourt.cpp: In function 'int main()':
foodcourt.cpp:159:31: warning: narrowing conversion of 's' from 'long long int' to 'int' [-Wnarrowing]
  159 |             update(1,1,n,l,r,{s,i,t});
      |                               ^
foodcourt.cpp: In function 'long long int getsz(int, int, int, int)':
foodcourt.cpp:104:15: warning: control reaches end of non-void function [-Wreturn-type]
  104 |     else getsz(2*v+1,tt+1,r,pos);
      |          ~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 97104 KB Output is correct
2 Correct 31 ms 97248 KB Output is correct
3 Correct 30 ms 97112 KB Output is correct
4 Correct 33 ms 97372 KB Output is correct
5 Correct 29 ms 96860 KB Output is correct
6 Correct 31 ms 94812 KB Output is correct
7 Correct 34 ms 97372 KB Output is correct
8 Correct 33 ms 97364 KB Output is correct
9 Correct 31 ms 97112 KB Output is correct
10 Correct 33 ms 97368 KB Output is correct
11 Correct 31 ms 95320 KB Output is correct
12 Correct 33 ms 97108 KB Output is correct
13 Correct 31 ms 96856 KB Output is correct
14 Correct 31 ms 95068 KB Output is correct
15 Correct 31 ms 97112 KB Output is correct
16 Correct 31 ms 97372 KB Output is correct
17 Correct 31 ms 97116 KB Output is correct
18 Correct 31 ms 95160 KB Output is correct
19 Correct 30 ms 97040 KB Output is correct
20 Correct 31 ms 97288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 97104 KB Output is correct
2 Correct 31 ms 97248 KB Output is correct
3 Correct 30 ms 97112 KB Output is correct
4 Correct 33 ms 97372 KB Output is correct
5 Correct 29 ms 96860 KB Output is correct
6 Correct 31 ms 94812 KB Output is correct
7 Correct 34 ms 97372 KB Output is correct
8 Correct 33 ms 97364 KB Output is correct
9 Correct 31 ms 97112 KB Output is correct
10 Correct 33 ms 97368 KB Output is correct
11 Correct 31 ms 95320 KB Output is correct
12 Correct 33 ms 97108 KB Output is correct
13 Correct 31 ms 96856 KB Output is correct
14 Correct 31 ms 95068 KB Output is correct
15 Correct 31 ms 97112 KB Output is correct
16 Correct 31 ms 97372 KB Output is correct
17 Correct 31 ms 97116 KB Output is correct
18 Correct 31 ms 95160 KB Output is correct
19 Correct 30 ms 97040 KB Output is correct
20 Correct 31 ms 97288 KB Output is correct
21 Correct 31 ms 95068 KB Output is correct
22 Correct 32 ms 97320 KB Output is correct
23 Correct 32 ms 97364 KB Output is correct
24 Correct 32 ms 97364 KB Output is correct
25 Correct 30 ms 94984 KB Output is correct
26 Correct 29 ms 97108 KB Output is correct
27 Correct 32 ms 97312 KB Output is correct
28 Correct 32 ms 97372 KB Output is correct
29 Correct 32 ms 97364 KB Output is correct
30 Correct 32 ms 97368 KB Output is correct
31 Correct 32 ms 97364 KB Output is correct
32 Correct 32 ms 97364 KB Output is correct
33 Correct 31 ms 97116 KB Output is correct
34 Correct 34 ms 95068 KB Output is correct
35 Correct 31 ms 97284 KB Output is correct
36 Correct 34 ms 97372 KB Output is correct
37 Correct 31 ms 97116 KB Output is correct
38 Correct 30 ms 97216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 475 ms 100188 KB Output is correct
2 Correct 381 ms 103204 KB Output is correct
3 Correct 461 ms 102724 KB Output is correct
4 Correct 479 ms 101196 KB Output is correct
5 Correct 401 ms 104544 KB Output is correct
6 Correct 401 ms 104472 KB Output is correct
7 Correct 71 ms 97788 KB Output is correct
8 Correct 62 ms 97872 KB Output is correct
9 Correct 736 ms 98772 KB Output is correct
10 Correct 741 ms 98896 KB Output is correct
11 Correct 732 ms 102440 KB Output is correct
12 Correct 743 ms 100608 KB Output is correct
13 Correct 197 ms 103120 KB Output is correct
14 Correct 264 ms 102212 KB Output is correct
15 Correct 96 ms 105300 KB Output is correct
16 Correct 114 ms 101972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1052 ms 106188 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 97104 KB Output is correct
2 Correct 31 ms 97248 KB Output is correct
3 Correct 30 ms 97112 KB Output is correct
4 Correct 33 ms 97372 KB Output is correct
5 Correct 29 ms 96860 KB Output is correct
6 Correct 31 ms 94812 KB Output is correct
7 Correct 34 ms 97372 KB Output is correct
8 Correct 33 ms 97364 KB Output is correct
9 Correct 31 ms 97112 KB Output is correct
10 Correct 33 ms 97368 KB Output is correct
11 Correct 31 ms 95320 KB Output is correct
12 Correct 33 ms 97108 KB Output is correct
13 Correct 31 ms 96856 KB Output is correct
14 Correct 31 ms 95068 KB Output is correct
15 Correct 31 ms 97112 KB Output is correct
16 Correct 31 ms 97372 KB Output is correct
17 Correct 31 ms 97116 KB Output is correct
18 Correct 31 ms 95160 KB Output is correct
19 Correct 30 ms 97040 KB Output is correct
20 Correct 31 ms 97288 KB Output is correct
21 Correct 475 ms 100188 KB Output is correct
22 Correct 381 ms 103204 KB Output is correct
23 Correct 461 ms 102724 KB Output is correct
24 Correct 479 ms 101196 KB Output is correct
25 Correct 401 ms 104544 KB Output is correct
26 Correct 401 ms 104472 KB Output is correct
27 Correct 71 ms 97788 KB Output is correct
28 Correct 62 ms 97872 KB Output is correct
29 Correct 736 ms 98772 KB Output is correct
30 Correct 741 ms 98896 KB Output is correct
31 Correct 732 ms 102440 KB Output is correct
32 Correct 743 ms 100608 KB Output is correct
33 Correct 197 ms 103120 KB Output is correct
34 Correct 264 ms 102212 KB Output is correct
35 Correct 96 ms 105300 KB Output is correct
36 Correct 114 ms 101972 KB Output is correct
37 Correct 643 ms 109028 KB Output is correct
38 Correct 849 ms 112680 KB Output is correct
39 Correct 80 ms 95828 KB Output is correct
40 Correct 75 ms 97996 KB Output is correct
41 Execution timed out 1065 ms 110416 KB Time limit exceeded
42 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 821 ms 113332 KB Output is correct
2 Correct 891 ms 114556 KB Output is correct
3 Correct 975 ms 115028 KB Output is correct
4 Correct 786 ms 110776 KB Output is correct
5 Execution timed out 1028 ms 113212 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 97104 KB Output is correct
2 Correct 31 ms 97248 KB Output is correct
3 Correct 30 ms 97112 KB Output is correct
4 Correct 33 ms 97372 KB Output is correct
5 Correct 29 ms 96860 KB Output is correct
6 Correct 31 ms 94812 KB Output is correct
7 Correct 34 ms 97372 KB Output is correct
8 Correct 33 ms 97364 KB Output is correct
9 Correct 31 ms 97112 KB Output is correct
10 Correct 33 ms 97368 KB Output is correct
11 Correct 31 ms 95320 KB Output is correct
12 Correct 33 ms 97108 KB Output is correct
13 Correct 31 ms 96856 KB Output is correct
14 Correct 31 ms 95068 KB Output is correct
15 Correct 31 ms 97112 KB Output is correct
16 Correct 31 ms 97372 KB Output is correct
17 Correct 31 ms 97116 KB Output is correct
18 Correct 31 ms 95160 KB Output is correct
19 Correct 30 ms 97040 KB Output is correct
20 Correct 31 ms 97288 KB Output is correct
21 Correct 31 ms 95068 KB Output is correct
22 Correct 32 ms 97320 KB Output is correct
23 Correct 32 ms 97364 KB Output is correct
24 Correct 32 ms 97364 KB Output is correct
25 Correct 30 ms 94984 KB Output is correct
26 Correct 29 ms 97108 KB Output is correct
27 Correct 32 ms 97312 KB Output is correct
28 Correct 32 ms 97372 KB Output is correct
29 Correct 32 ms 97364 KB Output is correct
30 Correct 32 ms 97368 KB Output is correct
31 Correct 32 ms 97364 KB Output is correct
32 Correct 32 ms 97364 KB Output is correct
33 Correct 31 ms 97116 KB Output is correct
34 Correct 34 ms 95068 KB Output is correct
35 Correct 31 ms 97284 KB Output is correct
36 Correct 34 ms 97372 KB Output is correct
37 Correct 31 ms 97116 KB Output is correct
38 Correct 30 ms 97216 KB Output is correct
39 Correct 475 ms 100188 KB Output is correct
40 Correct 381 ms 103204 KB Output is correct
41 Correct 461 ms 102724 KB Output is correct
42 Correct 479 ms 101196 KB Output is correct
43 Correct 401 ms 104544 KB Output is correct
44 Correct 401 ms 104472 KB Output is correct
45 Correct 71 ms 97788 KB Output is correct
46 Correct 62 ms 97872 KB Output is correct
47 Correct 736 ms 98772 KB Output is correct
48 Correct 741 ms 98896 KB Output is correct
49 Correct 732 ms 102440 KB Output is correct
50 Correct 743 ms 100608 KB Output is correct
51 Correct 197 ms 103120 KB Output is correct
52 Correct 264 ms 102212 KB Output is correct
53 Correct 96 ms 105300 KB Output is correct
54 Correct 114 ms 101972 KB Output is correct
55 Correct 643 ms 109028 KB Output is correct
56 Correct 849 ms 112680 KB Output is correct
57 Correct 80 ms 95828 KB Output is correct
58 Correct 75 ms 97996 KB Output is correct
59 Execution timed out 1065 ms 110416 KB Time limit exceeded
60 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 97104 KB Output is correct
2 Correct 31 ms 97248 KB Output is correct
3 Correct 30 ms 97112 KB Output is correct
4 Correct 33 ms 97372 KB Output is correct
5 Correct 29 ms 96860 KB Output is correct
6 Correct 31 ms 94812 KB Output is correct
7 Correct 34 ms 97372 KB Output is correct
8 Correct 33 ms 97364 KB Output is correct
9 Correct 31 ms 97112 KB Output is correct
10 Correct 33 ms 97368 KB Output is correct
11 Correct 31 ms 95320 KB Output is correct
12 Correct 33 ms 97108 KB Output is correct
13 Correct 31 ms 96856 KB Output is correct
14 Correct 31 ms 95068 KB Output is correct
15 Correct 31 ms 97112 KB Output is correct
16 Correct 31 ms 97372 KB Output is correct
17 Correct 31 ms 97116 KB Output is correct
18 Correct 31 ms 95160 KB Output is correct
19 Correct 30 ms 97040 KB Output is correct
20 Correct 31 ms 97288 KB Output is correct
21 Correct 31 ms 95068 KB Output is correct
22 Correct 32 ms 97320 KB Output is correct
23 Correct 32 ms 97364 KB Output is correct
24 Correct 32 ms 97364 KB Output is correct
25 Correct 30 ms 94984 KB Output is correct
26 Correct 29 ms 97108 KB Output is correct
27 Correct 32 ms 97312 KB Output is correct
28 Correct 32 ms 97372 KB Output is correct
29 Correct 32 ms 97364 KB Output is correct
30 Correct 32 ms 97368 KB Output is correct
31 Correct 32 ms 97364 KB Output is correct
32 Correct 32 ms 97364 KB Output is correct
33 Correct 31 ms 97116 KB Output is correct
34 Correct 34 ms 95068 KB Output is correct
35 Correct 31 ms 97284 KB Output is correct
36 Correct 34 ms 97372 KB Output is correct
37 Correct 31 ms 97116 KB Output is correct
38 Correct 30 ms 97216 KB Output is correct
39 Correct 475 ms 100188 KB Output is correct
40 Correct 381 ms 103204 KB Output is correct
41 Correct 461 ms 102724 KB Output is correct
42 Correct 479 ms 101196 KB Output is correct
43 Correct 401 ms 104544 KB Output is correct
44 Correct 401 ms 104472 KB Output is correct
45 Correct 71 ms 97788 KB Output is correct
46 Correct 62 ms 97872 KB Output is correct
47 Correct 736 ms 98772 KB Output is correct
48 Correct 741 ms 98896 KB Output is correct
49 Correct 732 ms 102440 KB Output is correct
50 Correct 743 ms 100608 KB Output is correct
51 Correct 197 ms 103120 KB Output is correct
52 Correct 264 ms 102212 KB Output is correct
53 Correct 96 ms 105300 KB Output is correct
54 Correct 114 ms 101972 KB Output is correct
55 Execution timed out 1052 ms 106188 KB Time limit exceeded
56 Halted 0 ms 0 KB -