Submission #1047648

# Submission time Handle Problem Language Result Execution time Memory
1047648 2024-08-07T14:41:12 Z Andrey Food Court (JOI21_foodcourt) C++14
68 / 100
205 ms 87660 KB
#include<bits/stdc++.h>
using namespace std;

vector<pair<pair<long long,long long>,long long>> haha[250001];
vector<pair<long long,long long>> bruh[250001];
vector<long long> seg(1000001);
vector<long long> wow(1000001);
vector<long long> idk(500001);
vector<long long> troll(500001);

long long calc3(long long a) {
    long long c = 0,ans = 0;
    for(long long i = 19; i >= 0; i--) {
        if(c+(1 << i) <= a) {
            c+=(1 << i);
            ans+=troll[c];
        }
    }
    return ans;
}

void upd2(long long a, long long x, bool yo) {
    while(a < idk.size()) {
        if(yo) {
            idk[a]+=x;
        }
        else {
            troll[a]+=x;
        }
        a+=(a&(-a));
    }
}

long long dude(long long br) {
    long long c = 0;
    for(long long i = 19; i >= 0; i--) {
        if(c+(1 << i) < idk.size() && idk[c+(1 << i)] < br) {
            c+=(1 << i);
            br-=idk[c];
        }
    }
    return c;
}

void upd(long long l, long long r, long long ql, long long qr, long long x, long long br) {
    if(qr < ql) {
        return;
    }
    if(l == ql && r == qr) {
        seg[x]+=br;
        wow[x]+=br;
        return;
    }
    int mid = (l+r)/2;
    if(qr <= mid) {
        upd(l,mid,ql,qr,x*2,br);
    }
    else if(ql > mid) {
        upd(mid+1,r,ql,qr,x*2+1,br);
    }
    else {
        upd(l,mid,ql,mid,x*2,br);
        upd(mid+1,r,mid+1,qr,x*2+1,br);
    }
    seg[x] = min(seg[x*2],seg[x*2+1]);
    seg[x]+=wow[x];
}

long long calc(long long l, long long r, long long ql, long long qr, long long x) {
    if(l == ql && r == qr) {
        return seg[x];
    }
    long long ans = 0;
    long long mid = (l+r)/2;
    if(qr <= mid) {
        ans = calc(l,mid,ql,qr,x*2);
    }
    else if(ql > mid) {
        ans = calc(mid+1,r,ql,qr,x*2+1);
    }
    else {
        ans = min(calc(l,mid,ql,mid,x*2),calc(mid+1,r,mid+1,qr,x*2+1));
    }
    return ans+wow[x];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n,m,q;
    cin >> n >> m >> q;
    vector<long long> col(q+1);
    for(long long i = 1; i <= q; i++) {
        long long t,l,r,x,br;
        cin >> t;
        if(t == 1) {
            cin >> l >> r >> x >> br;
            haha[l].push_back({{i,br},0});
            haha[r+1].push_back({{i,-br},0});
            col[i] = x;
        }
        else if(t == 2) {
            cin >> l >> r >> br;
            haha[l].push_back({{i,-br},1});
            haha[r+1].push_back({{i,br},1});
        }
        else {
            cin >> l >> br;
            bruh[l].push_back({i,br});
        }
    }
    vector<long long> ans(q+1,-1);
    for(long long i = 1; i <= n; i++) {
        for(pair<pair<long long,long long>,long long> v: haha[i]) {
            long long p = v.first.first,c = v.first.second;
            upd(1,q,p,q,1,c);
            if(v.second) {
                upd2(p,-c,0);
            }
            else {
                upd2(p,c,1);
            }
        }
        for(pair<long long,long long> v: bruh[i]) {
            long long br = v.second;
            br+=calc3(v.first);
            br+=min(0LL,calc(1,q,1,v.first,1));
            long long c = dude(br);
            if(c >= v.first) {
                ans[v.first] = 0;
            }
            else {
                ans[v.first] = col[c+1];
            }
        }
    }
    for(long long i = 1; i <= q; i++) {
        if(ans[i] != -1) {
            cout << ans[i] << "\n";
        }
    }
    return 0;
}

Compilation message

foodcourt.cpp: In function 'void upd2(long long int, long long int, bool)':
foodcourt.cpp:23:13: 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]
   23 |     while(a < idk.size()) {
      |           ~~^~~~~~~~~~~~
foodcourt.cpp: In function 'long long int dude(long long int)':
foodcourt.cpp:37:23: 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]
   37 |         if(c+(1 << i) < idk.size() && idk[c+(1 << i)] < br) {
      |            ~~~~~~~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 35676 KB Output is correct
2 Correct 7 ms 35676 KB Output is correct
3 Correct 8 ms 35672 KB Output is correct
4 Correct 8 ms 35680 KB Output is correct
5 Correct 6 ms 35676 KB Output is correct
6 Correct 6 ms 35676 KB Output is correct
7 Correct 7 ms 35676 KB Output is correct
8 Correct 7 ms 35720 KB Output is correct
9 Correct 8 ms 35676 KB Output is correct
10 Correct 7 ms 35672 KB Output is correct
11 Correct 7 ms 35672 KB Output is correct
12 Correct 6 ms 35824 KB Output is correct
13 Correct 7 ms 35676 KB Output is correct
14 Correct 7 ms 35832 KB Output is correct
15 Correct 7 ms 35672 KB Output is correct
16 Correct 7 ms 35676 KB Output is correct
17 Correct 6 ms 35676 KB Output is correct
18 Correct 7 ms 35676 KB Output is correct
19 Correct 7 ms 35876 KB Output is correct
20 Correct 7 ms 35672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 35676 KB Output is correct
2 Correct 7 ms 35676 KB Output is correct
3 Correct 8 ms 35672 KB Output is correct
4 Correct 8 ms 35680 KB Output is correct
5 Correct 6 ms 35676 KB Output is correct
6 Correct 6 ms 35676 KB Output is correct
7 Correct 7 ms 35676 KB Output is correct
8 Correct 7 ms 35720 KB Output is correct
9 Correct 8 ms 35676 KB Output is correct
10 Correct 7 ms 35672 KB Output is correct
11 Correct 7 ms 35672 KB Output is correct
12 Correct 6 ms 35824 KB Output is correct
13 Correct 7 ms 35676 KB Output is correct
14 Correct 7 ms 35832 KB Output is correct
15 Correct 7 ms 35672 KB Output is correct
16 Correct 7 ms 35676 KB Output is correct
17 Correct 6 ms 35676 KB Output is correct
18 Correct 7 ms 35676 KB Output is correct
19 Correct 7 ms 35876 KB Output is correct
20 Correct 7 ms 35672 KB Output is correct
21 Correct 7 ms 35672 KB Output is correct
22 Correct 8 ms 35676 KB Output is correct
23 Correct 7 ms 35848 KB Output is correct
24 Correct 7 ms 35672 KB Output is correct
25 Correct 6 ms 35676 KB Output is correct
26 Correct 6 ms 35676 KB Output is correct
27 Correct 7 ms 35676 KB Output is correct
28 Correct 7 ms 35676 KB Output is correct
29 Correct 7 ms 35776 KB Output is correct
30 Correct 7 ms 35676 KB Output is correct
31 Correct 7 ms 35724 KB Output is correct
32 Correct 7 ms 35676 KB Output is correct
33 Correct 7 ms 35832 KB Output is correct
34 Correct 8 ms 35676 KB Output is correct
35 Correct 8 ms 35852 KB Output is correct
36 Correct 8 ms 35836 KB Output is correct
37 Correct 7 ms 35688 KB Output is correct
38 Correct 7 ms 35676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 41300 KB Output is correct
2 Correct 46 ms 41612 KB Output is correct
3 Correct 46 ms 41128 KB Output is correct
4 Correct 51 ms 41296 KB Output is correct
5 Correct 44 ms 41620 KB Output is correct
6 Correct 49 ms 41564 KB Output is correct
7 Correct 25 ms 39808 KB Output is correct
8 Correct 27 ms 40052 KB Output is correct
9 Correct 45 ms 41560 KB Output is correct
10 Correct 46 ms 41564 KB Output is correct
11 Correct 47 ms 41628 KB Output is correct
12 Correct 47 ms 41564 KB Output is correct
13 Correct 38 ms 40536 KB Output is correct
14 Correct 45 ms 41272 KB Output is correct
15 Correct 47 ms 41812 KB Output is correct
16 Correct 46 ms 41944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 205 ms 56912 KB Output is correct
2 Correct 180 ms 52596 KB Output is correct
3 Runtime error 65 ms 87660 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 35676 KB Output is correct
2 Correct 7 ms 35676 KB Output is correct
3 Correct 8 ms 35672 KB Output is correct
4 Correct 8 ms 35680 KB Output is correct
5 Correct 6 ms 35676 KB Output is correct
6 Correct 6 ms 35676 KB Output is correct
7 Correct 7 ms 35676 KB Output is correct
8 Correct 7 ms 35720 KB Output is correct
9 Correct 8 ms 35676 KB Output is correct
10 Correct 7 ms 35672 KB Output is correct
11 Correct 7 ms 35672 KB Output is correct
12 Correct 6 ms 35824 KB Output is correct
13 Correct 7 ms 35676 KB Output is correct
14 Correct 7 ms 35832 KB Output is correct
15 Correct 7 ms 35672 KB Output is correct
16 Correct 7 ms 35676 KB Output is correct
17 Correct 6 ms 35676 KB Output is correct
18 Correct 7 ms 35676 KB Output is correct
19 Correct 7 ms 35876 KB Output is correct
20 Correct 7 ms 35672 KB Output is correct
21 Correct 48 ms 41300 KB Output is correct
22 Correct 46 ms 41612 KB Output is correct
23 Correct 46 ms 41128 KB Output is correct
24 Correct 51 ms 41296 KB Output is correct
25 Correct 44 ms 41620 KB Output is correct
26 Correct 49 ms 41564 KB Output is correct
27 Correct 25 ms 39808 KB Output is correct
28 Correct 27 ms 40052 KB Output is correct
29 Correct 45 ms 41560 KB Output is correct
30 Correct 46 ms 41564 KB Output is correct
31 Correct 47 ms 41628 KB Output is correct
32 Correct 47 ms 41564 KB Output is correct
33 Correct 38 ms 40536 KB Output is correct
34 Correct 45 ms 41272 KB Output is correct
35 Correct 47 ms 41812 KB Output is correct
36 Correct 46 ms 41944 KB Output is correct
37 Correct 42 ms 40532 KB Output is correct
38 Correct 42 ms 40280 KB Output is correct
39 Correct 24 ms 39292 KB Output is correct
40 Correct 30 ms 39912 KB Output is correct
41 Correct 49 ms 41392 KB Output is correct
42 Correct 50 ms 41304 KB Output is correct
43 Correct 52 ms 41440 KB Output is correct
44 Correct 52 ms 41296 KB Output is correct
45 Correct 49 ms 41352 KB Output is correct
46 Correct 45 ms 41352 KB Output is correct
47 Correct 33 ms 40316 KB Output is correct
48 Correct 48 ms 41820 KB Output is correct
49 Correct 36 ms 39772 KB Output is correct
50 Correct 41 ms 40540 KB Output is correct
51 Correct 51 ms 41552 KB Output is correct
52 Correct 54 ms 41416 KB Output is correct
53 Correct 63 ms 40540 KB Output is correct
54 Correct 50 ms 41816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 40676 KB Output is correct
2 Correct 53 ms 41280 KB Output is correct
3 Correct 55 ms 41308 KB Output is correct
4 Correct 42 ms 39760 KB Output is correct
5 Correct 52 ms 40628 KB Output is correct
6 Correct 51 ms 41308 KB Output is correct
7 Correct 26 ms 39728 KB Output is correct
8 Correct 29 ms 39548 KB Output is correct
9 Correct 39 ms 40772 KB Output is correct
10 Correct 50 ms 40016 KB Output is correct
11 Correct 44 ms 41308 KB Output is correct
12 Correct 48 ms 41368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 35676 KB Output is correct
2 Correct 7 ms 35676 KB Output is correct
3 Correct 8 ms 35672 KB Output is correct
4 Correct 8 ms 35680 KB Output is correct
5 Correct 6 ms 35676 KB Output is correct
6 Correct 6 ms 35676 KB Output is correct
7 Correct 7 ms 35676 KB Output is correct
8 Correct 7 ms 35720 KB Output is correct
9 Correct 8 ms 35676 KB Output is correct
10 Correct 7 ms 35672 KB Output is correct
11 Correct 7 ms 35672 KB Output is correct
12 Correct 6 ms 35824 KB Output is correct
13 Correct 7 ms 35676 KB Output is correct
14 Correct 7 ms 35832 KB Output is correct
15 Correct 7 ms 35672 KB Output is correct
16 Correct 7 ms 35676 KB Output is correct
17 Correct 6 ms 35676 KB Output is correct
18 Correct 7 ms 35676 KB Output is correct
19 Correct 7 ms 35876 KB Output is correct
20 Correct 7 ms 35672 KB Output is correct
21 Correct 7 ms 35672 KB Output is correct
22 Correct 8 ms 35676 KB Output is correct
23 Correct 7 ms 35848 KB Output is correct
24 Correct 7 ms 35672 KB Output is correct
25 Correct 6 ms 35676 KB Output is correct
26 Correct 6 ms 35676 KB Output is correct
27 Correct 7 ms 35676 KB Output is correct
28 Correct 7 ms 35676 KB Output is correct
29 Correct 7 ms 35776 KB Output is correct
30 Correct 7 ms 35676 KB Output is correct
31 Correct 7 ms 35724 KB Output is correct
32 Correct 7 ms 35676 KB Output is correct
33 Correct 7 ms 35832 KB Output is correct
34 Correct 8 ms 35676 KB Output is correct
35 Correct 8 ms 35852 KB Output is correct
36 Correct 8 ms 35836 KB Output is correct
37 Correct 7 ms 35688 KB Output is correct
38 Correct 7 ms 35676 KB Output is correct
39 Correct 48 ms 41300 KB Output is correct
40 Correct 46 ms 41612 KB Output is correct
41 Correct 46 ms 41128 KB Output is correct
42 Correct 51 ms 41296 KB Output is correct
43 Correct 44 ms 41620 KB Output is correct
44 Correct 49 ms 41564 KB Output is correct
45 Correct 25 ms 39808 KB Output is correct
46 Correct 27 ms 40052 KB Output is correct
47 Correct 45 ms 41560 KB Output is correct
48 Correct 46 ms 41564 KB Output is correct
49 Correct 47 ms 41628 KB Output is correct
50 Correct 47 ms 41564 KB Output is correct
51 Correct 38 ms 40536 KB Output is correct
52 Correct 45 ms 41272 KB Output is correct
53 Correct 47 ms 41812 KB Output is correct
54 Correct 46 ms 41944 KB Output is correct
55 Correct 42 ms 40532 KB Output is correct
56 Correct 42 ms 40280 KB Output is correct
57 Correct 24 ms 39292 KB Output is correct
58 Correct 30 ms 39912 KB Output is correct
59 Correct 49 ms 41392 KB Output is correct
60 Correct 50 ms 41304 KB Output is correct
61 Correct 52 ms 41440 KB Output is correct
62 Correct 52 ms 41296 KB Output is correct
63 Correct 49 ms 41352 KB Output is correct
64 Correct 45 ms 41352 KB Output is correct
65 Correct 33 ms 40316 KB Output is correct
66 Correct 48 ms 41820 KB Output is correct
67 Correct 36 ms 39772 KB Output is correct
68 Correct 41 ms 40540 KB Output is correct
69 Correct 51 ms 41552 KB Output is correct
70 Correct 54 ms 41416 KB Output is correct
71 Correct 63 ms 40540 KB Output is correct
72 Correct 50 ms 41816 KB Output is correct
73 Correct 45 ms 40676 KB Output is correct
74 Correct 53 ms 41280 KB Output is correct
75 Correct 55 ms 41308 KB Output is correct
76 Correct 42 ms 39760 KB Output is correct
77 Correct 52 ms 40628 KB Output is correct
78 Correct 51 ms 41308 KB Output is correct
79 Correct 26 ms 39728 KB Output is correct
80 Correct 29 ms 39548 KB Output is correct
81 Correct 39 ms 40772 KB Output is correct
82 Correct 50 ms 40016 KB Output is correct
83 Correct 44 ms 41308 KB Output is correct
84 Correct 48 ms 41368 KB Output is correct
85 Correct 48 ms 41188 KB Output is correct
86 Correct 55 ms 41808 KB Output is correct
87 Correct 45 ms 41300 KB Output is correct
88 Correct 52 ms 42008 KB Output is correct
89 Correct 33 ms 39768 KB Output is correct
90 Correct 49 ms 42068 KB Output is correct
91 Correct 42 ms 40796 KB Output is correct
92 Correct 39 ms 40540 KB Output is correct
93 Correct 52 ms 41884 KB Output is correct
94 Correct 51 ms 41992 KB Output is correct
95 Correct 51 ms 41804 KB Output is correct
96 Correct 54 ms 41928 KB Output is correct
97 Correct 52 ms 41952 KB Output is correct
98 Correct 43 ms 41052 KB Output is correct
99 Correct 33 ms 40668 KB Output is correct
100 Correct 40 ms 40784 KB Output is correct
101 Correct 45 ms 42332 KB Output is correct
102 Correct 46 ms 42316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 35676 KB Output is correct
2 Correct 7 ms 35676 KB Output is correct
3 Correct 8 ms 35672 KB Output is correct
4 Correct 8 ms 35680 KB Output is correct
5 Correct 6 ms 35676 KB Output is correct
6 Correct 6 ms 35676 KB Output is correct
7 Correct 7 ms 35676 KB Output is correct
8 Correct 7 ms 35720 KB Output is correct
9 Correct 8 ms 35676 KB Output is correct
10 Correct 7 ms 35672 KB Output is correct
11 Correct 7 ms 35672 KB Output is correct
12 Correct 6 ms 35824 KB Output is correct
13 Correct 7 ms 35676 KB Output is correct
14 Correct 7 ms 35832 KB Output is correct
15 Correct 7 ms 35672 KB Output is correct
16 Correct 7 ms 35676 KB Output is correct
17 Correct 6 ms 35676 KB Output is correct
18 Correct 7 ms 35676 KB Output is correct
19 Correct 7 ms 35876 KB Output is correct
20 Correct 7 ms 35672 KB Output is correct
21 Correct 7 ms 35672 KB Output is correct
22 Correct 8 ms 35676 KB Output is correct
23 Correct 7 ms 35848 KB Output is correct
24 Correct 7 ms 35672 KB Output is correct
25 Correct 6 ms 35676 KB Output is correct
26 Correct 6 ms 35676 KB Output is correct
27 Correct 7 ms 35676 KB Output is correct
28 Correct 7 ms 35676 KB Output is correct
29 Correct 7 ms 35776 KB Output is correct
30 Correct 7 ms 35676 KB Output is correct
31 Correct 7 ms 35724 KB Output is correct
32 Correct 7 ms 35676 KB Output is correct
33 Correct 7 ms 35832 KB Output is correct
34 Correct 8 ms 35676 KB Output is correct
35 Correct 8 ms 35852 KB Output is correct
36 Correct 8 ms 35836 KB Output is correct
37 Correct 7 ms 35688 KB Output is correct
38 Correct 7 ms 35676 KB Output is correct
39 Correct 48 ms 41300 KB Output is correct
40 Correct 46 ms 41612 KB Output is correct
41 Correct 46 ms 41128 KB Output is correct
42 Correct 51 ms 41296 KB Output is correct
43 Correct 44 ms 41620 KB Output is correct
44 Correct 49 ms 41564 KB Output is correct
45 Correct 25 ms 39808 KB Output is correct
46 Correct 27 ms 40052 KB Output is correct
47 Correct 45 ms 41560 KB Output is correct
48 Correct 46 ms 41564 KB Output is correct
49 Correct 47 ms 41628 KB Output is correct
50 Correct 47 ms 41564 KB Output is correct
51 Correct 38 ms 40536 KB Output is correct
52 Correct 45 ms 41272 KB Output is correct
53 Correct 47 ms 41812 KB Output is correct
54 Correct 46 ms 41944 KB Output is correct
55 Correct 205 ms 56912 KB Output is correct
56 Correct 180 ms 52596 KB Output is correct
57 Runtime error 65 ms 87660 KB Execution killed with signal 11
58 Halted 0 ms 0 KB -