Submission #1007062

# Submission time Handle Problem Language Result Execution time Memory
1007062 2024-06-24T11:18:42 Z Unforgettablepl Food Court (JOI21_foodcourt) C++17
35 / 100
1000 ms 388800 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[2000000];

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;
    }
    merge(tree[2*x],tree[x]);
    merge(tree[2*x+1],tree[x]);
    tree[x] = {0,0};
    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);
}

struct fenwick{
    vector<int> tree;
    fenwick(int n):tree(n+1){}
    int get(int x){
        int ans = 0;
        while(x){
            ans+=tree[x];
            x-=x&-x;
        }
        return ans;
    }
    void update(int x,int k){
        while(x<tree.size()){
            tree[x]+=k;
            x+=x&-x;
        }
    }
};

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int m,q;
    cin >> n >> m >> q;
    if(n<=2000 and q<=2000)solve1(n,m,q);
    if(m==1)solve2(n,m,q);
    vector<deque<int>> queues(n+1);
    fenwick fen(n);
    auto calc = [&](int x){
        int tar = fen.get(x);
        fen.update(x,-tar);
        fen.update(x+1,tar);
        while(tar-- and !queues[x].empty())queues[x].pop_front();
    };
    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++){
                calc(x);
                queues[x].emplace_back(c);
            }
        } else if(type==2){
            int l,r,k;cin>>l>>r>>k;
            fen.update(l,k);
            fen.update(r+1,-k);
        } else {
            int a,b;cin>>a>>b;
            calc(a);
            if(queues[a].size()<b)cout<<"0\n";
            else cout<<queues[a][b-1]<<'\n';
        }
    }
}

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++){
      |                         ~^~~~~~~~~~~~~~~~~
foodcourt.cpp: In member function 'void fenwick::update(long long int, long long int)':
foodcourt.cpp:110:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  110 |         while(x<tree.size()){
      |               ~^~~~~~~~~~~~
foodcourt.cpp: In function 'int32_t main()':
foodcourt.cpp:147:32: warning: comparison of integer expressions of different signedness: 'std::deque<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
  147 |             if(queues[a].size()<b)cout<<"0\n";
      |                ~~~~~~~~~~~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1884 KB Output is correct
2 Correct 5 ms 2396 KB Output is correct
3 Correct 7 ms 9152 KB Output is correct
4 Correct 11 ms 12636 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 14 ms 14172 KB Output is correct
8 Correct 11 ms 9816 KB Output is correct
9 Correct 7 ms 2652 KB Output is correct
10 Correct 10 ms 9308 KB Output is correct
11 Correct 13 ms 6480 KB Output is correct
12 Correct 7 ms 2648 KB Output is correct
13 Correct 10 ms 2620 KB Output is correct
14 Correct 13 ms 3864 KB Output is correct
15 Correct 8 ms 4700 KB Output is correct
16 Correct 11 ms 3928 KB Output is correct
17 Correct 4 ms 1628 KB Output is correct
18 Correct 6 ms 2140 KB Output is correct
19 Correct 1 ms 1372 KB Output is correct
20 Correct 1 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1884 KB Output is correct
2 Correct 5 ms 2396 KB Output is correct
3 Correct 7 ms 9152 KB Output is correct
4 Correct 11 ms 12636 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 14 ms 14172 KB Output is correct
8 Correct 11 ms 9816 KB Output is correct
9 Correct 7 ms 2652 KB Output is correct
10 Correct 10 ms 9308 KB Output is correct
11 Correct 13 ms 6480 KB Output is correct
12 Correct 7 ms 2648 KB Output is correct
13 Correct 10 ms 2620 KB Output is correct
14 Correct 13 ms 3864 KB Output is correct
15 Correct 8 ms 4700 KB Output is correct
16 Correct 11 ms 3928 KB Output is correct
17 Correct 4 ms 1628 KB Output is correct
18 Correct 6 ms 2140 KB Output is correct
19 Correct 1 ms 1372 KB Output is correct
20 Correct 1 ms 1628 KB Output is correct
21 Correct 5 ms 2396 KB Output is correct
22 Correct 7 ms 2676 KB Output is correct
23 Correct 9 ms 8536 KB Output is correct
24 Correct 13 ms 12892 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 14 ms 13656 KB Output is correct
28 Correct 14 ms 10588 KB Output is correct
29 Correct 9 ms 4444 KB Output is correct
30 Correct 14 ms 8796 KB Output is correct
31 Correct 14 ms 6460 KB Output is correct
32 Correct 8 ms 2396 KB Output is correct
33 Correct 11 ms 2444 KB Output is correct
34 Correct 14 ms 4944 KB Output is correct
35 Correct 9 ms 2908 KB Output is correct
36 Correct 13 ms 3676 KB Output is correct
37 Correct 1 ms 1372 KB Output is correct
38 Correct 1 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 44740 KB Output is correct
2 Correct 41 ms 45908 KB Output is correct
3 Correct 39 ms 45880 KB Output is correct
4 Correct 40 ms 45908 KB Output is correct
5 Correct 51 ms 45908 KB Output is correct
6 Correct 44 ms 45908 KB Output is correct
7 Correct 11 ms 1116 KB Output is correct
8 Correct 11 ms 1116 KB Output is correct
9 Correct 40 ms 45908 KB Output is correct
10 Correct 39 ms 45908 KB Output is correct
11 Correct 39 ms 45908 KB Output is correct
12 Correct 36 ms 45908 KB Output is correct
13 Correct 33 ms 31272 KB Output is correct
14 Correct 40 ms 45652 KB Output is correct
15 Correct 44 ms 31828 KB Output is correct
16 Correct 47 ms 45908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 165 ms 8788 KB Output is correct
2 Correct 131 ms 8684 KB Output is correct
3 Correct 202 ms 8784 KB Output is correct
4 Correct 143 ms 8684 KB Output is correct
5 Correct 141 ms 8684 KB Output is correct
6 Correct 195 ms 8536 KB Output is correct
7 Correct 42 ms 556 KB Output is correct
8 Correct 44 ms 584 KB Output is correct
9 Correct 178 ms 8788 KB Output is correct
10 Correct 174 ms 8788 KB Output is correct
11 Correct 173 ms 8540 KB Output is correct
12 Correct 184 ms 8540 KB Output is correct
13 Correct 176 ms 8536 KB Output is correct
14 Correct 191 ms 8540 KB Output is correct
15 Correct 187 ms 8684 KB Output is correct
16 Correct 194 ms 8540 KB Output is correct
17 Correct 182 ms 8540 KB Output is correct
18 Correct 185 ms 8540 KB Output is correct
19 Correct 180 ms 8916 KB Output is correct
20 Correct 186 ms 8536 KB Output is correct
21 Correct 195 ms 8680 KB Output is correct
22 Correct 187 ms 8792 KB Output is correct
23 Correct 184 ms 8536 KB Output is correct
24 Correct 203 ms 8788 KB Output is correct
25 Correct 157 ms 8716 KB Output is correct
26 Correct 190 ms 8788 KB Output is correct
27 Correct 134 ms 8660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1884 KB Output is correct
2 Correct 5 ms 2396 KB Output is correct
3 Correct 7 ms 9152 KB Output is correct
4 Correct 11 ms 12636 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 14 ms 14172 KB Output is correct
8 Correct 11 ms 9816 KB Output is correct
9 Correct 7 ms 2652 KB Output is correct
10 Correct 10 ms 9308 KB Output is correct
11 Correct 13 ms 6480 KB Output is correct
12 Correct 7 ms 2648 KB Output is correct
13 Correct 10 ms 2620 KB Output is correct
14 Correct 13 ms 3864 KB Output is correct
15 Correct 8 ms 4700 KB Output is correct
16 Correct 11 ms 3928 KB Output is correct
17 Correct 4 ms 1628 KB Output is correct
18 Correct 6 ms 2140 KB Output is correct
19 Correct 1 ms 1372 KB Output is correct
20 Correct 1 ms 1628 KB Output is correct
21 Correct 40 ms 44740 KB Output is correct
22 Correct 41 ms 45908 KB Output is correct
23 Correct 39 ms 45880 KB Output is correct
24 Correct 40 ms 45908 KB Output is correct
25 Correct 51 ms 45908 KB Output is correct
26 Correct 44 ms 45908 KB Output is correct
27 Correct 11 ms 1116 KB Output is correct
28 Correct 11 ms 1116 KB Output is correct
29 Correct 40 ms 45908 KB Output is correct
30 Correct 39 ms 45908 KB Output is correct
31 Correct 39 ms 45908 KB Output is correct
32 Correct 36 ms 45908 KB Output is correct
33 Correct 33 ms 31272 KB Output is correct
34 Correct 40 ms 45652 KB Output is correct
35 Correct 44 ms 31828 KB Output is correct
36 Correct 47 ms 45908 KB Output is correct
37 Execution timed out 1055 ms 55256 KB Time limit exceeded
38 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1062 ms 388800 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1884 KB Output is correct
2 Correct 5 ms 2396 KB Output is correct
3 Correct 7 ms 9152 KB Output is correct
4 Correct 11 ms 12636 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 14 ms 14172 KB Output is correct
8 Correct 11 ms 9816 KB Output is correct
9 Correct 7 ms 2652 KB Output is correct
10 Correct 10 ms 9308 KB Output is correct
11 Correct 13 ms 6480 KB Output is correct
12 Correct 7 ms 2648 KB Output is correct
13 Correct 10 ms 2620 KB Output is correct
14 Correct 13 ms 3864 KB Output is correct
15 Correct 8 ms 4700 KB Output is correct
16 Correct 11 ms 3928 KB Output is correct
17 Correct 4 ms 1628 KB Output is correct
18 Correct 6 ms 2140 KB Output is correct
19 Correct 1 ms 1372 KB Output is correct
20 Correct 1 ms 1628 KB Output is correct
21 Correct 5 ms 2396 KB Output is correct
22 Correct 7 ms 2676 KB Output is correct
23 Correct 9 ms 8536 KB Output is correct
24 Correct 13 ms 12892 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 14 ms 13656 KB Output is correct
28 Correct 14 ms 10588 KB Output is correct
29 Correct 9 ms 4444 KB Output is correct
30 Correct 14 ms 8796 KB Output is correct
31 Correct 14 ms 6460 KB Output is correct
32 Correct 8 ms 2396 KB Output is correct
33 Correct 11 ms 2444 KB Output is correct
34 Correct 14 ms 4944 KB Output is correct
35 Correct 9 ms 2908 KB Output is correct
36 Correct 13 ms 3676 KB Output is correct
37 Correct 1 ms 1372 KB Output is correct
38 Correct 1 ms 1628 KB Output is correct
39 Correct 40 ms 44740 KB Output is correct
40 Correct 41 ms 45908 KB Output is correct
41 Correct 39 ms 45880 KB Output is correct
42 Correct 40 ms 45908 KB Output is correct
43 Correct 51 ms 45908 KB Output is correct
44 Correct 44 ms 45908 KB Output is correct
45 Correct 11 ms 1116 KB Output is correct
46 Correct 11 ms 1116 KB Output is correct
47 Correct 40 ms 45908 KB Output is correct
48 Correct 39 ms 45908 KB Output is correct
49 Correct 39 ms 45908 KB Output is correct
50 Correct 36 ms 45908 KB Output is correct
51 Correct 33 ms 31272 KB Output is correct
52 Correct 40 ms 45652 KB Output is correct
53 Correct 44 ms 31828 KB Output is correct
54 Correct 47 ms 45908 KB Output is correct
55 Execution timed out 1055 ms 55256 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1884 KB Output is correct
2 Correct 5 ms 2396 KB Output is correct
3 Correct 7 ms 9152 KB Output is correct
4 Correct 11 ms 12636 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 14 ms 14172 KB Output is correct
8 Correct 11 ms 9816 KB Output is correct
9 Correct 7 ms 2652 KB Output is correct
10 Correct 10 ms 9308 KB Output is correct
11 Correct 13 ms 6480 KB Output is correct
12 Correct 7 ms 2648 KB Output is correct
13 Correct 10 ms 2620 KB Output is correct
14 Correct 13 ms 3864 KB Output is correct
15 Correct 8 ms 4700 KB Output is correct
16 Correct 11 ms 3928 KB Output is correct
17 Correct 4 ms 1628 KB Output is correct
18 Correct 6 ms 2140 KB Output is correct
19 Correct 1 ms 1372 KB Output is correct
20 Correct 1 ms 1628 KB Output is correct
21 Correct 5 ms 2396 KB Output is correct
22 Correct 7 ms 2676 KB Output is correct
23 Correct 9 ms 8536 KB Output is correct
24 Correct 13 ms 12892 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 14 ms 13656 KB Output is correct
28 Correct 14 ms 10588 KB Output is correct
29 Correct 9 ms 4444 KB Output is correct
30 Correct 14 ms 8796 KB Output is correct
31 Correct 14 ms 6460 KB Output is correct
32 Correct 8 ms 2396 KB Output is correct
33 Correct 11 ms 2444 KB Output is correct
34 Correct 14 ms 4944 KB Output is correct
35 Correct 9 ms 2908 KB Output is correct
36 Correct 13 ms 3676 KB Output is correct
37 Correct 1 ms 1372 KB Output is correct
38 Correct 1 ms 1628 KB Output is correct
39 Correct 40 ms 44740 KB Output is correct
40 Correct 41 ms 45908 KB Output is correct
41 Correct 39 ms 45880 KB Output is correct
42 Correct 40 ms 45908 KB Output is correct
43 Correct 51 ms 45908 KB Output is correct
44 Correct 44 ms 45908 KB Output is correct
45 Correct 11 ms 1116 KB Output is correct
46 Correct 11 ms 1116 KB Output is correct
47 Correct 40 ms 45908 KB Output is correct
48 Correct 39 ms 45908 KB Output is correct
49 Correct 39 ms 45908 KB Output is correct
50 Correct 36 ms 45908 KB Output is correct
51 Correct 33 ms 31272 KB Output is correct
52 Correct 40 ms 45652 KB Output is correct
53 Correct 44 ms 31828 KB Output is correct
54 Correct 47 ms 45908 KB Output is correct
55 Correct 165 ms 8788 KB Output is correct
56 Correct 131 ms 8684 KB Output is correct
57 Correct 202 ms 8784 KB Output is correct
58 Correct 143 ms 8684 KB Output is correct
59 Correct 141 ms 8684 KB Output is correct
60 Correct 195 ms 8536 KB Output is correct
61 Correct 42 ms 556 KB Output is correct
62 Correct 44 ms 584 KB Output is correct
63 Correct 178 ms 8788 KB Output is correct
64 Correct 174 ms 8788 KB Output is correct
65 Correct 173 ms 8540 KB Output is correct
66 Correct 184 ms 8540 KB Output is correct
67 Correct 176 ms 8536 KB Output is correct
68 Correct 191 ms 8540 KB Output is correct
69 Correct 187 ms 8684 KB Output is correct
70 Correct 194 ms 8540 KB Output is correct
71 Correct 182 ms 8540 KB Output is correct
72 Correct 185 ms 8540 KB Output is correct
73 Correct 180 ms 8916 KB Output is correct
74 Correct 186 ms 8536 KB Output is correct
75 Correct 195 ms 8680 KB Output is correct
76 Correct 187 ms 8792 KB Output is correct
77 Correct 184 ms 8536 KB Output is correct
78 Correct 203 ms 8788 KB Output is correct
79 Correct 157 ms 8716 KB Output is correct
80 Correct 190 ms 8788 KB Output is correct
81 Correct 134 ms 8660 KB Output is correct
82 Execution timed out 1055 ms 55256 KB Time limit exceeded
83 Halted 0 ms 0 KB -