Submission #566562

# Submission time Handle Problem Language Result Execution time Memory
566562 2022-05-22T12:11:29 Z joshjms Food Court (JOI21_foodcourt) C++14
14 / 100
1000 ms 22820 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define debug(x) cout << #x << " => " << x << "\n";

const long long mod = 1e9 + 7;

int n, m, q;

struct Query {
    int t;
    int l, r, k, c, a, b;
} query[250005];

int itr;
pair <int,int> idx[250005];

vector <pair<int,int>> idxs[250005];
pair <int,int> a[250005];
int iitr;

int ans[250005];

struct SegTree {
    int tree[1000005], lazy[1000005];

    void push(int idx, int l, int r) {
        if(lazy[idx] != 0) {
            tree[idx] += lazy[idx];
            if(l != r) {
                int mid = (l + r) / 2;
                push(idx * 2, l, mid);
                lazy[idx * 2] += lazy[idx];
                lazy[idx * 2] = max(lazy[idx * 2], -tree[idx * 2]);
                push(idx * 2 + 1, mid + 1, r);
                lazy[idx * 2 + 1] += lazy[idx];
                lazy[idx * 2 + 1] = max(lazy[idx * 2 + 1], -tree[idx * 2 + 1]);
            }
            lazy[idx] = 0;
        }
    }

    void add(int idx, int l, int r, int x, int y, int v) {
        push(idx, l, r);
        if(l > r || l > y || r < x) return;
        if(l >= x && r <= y) {
            lazy[idx] += v;
            lazy[idx] = max(lazy[idx], -tree[idx]);
            push(idx, l, r);
            return;
        }
        int mid = (l + r) / 2;
        add(idx * 2, l, mid, x, y, v);
        add(idx * 2 + 1, mid + 1, r, x, y, v);
        tree[idx] = max(tree[idx * 2], tree[idx * 2 + 1]);
    }

    int query(int idx, int l, int r, int x) {
        push(idx, l, r);
        if(l == r) return tree[idx];
        int mid = (l + r) / 2;
        if(x <= mid) return query(idx * 2, l, mid, x);
        else return query(idx * 2 + 1, mid + 1, r, x);
    }

} cur, tot;

struct SegTree2 {
    int tree[1000005], lazy[1000005];

    void push(int idx, int l, int r) {
        if(lazy[idx] != 0) {
            tree[idx] += lazy[idx];
            if(l != r) {
                lazy[idx * 2] += lazy[idx];
                lazy[idx * 2 + 1] += lazy[idx];
            }
            lazy[idx] = 0;
        }
    }

    void add(int idx, int l, int r, int x, int y, int v) {
        push(idx, l, r);
        if(l > r || l > y || r < x) return;
        if(l >= x && r <= y) {
            lazy[idx] += v;
            push(idx, l, r);
            return;
        }
        int mid = (l + r) / 2;
        add(idx * 2, l, mid, x, y, v);
        add(idx * 2 + 1, mid + 1, r, x, y, v);
        tree[idx] = min(tree[idx * 2], tree[idx * 2 + 1]);
    }

    int query(int idx, int l, int r) {
        push(idx, l, r);
        if(tree[idx] > 0) return -1;
        if(l == r) {tree[idx] = 1e18; return l;}
        int mid = (l + r) / 2;
        push(idx * 2, l, mid);
        push(idx * 2 + 1, mid + 1, r);
        int res = -1;
        if(tree[idx * 2] <= 0) res = query(idx * 2, l, mid);
        else res = query(idx * 2 + 1, mid + 1, r);
        tree[idx] = min(tree[idx * 2], tree[idx * 2 + 1]);
        push(idx, l, r);
        return res;
    }

    int val(int idx, int l, int r, int x) {
        push(idx, l, r);
        if(l == r) return tree[idx];
        int mid = (l + r) / 2;
        if(x <= mid) return val(idx * 2, l, mid, x);
        else return val(idx * 2 + 1, mid + 1, r, x);
    }

} group;

