답안 #1007028

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1007028 2024-06-24T10:59:42 Z Unforgettablepl 푸드 코트 (JOI21_foodcourt) C++17
0 / 100
122 ms 8660 KB
#include <bits/stdc++.h>
using namespace std;

// #define x first
// #define y second

#define int long long

void solve1(int n,int m,int q){
    vector<deque<pair<int,int>>> queues(n+1);
    for(int i=1;i<=q;i++){
        int type;cin>>type;
        if(type==1){
            int l,r,c,k;cin>>l>>r>>c>>k;
            for(int x=l;x<=r;x++)queues[x].emplace_back(k,c);
        } else if(type==2){
            int l,r,k;cin>>l>>r>>k;
            for(int x=l;x<=r;x++){
                int tar = k;
                while(tar and !queues[x].empty()){
                    if(queues[x].front().first<=tar){
                        tar-=queues[x].front().first;
                        queues[x].pop_front();
                    } else {
                        queues[x].front().first-=tar;
                        tar = 0;
                    }
                }
            }
        } else {
            int a,b;cin>>a>>b;
            int curr = 0;
            for(int i=0;i<queues[a].size();i++){
                curr+=queues[a][i].first;
                if(curr>=b){cout<<queues[a][i].second<<'\n';break;}
            }
            if(curr<b)cout<<"0\n";
        }
    }
    exit(0);
}

pair<int,int> tree[524288];

void merge(pair<int,int> &a,pair<int,int> b){
    int cut = min(a.second,b.first);
    a.second-=cut;
    b.first-=cut;
    a.first+=b.first;
    a.second+=b.second;
}
int n;

void update(int qL,int qR,pair<int,int> qu,int x=1,int l=1,int r=n){
    if(qR<l or r<qL)return;
    if(qL<=l and r<=qR){
        merge(tree[x],qu);
        return;
    }
    int mid = (l+r)/2;
    update(qL,qR,qu,2*x,l,mid);
    update(qL,qR,qu,2*x+1,mid+1,r);
}

int get(int qu,int x=1,int l=1,int r=n){
    if(qu<l or r<qu)return 0;
    if(l==r){
        return tree[x].second;
    }
    merge(tree[2*x],tree[x]);
    merge(tree[2*x+1],tree[x]);
    tree[x] = {0,0};
    int mid = (l+r)/2;
    return get(qu,2*x,l,mid)+get(qu,2*x+1,mid+1,r);
}

void solve2(int n,int m,int q){
    for(int i=1;i<=q;i++){
        int type;cin>>type;
        if(type==1){
            int l,r,c,k;cin>>l>>r>>c>>k;
            update(l,r,{0,k});
        } else if(type==2){
            int l,r,k;cin>>l>>r>>k;
            update(l,r,{k,0});
        } else {
            int a,b;cin>>a>>b;
            if(get(a)<b)cout<<"0\n";
            else cout<<"1\n";
        }
    }
    exit(0);
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int m,q;
    cin >> n >> m >> q;
    solve2(n,m,q);
    if(n<=2000 and q<=2000)solve1(n,m,q);
    if(m==1)solve2(n,m,q);
}

Compilation message

foodcourt.cpp: In function 'void solve1(long long int, long long int, long long int)':
foodcourt.cpp:33:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::deque<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |             for(int i=0;i<queues[a].size();i++){
      |                         ~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 31 ms 3668 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 122 ms 8660 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 33 ms 3932 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -