Submission #998375

# Submission time Handle Problem Language Result Execution time Memory
998375 2024-06-13T18:13:03 Z vladilius Food Court (JOI21_foodcourt) C++17
14 / 100
1000 ms 260768 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
#define ins insert
const ll inf = numeric_limits<ll> :: max();
 
struct STB{
    vector<ll> a;
    // a[i] += x (l <= i <= r)
    // a[i] = max(a[i], x) (l <= i <= r)
    // ? a[i]
    int n;
    STB(int ns){
        n = ns;
        a.resize(n + 1);
    }
    void add(int l, int r, ll x){
        for (int i = l; i <= r; i++){
            a[i] += x;
        }
    }
    void chmax(int l, int r, ll x){
        for (int i = l; i <= r; i++){
            a[i] = max(a[i], x);
        }
    }
    ll get(int p){
        return a[p];
    }
};
 
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
    int n, m, q; cin>>n>>m>>q;
    STB C(n);
    const int S = sqrt(n);
    const int sz = (int) ceil(1.0 * n / S) - 1;
    vector<int> st[n + 1], st1[sz + 5];
    vector<ll> pr[n + 1], pr1[sz + 5];
    
    vector<int> bc(n + 1);
    int i = 1, j = S, k = 0;
    while (i <= n){
        while (i <= j) bc[i++] = k;
        j = min(n, j + S);
        k++;
    }
 
    vector<int> col(q + 1);
    map<int, bool> mp;
    for (int tt = 1; tt <= q; tt++){
        int type; cin>>type;
        if (type == 1){
            int l, r, c, k; cin>>l>>r>>c>>k;
            col[tt] = c;
            mp[tt] = 1;
            C.add(l, r, k);
            int bl = bc[l] + 1, br = bc[r] - 1;
            if (bl > br){
                for (int i = l; i <= r; i++){
                    st[i].pb(tt);
                    if (pr[i].empty()) pr[i].pb(k);
                    else pr[i].pb(pr[i].back() + k);
                }
                continue;
            }
            for (int i = bl; i <= br; i++){
                st1[i].pb(tt);
                if (pr1[i].empty()) pr1[i].pb(k);
                else pr1[i].pb(pr1[i].back() + k);
            }
            for (int i = l; i <= S * bl; i++){
                st[i].pb(tt);
                if (pr[i].empty()) pr[i].pb(k);
                else pr[i].pb(pr[i].back() + k);
            }
            for (int i = S * (br + 1) + 1; i <= r; i++){
                st[i].pb(tt);
                if (pr[i].empty()) pr[i].pb(k);
                else pr[i].pb(pr[i].back() + k);
            }
        }
        else if (type == 2){
            int l, r, k; cin>>l>>r>>k;
            C.add(l, r, -k);
            C.chmax(1, n, 0);
        }
        else {
            int a; ll b; cin>>a>>b;
            ll v = C.get(a);
            if (b > v){
                cout<<0<<"\n";
                continue;
            }
            b -= v;
            if (!pr1[bc[a]].empty()) b += pr1[bc[a]].back();
            if (!pr[a].empty()) b += pr[a].back();
            
            auto low = [&](vector<int>& x, int t){
                if (x.empty() || x[0] > t) return -1;
                int l = 0, r = (int) x.size() - 1;
                while (l + 1 < r){
                    int m = (l + r) / 2;
                    if (x[m] <= t){
                        l = m;
                    }
                    else {
                        r = m - 1;
                    }
                }
                if (x[r] <= t) l = r;
                return l;
            };
            
            auto check = [&](int m){
                int j1 = low(st1[bc[a]], m);
                int j2 = low(st[a], m);
                ll val = 0;
                if (j1 >= 0) val += pr1[bc[a]][j1];
                if (j2 >= 0) val += pr[a][j2];
                return (val >= b);
            };
            
            int l = 1, r = tt;
            while (l + 1 < r){
                int m = (l + r) / 2;
                if (check(m)){
                    r = m;
                }
                else {
                    l = m + 1;
                }
            }
            if (check(l)) r = l;
            if (mp.find(r) == mp.end()){
                while (true){
                    l++;
                }
            }
            cout<<col[r]<<"\n";
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 860 KB Output is correct
2 Correct 4 ms 1372 KB Output is correct
3 Correct 2 ms 1372 KB Output is correct
4 Correct 3 ms 1628 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 3 ms 1380 KB Output is correct
8 Correct 4 ms 1372 KB Output is correct
9 Correct 3 ms 1540 KB Output is correct
10 Correct 3 ms 1372 KB Output is correct
11 Correct 3 ms 1352 KB Output is correct
12 Correct 6 ms 1368 KB Output is correct
13 Correct 3 ms 1628 KB Output is correct
14 Correct 3 ms 1884 KB Output is correct
15 Correct 3 ms 1112 KB Output is correct
16 Correct 3 ms 1628 KB Output is correct
17 Correct 2 ms 1116 KB Output is correct
18 Correct 3 ms 1372 KB Output is correct
19 Correct 2 ms 856 KB Output is correct
20 Correct 2 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 860 KB Output is correct
2 Correct 4 ms 1372 KB Output is correct
3 Correct 2 ms 1372 KB Output is correct
4 Correct 3 ms 1628 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 3 ms 1380 KB Output is correct
8 Correct 4 ms 1372 KB Output is correct
9 Correct 3 ms 1540 KB Output is correct
10 Correct 3 ms 1372 KB Output is correct
11 Correct 3 ms 1352 KB Output is correct
12 Correct 6 ms 1368 KB Output is correct
13 Correct 3 ms 1628 KB Output is correct
14 Correct 3 ms 1884 KB Output is correct
15 Correct 3 ms 1112 KB Output is correct
16 Correct 3 ms 1628 KB Output is correct
17 Correct 2 ms 1116 KB Output is correct
18 Correct 3 ms 1372 KB Output is correct
19 Correct 2 ms 856 KB Output is correct
20 Correct 2 ms 856 KB Output is correct
21 Correct 3 ms 1116 KB Output is correct
22 Correct 3 ms 1372 KB Output is correct
23 Correct 3 ms 1372 KB Output is correct
24 Correct 4 ms 1728 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 3 ms 1372 KB Output is correct
28 Correct 4 ms 1372 KB Output is correct
29 Correct 4 ms 1372 KB Output is correct
30 Correct 4 ms 1368 KB Output is correct
31 Correct 3 ms 1372 KB Output is correct
32 Correct 4 ms 1372 KB Output is correct
33 Correct 3 ms 1680 KB Output is correct
34 Correct 3 ms 1880 KB Output is correct
35 Correct 3 ms 1348 KB Output is correct
36 Correct 3 ms 1692 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 1 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 824 ms 9552 KB Output is correct
2 Correct 577 ms 11344 KB Output is correct
3 Correct 761 ms 11892 KB Output is correct
4 Correct 787 ms 11600 KB Output is correct
5 Correct 609 ms 14416 KB Output is correct
6 Correct 583 ms 14420 KB Output is correct
7 Correct 16 ms 1880 KB Output is correct
8 Correct 17 ms 2264 KB Output is correct
9 Correct 920 ms 10036 KB Output is correct
10 Correct 896 ms 10064 KB Output is correct
11 Correct 879 ms 10000 KB Output is correct
12 Correct 960 ms 10068 KB Output is correct
13 Correct 226 ms 9876 KB Output is correct
14 Correct 314 ms 12368 KB Output is correct
15 Correct 65 ms 13140 KB Output is correct
16 Correct 89 ms 15180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1081 ms 86612 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 860 KB Output is correct
2 Correct 4 ms 1372 KB Output is correct
3 Correct 2 ms 1372 KB Output is correct
4 Correct 3 ms 1628 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 3 ms 1380 KB Output is correct
8 Correct 4 ms 1372 KB Output is correct
9 Correct 3 ms 1540 KB Output is correct
10 Correct 3 ms 1372 KB Output is correct
11 Correct 3 ms 1352 KB Output is correct
12 Correct 6 ms 1368 KB Output is correct
13 Correct 3 ms 1628 KB Output is correct
14 Correct 3 ms 1884 KB Output is correct
15 Correct 3 ms 1112 KB Output is correct
16 Correct 3 ms 1628 KB Output is correct
17 Correct 2 ms 1116 KB Output is correct
18 Correct 3 ms 1372 KB Output is correct
19 Correct 2 ms 856 KB Output is correct
20 Correct 2 ms 856 KB Output is correct
21 Correct 824 ms 9552 KB Output is correct
22 Correct 577 ms 11344 KB Output is correct
23 Correct 761 ms 11892 KB Output is correct
24 Correct 787 ms 11600 KB Output is correct
25 Correct 609 ms 14416 KB Output is correct
26 Correct 583 ms 14420 KB Output is correct
27 Correct 16 ms 1880 KB Output is correct
28 Correct 17 ms 2264 KB Output is correct
29 Correct 920 ms 10036 KB Output is correct
30 Correct 896 ms 10064 KB Output is correct
31 Correct 879 ms 10000 KB Output is correct
32 Correct 960 ms 10068 KB Output is correct
33 Correct 226 ms 9876 KB Output is correct
34 Correct 314 ms 12368 KB Output is correct
35 Correct 65 ms 13140 KB Output is correct
36 Correct 89 ms 15180 KB Output is correct
37 Correct 928 ms 112908 KB Output is correct
38 Correct 986 ms 161508 KB Output is correct
39 Correct 17 ms 2396 KB Output is correct
40 Correct 21 ms 2904 KB Output is correct
41 Execution timed out 1010 ms 157912 KB Time limit exceeded
42 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 553 ms 167764 KB Output is correct
2 Correct 570 ms 176812 KB Output is correct
3 Correct 623 ms 192084 KB Output is correct
4 Correct 615 ms 143692 KB Output is correct
5 Correct 734 ms 178336 KB Output is correct
6 Correct 848 ms 207396 KB Output is correct
7 Correct 39 ms 2384 KB Output is correct
8 Correct 46 ms 2564 KB Output is correct
9 Execution timed out 1106 ms 260768 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 860 KB Output is correct
2 Correct 4 ms 1372 KB Output is correct
3 Correct 2 ms 1372 KB Output is correct
4 Correct 3 ms 1628 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 3 ms 1380 KB Output is correct
8 Correct 4 ms 1372 KB Output is correct
9 Correct 3 ms 1540 KB Output is correct
10 Correct 3 ms 1372 KB Output is correct
11 Correct 3 ms 1352 KB Output is correct
12 Correct 6 ms 1368 KB Output is correct
13 Correct 3 ms 1628 KB Output is correct
14 Correct 3 ms 1884 KB Output is correct
15 Correct 3 ms 1112 KB Output is correct
16 Correct 3 ms 1628 KB Output is correct
17 Correct 2 ms 1116 KB Output is correct
18 Correct 3 ms 1372 KB Output is correct
19 Correct 2 ms 856 KB Output is correct
20 Correct 2 ms 856 KB Output is correct
21 Correct 3 ms 1116 KB Output is correct
22 Correct 3 ms 1372 KB Output is correct
23 Correct 3 ms 1372 KB Output is correct
24 Correct 4 ms 1728 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 3 ms 1372 KB Output is correct
28 Correct 4 ms 1372 KB Output is correct
29 Correct 4 ms 1372 KB Output is correct
30 Correct 4 ms 1368 KB Output is correct
31 Correct 3 ms 1372 KB Output is correct
32 Correct 4 ms 1372 KB Output is correct
33 Correct 3 ms 1680 KB Output is correct
34 Correct 3 ms 1880 KB Output is correct
35 Correct 3 ms 1348 KB Output is correct
36 Correct 3 ms 1692 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 1 ms 860 KB Output is correct
39 Correct 824 ms 9552 KB Output is correct
40 Correct 577 ms 11344 KB Output is correct
41 Correct 761 ms 11892 KB Output is correct
42 Correct 787 ms 11600 KB Output is correct
43 Correct 609 ms 14416 KB Output is correct
44 Correct 583 ms 14420 KB Output is correct
45 Correct 16 ms 1880 KB Output is correct
46 Correct 17 ms 2264 KB Output is correct
47 Correct 920 ms 10036 KB Output is correct
48 Correct 896 ms 10064 KB Output is correct
49 Correct 879 ms 10000 KB Output is correct
50 Correct 960 ms 10068 KB Output is correct
51 Correct 226 ms 9876 KB Output is correct
52 Correct 314 ms 12368 KB Output is correct
53 Correct 65 ms 13140 KB Output is correct
54 Correct 89 ms 15180 KB Output is correct
55 Correct 928 ms 112908 KB Output is correct
56 Correct 986 ms 161508 KB Output is correct
57 Correct 17 ms 2396 KB Output is correct
58 Correct 21 ms 2904 KB Output is correct
59 Execution timed out 1010 ms 157912 KB Time limit exceeded
60 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 860 KB Output is correct
2 Correct 4 ms 1372 KB Output is correct
3 Correct 2 ms 1372 KB Output is correct
4 Correct 3 ms 1628 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 3 ms 1380 KB Output is correct
8 Correct 4 ms 1372 KB Output is correct
9 Correct 3 ms 1540 KB Output is correct
10 Correct 3 ms 1372 KB Output is correct
11 Correct 3 ms 1352 KB Output is correct
12 Correct 6 ms 1368 KB Output is correct
13 Correct 3 ms 1628 KB Output is correct
14 Correct 3 ms 1884 KB Output is correct
15 Correct 3 ms 1112 KB Output is correct
16 Correct 3 ms 1628 KB Output is correct
17 Correct 2 ms 1116 KB Output is correct
18 Correct 3 ms 1372 KB Output is correct
19 Correct 2 ms 856 KB Output is correct
20 Correct 2 ms 856 KB Output is correct
21 Correct 3 ms 1116 KB Output is correct
22 Correct 3 ms 1372 KB Output is correct
23 Correct 3 ms 1372 KB Output is correct
24 Correct 4 ms 1728 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 3 ms 1372 KB Output is correct
28 Correct 4 ms 1372 KB Output is correct
29 Correct 4 ms 1372 KB Output is correct
30 Correct 4 ms 1368 KB Output is correct
31 Correct 3 ms 1372 KB Output is correct
32 Correct 4 ms 1372 KB Output is correct
33 Correct 3 ms 1680 KB Output is correct
34 Correct 3 ms 1880 KB Output is correct
35 Correct 3 ms 1348 KB Output is correct
36 Correct 3 ms 1692 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 1 ms 860 KB Output is correct
39 Correct 824 ms 9552 KB Output is correct
40 Correct 577 ms 11344 KB Output is correct
41 Correct 761 ms 11892 KB Output is correct
42 Correct 787 ms 11600 KB Output is correct
43 Correct 609 ms 14416 KB Output is correct
44 Correct 583 ms 14420 KB Output is correct
45 Correct 16 ms 1880 KB Output is correct
46 Correct 17 ms 2264 KB Output is correct
47 Correct 920 ms 10036 KB Output is correct
48 Correct 896 ms 10064 KB Output is correct
49 Correct 879 ms 10000 KB Output is correct
50 Correct 960 ms 10068 KB Output is correct
51 Correct 226 ms 9876 KB Output is correct
52 Correct 314 ms 12368 KB Output is correct
53 Correct 65 ms 13140 KB Output is correct
54 Correct 89 ms 15180 KB Output is correct
55 Execution timed out 1081 ms 86612 KB Time limit exceeded
56 Halted 0 ms 0 KB -