void solve () {
    cin >> n >> m >> q;
    for(int i = 1; i <= q; i++) {
        cin >> query[i].t;
        if(query[i].t == 1) {
            cin >> query[i].l >> query[i].r >> query[i].c >> query[i].k;
            cur.add(1, 1, n, query[i].l, query[i].r, query[i].k);
            tot.add(1, 1, n, query[i].l, query[i].r, query[i].k);
        }
        else if(query[i].t == 2) {
            cin >> query[i].l >> query[i].r >> query[i].k;
            cur.add(1, 1, n, query[i].l, query[i].r, -query[i].k);
        }
        else {
            cin >> query[i].a >> query[i].b;
            int Total = tot.query(1, 1, n, query[i].a);
            int Cur = cur.query(1, 1, n, query[i].a);
            if(query[i].b <= Cur) idx[++itr] = {Total - Cur + query[i].b, query[i].a};
            else idx[++itr] = {-1, query[i].a};
        }
    }
    // for(int i = 1; i <= itr; i++)
    //     cout << idx[i].fi << "\n";
    for(int i = 1; i <= itr; i++) 
        idxs[idx[i].se].pb({idx[i].fi, i});
    for(int i = 1; i <= n; i++) {
        sort(idxs[i].begin(), idxs[i].end());
        for(auto j : idxs[i]) a[++iitr] = j;
    }
    assert(itr == iitr);
    for(int i = 1; i <= itr; i++) {
        group.add(1, 1, itr, i, i, a[i].fi);
    }
    for(int i = 1; i <= q; i++) {
        if(query[i].t == 1) {
            int nl, nr, le = n + 1, ri = 0;
            nl = 1, nr = itr;
            while(nl <= nr) {
                int mid = (nl + nr) / 2;
                if(idx[a[mid].se].se >= query[i].l) nr = mid - 1, le = mid;
                else nl = mid + 1; 
            }
            nl = 1, nr = itr;
            while(nl <= nr) {
                int mid = (nl + nr) / 2;
                if(idx[a[mid].se].se <= query[i].r) nl = mid + 1, ri = mid;
                else nr = mid - 1;
            }
            if(le <= ri) group.add(1, 1, itr, le, ri, -query[i].k);
            while (true) {
                int aqua = group.query(1, 1, itr);
                if(aqua == -1) break;
                ans[a[aqua].se] = query[i].c;
            }
        }
    }
    for(int i = 1; i <= itr; i++)
        if(idx[i].fi == -1) ans[i] = 0;

    for(int i = 1; i <= itr; i++)
        cout << ans[i] << "\n";
}

signed main () {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve ();
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 6484 KB Output is correct
2 Correct 20 ms 6616 KB Output is correct
3 Correct 15 ms 6484 KB Output is correct
4 Correct 23 ms 6500 KB Output is correct
5 Correct 5 ms 6348 KB Output is correct
6 Correct 4 ms 6348 KB Output is correct
7 Correct 21 ms 6476 KB Output is correct
8 Correct 22 ms 6572 KB Output is correct
9 Correct 22 ms 6484 KB Output is correct
10 Correct 22 ms 6488 KB Output is correct
11 Correct 22 ms 6484 KB Output is correct
12 Correct 23 ms 6556 KB Output is correct
13 Correct 26 ms 6472 KB Output is correct
14 Correct 33 ms 6596 KB Output is correct
15 Correct 24 ms 6476 KB Output is correct
16 Correct 34 ms 6484 KB Output is correct
17 Correct 14 ms 6476 KB Output is correct
18 Correct 20 ms 6484 KB Output is correct
19 Correct 6 ms 6484 KB Output is correct
20 Correct 6 ms 6484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 6484 KB Output is correct
2 Correct 20 ms 6616 KB Output is correct
3 Correct 15 ms 6484 KB Output is correct
4 Correct 23 ms 6500 KB Output is correct
5 Correct 5 ms 6348 KB Output is correct
6 Correct 4 ms 6348 KB Output is correct
7 Correct 21 ms 6476 KB Output is correct
8 Correct 22 ms 6572 KB Output is correct
9 Correct 22 ms 6484 KB Output is correct
10 Correct 22 ms 6488 KB Output is correct
11 Correct 22 ms 6484 KB Output is correct
12 Correct 23 ms 6556 KB Output is correct
13 Correct 26 ms 6472 KB Output is correct
14 Correct 33 ms 6596 KB Output is correct
15 Correct 24 ms 6476 KB Output is correct
16 Correct 34 ms 6484 KB Output is correct
17 Correct 14 ms 6476 KB Output is correct
18 Correct 20 ms 6484 KB Output is correct
19 Correct 6 ms 6484 KB Output is correct
20 Correct 6 ms 6484 KB Output is correct
21 Correct 13 ms 6604 KB Output is correct
22 Correct 15 ms 6612 KB Output is correct
23 Correct 16 ms 6592 KB Output is correct
24 Correct 23 ms 6596 KB Output is correct
25 Correct 5 ms 6432 KB Output is correct
26 Correct 6 ms 6356 KB Output is correct
27 Correct 20 ms 6612 KB Output is correct
28 Correct 23 ms 6608 KB Output is correct
29 Correct 23 ms 6484 KB Output is correct
30 Correct 21 ms 6612 KB Output is correct
31 Correct 20 ms 6492 KB Output is correct
32 Correct 21 ms 6496 KB Output is correct
33 Correct 25 ms 6584 KB Output is correct
34 Correct 43 ms 6604 KB Output is correct
35 Correct 25 ms 6484 KB Output is correct
36 Correct 34 ms 6608 KB Output is correct
37 Correct 6 ms 6400 KB Output is correct
38 Correct 5 ms 6484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 84 ms 16380 KB Output is correct
2 Correct 91 ms 16700 KB Output is correct
3 Correct 109 ms 17488 KB Output is correct
4 Correct 102 ms 17488 KB Output is correct
5 Correct 106 ms 16836 KB Output is correct
6 Correct 109 ms 16700 KB Output is correct
7 Correct 30 ms 12572 KB Output is correct
8 Correct 37 ms 12676 KB Output is correct
9 Correct 89 ms 17204 KB Output is correct
10 Correct 87 ms 16676 KB Output is correct
11 Correct 90 ms 16740 KB Output is correct
12 Correct 92 ms 16712 KB Output is correct
13 Correct 90 ms 16788 KB Output is correct
14 Correct 101 ms 17348 KB Output is correct
15 Correct 106 ms 16200 KB Output is correct
16 Correct 115 ms 16460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1075 ms 22820 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 6484 KB Output is correct
2 Correct 20 ms 6616 KB Output is correct
3 Correct 15 ms 6484 KB Output is correct
4 Correct 23 ms 6500 KB Output is correct
5 Correct 5 ms 6348 KB Output is correct
6 Correct 4 ms 6348 KB Output is correct
7 Correct 21 ms 6476 KB Output is correct
8 Correct 22 ms 6572 KB Output is correct
9 Correct 22 ms 6484 KB Output is correct
10 Correct 22 ms 6488 KB Output is correct
11 Correct 22 ms 6484 KB Output is correct
12 Correct 23 ms 6556 KB Output is correct
13 Correct 26 ms 6472 KB Output is correct
14 Correct 33 ms 6596 KB Output is correct
15 Correct 24 ms 6476 KB Output is correct
16 Correct 34 ms 6484 KB Output is correct
17 Correct 14 ms 6476 KB Output is correct
18 Correct 20 ms 6484 KB Output is correct
19 Correct 6 ms 6484 KB Output is correct
20 Correct 6 ms 6484 KB Output is correct
21 Correct 84 ms 16380 KB Output is correct
22 Correct 91 ms 16700 KB Output is correct
23 Correct 109 ms 17488 KB Output is correct
24 Correct 102 ms 17488 KB Output is correct
25 Correct 106 ms 16836 KB Output is correct
26 Correct 109 ms 16700 KB Output is correct
27 Correct 30 ms 12572 KB Output is correct
28 Correct 37 ms 12676 KB Output is correct
29 Correct 89 ms 17204 KB Output is correct
30 Correct 87 ms 16676 KB Output is correct
31 Correct 90 ms 16740 KB Output is correct
32 Correct 92 ms 16712 KB Output is correct
33 Correct 90 ms 16788 KB Output is correct
34 Correct 101 ms 17348 KB Output is correct
35 Correct 106 ms 16200 KB Output is correct
36 Correct 115 ms 16460 KB Output is correct
37 Execution timed out 1096 ms 11208 KB Time limit exceeded
38 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1087 ms 10804 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 6484 KB Output is correct
2 Correct 20 ms 6616 KB Output is correct
3 Correct 15 ms 6484 KB Output is correct
4 Correct 23 ms 6500 KB Output is correct
5 Correct 5 ms 6348 KB Output is correct
6 Correct 4 ms 6348 KB Output is correct
7 Correct 21 ms 6476 KB Output is correct
8 Correct 22 ms 6572 KB Output is correct
9 Correct 22 ms 6484 KB Output is correct
10 Correct 22 ms 6488 KB Output is correct
11 Correct 22 ms 6484 KB Output is correct
12 Correct 23 ms 6556 KB Output is correct
13 Correct 26 ms 6472 KB Output is correct
14 Correct 33 ms 6596 KB Output is correct
15 Correct 24 ms 6476 KB Output is correct
16 Correct 34 ms 6484 KB Output is correct
17 Correct 14 ms 6476 KB Output is correct
18 Correct 20 ms 6484 KB Output is correct
19 Correct 6 ms 6484 KB Output is correct
20 Correct 6 ms 6484 KB Output is correct
21 Correct 13 ms 6604 KB Output is correct
22 Correct 15 ms 6612 KB Output is correct
23 Correct 16 ms 6592 KB Output is correct
24 Correct 23 ms 6596 KB Output is correct
25 Correct 5 ms 6432 KB Output is correct
26 Correct 6 ms 6356 KB Output is correct
27 Correct 20 ms 6612 KB Output is correct
28 Correct 23 ms 6608 KB Output is correct
29 Correct 23 ms 6484 KB Output is correct
30 Correct 21 ms 6612 KB Output is correct
31 Correct 20 ms 6492 KB Output is correct
32 Correct 21 ms 6496 KB Output is correct
33 Correct 25 ms 6584 KB Output is correct
34 Correct 43 ms 6604 KB Output is correct
35 Correct 25 ms 6484 KB Output is correct
36 Correct 34 ms 6608 KB Output is correct
37 Correct 6 ms 6400 KB Output is correct
38 Correct 5 ms 6484 KB Output is correct
39 Correct 84 ms 16380 KB Output is correct
40 Correct 91 ms 16700 KB Output is correct
41 Correct 109 ms 17488 KB Output is correct
42 Correct 102 ms 17488 KB Output is correct
43 Correct 106 ms 16836 KB Output is correct
44 Correct 109 ms 16700 KB Output is correct
45 Correct 30 ms 12572 KB Output is correct
46 Correct 37 ms 12676 KB Output is correct
47 Correct 89 ms 17204 KB Output is correct
48 Correct 87 ms 16676 KB Output is correct
49 Correct 90 ms 16740 KB Output is correct
50 Correct 92 ms 16712 KB Output is correct
51 Correct 90 ms 16788 KB Output is correct
52 Correct 101 ms 17348 KB Output is correct
53 Correct 106 ms 16200 KB Output is correct
54 Correct 115 ms 16460 KB Output is correct
55 Execution timed out 1096 ms 11208 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 6484 KB Output is correct
2 Correct 20 ms 6616 KB Output is correct
3 Correct 15 ms 6484 KB Output is correct
4 Correct 23 ms 6500 KB Output is correct
5 Correct 5 ms 6348 KB Output is correct
6 Correct 4 ms 6348 KB Output is correct
7 Correct 21 ms 6476 KB Output is correct
8 Correct 22 ms 6572 KB Output is correct
9 Correct 22 ms 6484 KB Output is correct
10 Correct 22 ms 6488 KB Output is correct
11 Correct 22 ms 6484 KB Output is correct
12 Correct 23 ms 6556 KB Output is correct
13 Correct 26 ms 6472 KB Output is correct
14 Correct 33 ms 6596 KB Output is correct
15 Correct 24 ms 6476 KB Output is correct
16 Correct 34 ms 6484 KB Output is correct
17 Correct 14 ms 6476 KB Output is correct
18 Correct 20 ms 6484 KB Output is correct
19 Correct 6 ms 6484 KB Output is correct
20 Correct 6 ms 6484 KB Output is correct
21 Correct 13 ms 6604 KB Output is correct
22 Correct 15 ms 6612 KB Output is correct
23 Correct 16 ms 6592 KB Output is correct
24 Correct 23 ms 6596 KB Output is correct
25 Correct 5 ms 6432 KB Output is correct
26 Correct 6 ms 6356 KB Output is correct
27 Correct 20 ms 6612 KB Output is correct
28 Correct 23 ms 6608 KB Output is correct
29 Correct 23 ms 6484 KB Output is correct
30 Correct 21 ms 6612 KB Output is correct
31 Correct 20 ms 6492 KB Output is correct
32 Correct 21 ms 6496 KB Output is correct
33 Correct 25 ms 6584 KB Output is correct
34 Correct 43 ms 6604 KB Output is correct
35 Correct 25 ms 6484 KB Output is correct
36 Correct 34 ms 6608 KB Output is correct
37 Correct 6 ms 6400 KB Output is correct
38 Correct 5 ms 6484 KB Output is correct
39 Correct 84 ms 16380 KB Output is correct
40 Correct 91 ms 16700 KB Output is correct
41 Correct 109 ms 17488 KB Output is correct
42 Correct 102 ms 17488 KB Output is correct
43 Correct 106 ms 16836 KB Output is correct
44 Correct 109 ms 16700 KB Output is correct
45 Correct 30 ms 12572 KB Output is correct
46 Correct 37 ms 12676 KB Output is correct
47 Correct 89 ms 17204 KB Output is correct
48 Correct 87 ms 16676 KB Output is correct
49 Correct 90 ms 16740 KB Output is correct
50 Correct 92 ms 16712 KB Output is correct
51 Correct 90 ms 16788 KB Output is correct
52 Correct 101 ms 17348 KB Output is correct
53 Correct 106 ms 16200 KB Output is correct
54 Correct 115 ms 16460 KB Output is correct
55 Execution timed out 1075 ms 22820 KB Time limit exceeded
56 Halted 0 ms 0 KB -