Submission #909868

# Submission time Handle Problem Language Result Execution time Memory
909868 2024-01-17T14:00:43 Z Trisanu_Das Food Court (JOI21_foodcourt) C++17
35 / 100
357 ms 230152 KB
#include <bits/stdc++.h>

using namespace std;

const int mod = 1e9 + 7;
const int INF = 1e9;
const int LOG = 18;

void add(int &a, int b) {
    a += b;
    if (a < 0) a += mod;
    if (a >= mod) a -= mod;
}

template <typename T>
void chkmin(T &a, T b) {
    if (a > b) a = b;
}

template <typename T>
void chkmax(T &a, T b) {
    if (a < b) a = b;
}

int _pow(int a, int n) {
    if (n == 0) return 1;
    int res = _pow(a, n / 2);
    if (n % 2) return (1ll * res * res % mod * a % mod);
    else return 1ll * res * res % mod;
}

int n, m, nq;

struct shape {
    int op, l, r, c, k;
    int pos;
    long long b;
} q[300009];

deque<pair<long long, long long>> deq[300009];

void sub1() {
    for (int run = 1; run <= nq; run++) {
        int op = q[run].op;
        if (op <= 2) {
            int l = q[run].l, r = q[run].r, c = q[run].c, k = q[run].k;
            if (op == 1) {
                for (int i = l; i <= r; i++) {
                    if (deq[i].empty() || deq[i].back().first != c) deq[i].push_back({c, k});
                    else deq[i].back().second += k;
                }
            } else {
                for (int i = l; i <= r; i++) {
                    int remain = k;
                    while (deq[i].size()) {
                        if (deq[i].front().second <= remain) remain -= deq[i].front().second, deq[i].pop_front();
                        else {
                            deq[i].front().second -= remain;
                            break;
                        }
                    }
                }
            }
        } else {
            int pos = q[run].pos;
            long long b = q[run].b;
            deque<pair<long long, long long>> New = deq[pos];
            long long sum = 0;
            int res = 0;
            while (!New.empty()) {
                if (sum + New.front().second >= b) {
                    res = New.front().first;
                    break;
                }
                sum += New.front().second;
                New.pop_front();
            }
            cout << res << "\n";
        }
    }
}

bool check_sub2() {
    if (max(n, nq) > 65000) return false;
    for (int i = 1; i <= nq; i++) {
        if (q[i].op == 1) {
            if (q[i].r - q[i].l > 10) return false;
            if (q[i].k != 1) return false;
        }
    }
    return true;
}

const int N = 2.5 * 1e5;
long long T[300009 * 4], lazy[300009 * 4];

void down_leave_sub2(int id) {
    long long &t = lazy[id];
    T[id * 2] += t, T[id * 2 + 1] += t;
    lazy[id * 2] += t, lazy[id * 2 + 1] += t;
    t = 0;
}

void update_leave_sub2(int id, int l, int r, int u, int v, int k) {
    if (l > v || r < u) return;
    if (u <= l && r <= v) {
        T[id] += k;
        lazy[id] += k;
        if (k == -1) T[id] = lazy[id] = 0;
        return;
    }
    int mid = (l + r) / 2;
    down_leave_sub2(id);
    update_leave_sub2(id * 2, l, mid, u, v, k);
    update_leave_sub2(id * 2 + 1, mid + 1, r, u, v, k);
}

long long get_leave_sub2(int id, int l, int r, int pos) {
    if (l > pos || r < pos) return 0;
    if (l == r) return T[id];
    down_leave_sub2(id);
    int mid = (l + r) / 2;
    return get_leave_sub2(id * 2, l, mid, pos) + get_leave_sub2(id * 2 + 1, mid + 1, r, pos);
}

void leave_sub2(int pos) {
    long long leave = get_leave_sub2(1, 1, N, pos);
    update_leave_sub2(1, 1, N, pos, pos, -1);
    while (deq[pos].size()) {
        if (deq[pos].front().second <= leave) leave -= deq[pos].front().second, deq[pos].pop_front();
        else {
            deq[pos].front().second -= leave;
            break;
        }
    }
}

void sub2() {
    for (int run = 1; run <= nq; run++) {
        if (q[run].op <= 2) {
            int l = q[run].l, r = q[run].r, c = q[run].c, k = q[run].k;
            if (q[run].op == 1) {
                for (int i = l; i <= r; i++) {
                    leave_sub2(i);
                    if (deq[i].empty() || deq[i].back().first != c) deq[i].push_back({c, k});
                    else deq[i].back().second += k;
                }
            } else {
                int l = q[run].l, r = q[run].r, k = q[run].k;
                update_leave_sub2(1, 1, N, l, r, k);
            }
        } else {
            int pos = q[run].pos;
            long long b = q[run].b;
            leave_sub2(pos);
            deque<pair<long long, long long>> New = deq[pos];
            long long sum = 0;
            int res = 0;
            while (!New.empty()) {
                if (sum + New.front().second >= b) {
                    res = New.front().first;
                    break;
                }
                sum += New.front().second;
                New.pop_front();
            }
            cout << res << "\n";
        }
    }
}

struct info {
    long long sum, minn;
    friend info operator+(info x, info y) {
        info res;
        res.minn = min(x.minn, x.sum + y.minn);
        res.sum = x.sum + y.sum;
        return res;
    }
} laz[300009 * 4];

void down_leave_sub3(int id) {
    laz[id * 2] = laz[id * 2] + laz[id];
    laz[id * 2 + 1] = laz[id * 2 + 1] + laz[id];
    laz[id] = {0, 0};
}

void update_leave_sub3(int id, int l, int r, int u, int v, int k) {
    if (l > v || r < u) return;
    if (u <= l && r <= v) {
        info dat = {k, min(k, 0)};
        laz[id] = laz[id] + dat;
        return;
    }
    int mid = (l + r) / 2;
    down_leave_sub3(id);
    update_leave_sub3(id * 2, l, mid, u, v, k);
    update_leave_sub3(id * 2 + 1, mid + 1, r, u, v, k);
    T[id] = min(T[id * 2], T[id * 2 + 1]);
}

long long get_leave_sub3(int id, int l, int r, int pos) {
    if (l > pos || r < pos) return 0;
    if (l == r) return laz[id].sum - laz[id].minn;
    int mid = (l + r) / 2;
    down_leave_sub3(id);
    return get_leave_sub3(id * 2, l, mid, pos) + get_leave_sub3(id * 2 + 1, mid + 1, r, pos);
}

void sub3() {
    for (int run = 1; run <= nq; run++) {
        int l = q[run].l, r = q[run].r, k = q[run].k;
        if (q[run].op == 1) update_leave_sub3(1, 1, N, l, r, k);
        else if (q[run].op == 2) update_leave_sub3(1, 1, N, l, r, -k);
        else {
            int pos = q[run].pos;
            long long b = q[run].b;
            if (get_leave_sub3(1, 1, N, pos) >= b) cout << 1 << "\n";
            else cout << 0 << "\n";
        }
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m >> nq;
    for (int i = 1; i <= nq; i++) {
        cin >> q[i].op;
        if (q[i].op == 1) cin >> q[i].l >> q[i].r >> q[i].c >> q[i].k;
        else if (q[i].op == 2) cin >> q[i].l >> q[i].r >> q[i].k;
        else cin >> q[i].pos >> q[i].b;
    }
    if (n <= 2e3 && nq <= 2e3) sub1();
    else if (check_sub2()) sub2();
    else if (m == 1) sub3();
}
# Verdict Execution time Memory Grader output
1 Correct 146 ms 204024 KB Output is correct
2 Correct 142 ms 204204 KB Output is correct
3 Correct 160 ms 210996 KB Output is correct
4 Correct 144 ms 214520 KB Output is correct
5 Correct 111 ms 203344 KB Output is correct
6 Correct 114 ms 203308 KB Output is correct
7 Correct 157 ms 216148 KB Output is correct
8 Correct 151 ms 211732 KB Output is correct
9 Correct 166 ms 204368 KB Output is correct
10 Correct 142 ms 211192 KB Output is correct
11 Correct 149 ms 208208 KB Output is correct
12 Correct 150 ms 204368 KB Output is correct
13 Correct 142 ms 204496 KB Output is correct
14 Correct 147 ms 205392 KB Output is correct
15 Correct 147 ms 206460 KB Output is correct
16 Correct 150 ms 205428 KB Output is correct
17 Correct 132 ms 203856 KB Output is correct
18 Correct 160 ms 204212 KB Output is correct
19 Correct 112 ms 203392 KB Output is correct
20 Correct 114 ms 203580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 146 ms 204024 KB Output is correct
2 Correct 142 ms 204204 KB Output is correct
3 Correct 160 ms 210996 KB Output is correct
4 Correct 144 ms 214520 KB Output is correct
5 Correct 111 ms 203344 KB Output is correct
6 Correct 114 ms 203308 KB Output is correct
7 Correct 157 ms 216148 KB Output is correct
8 Correct 151 ms 211732 KB Output is correct
9 Correct 166 ms 204368 KB Output is correct
10 Correct 142 ms 211192 KB Output is correct
11 Correct 149 ms 208208 KB Output is correct
12 Correct 150 ms 204368 KB Output is correct
13 Correct 142 ms 204496 KB Output is correct
14 Correct 147 ms 205392 KB Output is correct
15 Correct 147 ms 206460 KB Output is correct
16 Correct 150 ms 205428 KB Output is correct
17 Correct 132 ms 203856 KB Output is correct
18 Correct 160 ms 204212 KB Output is correct
19 Correct 112 ms 203392 KB Output is correct
20 Correct 114 ms 203580 KB Output is correct
21 Correct 140 ms 204116 KB Output is correct
22 Correct 139 ms 204624 KB Output is correct
23 Correct 138 ms 210776 KB Output is correct
24 Correct 156 ms 214460 KB Output is correct
25 Correct 113 ms 203408 KB Output is correct
26 Correct 114 ms 203436 KB Output is correct
27 Correct 147 ms 215508 KB Output is correct
28 Correct 144 ms 212484 KB Output is correct
29 Correct 175 ms 206416 KB Output is correct
30 Correct 148 ms 210772 KB Output is correct
31 Correct 145 ms 208208 KB Output is correct
32 Correct 145 ms 204208 KB Output is correct
33 Correct 144 ms 204368 KB Output is correct
34 Correct 171 ms 206504 KB Output is correct
35 Correct 149 ms 205140 KB Output is correct
36 Correct 153 ms 205648 KB Output is correct
37 Correct 117 ms 203332 KB Output is correct
38 Correct 113 ms 203580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 200 ms 213516 KB Output is correct
2 Correct 214 ms 213584 KB Output is correct
3 Correct 220 ms 213532 KB Output is correct
4 Correct 233 ms 213772 KB Output is correct
5 Correct 268 ms 213584 KB Output is correct
6 Correct 273 ms 213588 KB Output is correct
7 Correct 143 ms 212560 KB Output is correct
8 Correct 142 ms 212604 KB Output is correct
9 Correct 191 ms 213588 KB Output is correct
10 Correct 191 ms 213584 KB Output is correct
11 Correct 194 ms 213588 KB Output is correct
12 Correct 218 ms 213588 KB Output is correct
13 Correct 205 ms 213168 KB Output is correct
14 Correct 235 ms 213332 KB Output is correct
15 Correct 266 ms 213516 KB Output is correct
16 Correct 252 ms 213584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 284 ms 228672 KB Output is correct
2 Correct 240 ms 223568 KB Output is correct
3 Correct 288 ms 229360 KB Output is correct
4 Correct 265 ms 225560 KB Output is correct
5 Correct 245 ms 222032 KB Output is correct
6 Correct 323 ms 229728 KB Output is correct
7 Correct 210 ms 217956 KB Output is correct
8 Correct 204 ms 218112 KB Output is correct
9 Correct 279 ms 229648 KB Output is correct
10 Correct 290 ms 229576 KB Output is correct
11 Correct 311 ms 229500 KB Output is correct
12 Correct 330 ms 229764 KB Output is correct
13 Correct 318 ms 229364 KB Output is correct
14 Correct 304 ms 229472 KB Output is correct
15 Correct 307 ms 230152 KB Output is correct
16 Correct 316 ms 229384 KB Output is correct
17 Correct 303 ms 229692 KB Output is correct
18 Correct 311 ms 229404 KB Output is correct
19 Correct 299 ms 228176 KB Output is correct
20 Correct 297 ms 229528 KB Output is correct
21 Correct 310 ms 229616 KB Output is correct
22 Correct 309 ms 229476 KB Output is correct
23 Correct 330 ms 229408 KB Output is correct
24 Correct 357 ms 229456 KB Output is correct
25 Correct 280 ms 226132 KB Output is correct
26 Correct 312 ms 225936 KB Output is correct
27 Correct 276 ms 229232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 146 ms 204024 KB Output is correct
2 Correct 142 ms 204204 KB Output is correct
3 Correct 160 ms 210996 KB Output is correct
4 Correct 144 ms 214520 KB Output is correct
5 Correct 111 ms 203344 KB Output is correct
6 Correct 114 ms 203308 KB Output is correct
7 Correct 157 ms 216148 KB Output is correct
8 Correct 151 ms 211732 KB Output is correct
9 Correct 166 ms 204368 KB Output is correct
10 Correct 142 ms 211192 KB Output is correct
11 Correct 149 ms 208208 KB Output is correct
12 Correct 150 ms 204368 KB Output is correct
13 Correct 142 ms 204496 KB Output is correct
14 Correct 147 ms 205392 KB Output is correct
15 Correct 147 ms 206460 KB Output is correct
16 Correct 150 ms 205428 KB Output is correct
17 Correct 132 ms 203856 KB Output is correct
18 Correct 160 ms 204212 KB Output is correct
19 Correct 112 ms 203392 KB Output is correct
20 Correct 114 ms 203580 KB Output is correct
21 Correct 200 ms 213516 KB Output is correct
22 Correct 214 ms 213584 KB Output is correct
23 Correct 220 ms 213532 KB Output is correct
24 Correct 233 ms 213772 KB Output is correct
25 Correct 268 ms 213584 KB Output is correct
26 Correct 273 ms 213588 KB Output is correct
27 Correct 143 ms 212560 KB Output is correct
28 Correct 142 ms 212604 KB Output is correct
29 Correct 191 ms 213588 KB Output is correct
30 Correct 191 ms 213584 KB Output is correct
31 Correct 194 ms 213588 KB Output is correct
32 Correct 218 ms 213588 KB Output is correct
33 Correct 205 ms 213168 KB Output is correct
34 Correct 235 ms 213332 KB Output is correct
35 Correct 266 ms 213516 KB Output is correct
36 Correct 252 ms 213584 KB Output is correct
37 Incorrect 125 ms 206420 KB Output isn't correct
38 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 132 ms 207044 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 146 ms 204024 KB Output is correct
2 Correct 142 ms 204204 KB Output is correct
3 Correct 160 ms 210996 KB Output is correct
4 Correct 144 ms 214520 KB Output is correct
5 Correct 111 ms 203344 KB Output is correct
6 Correct 114 ms 203308 KB Output is correct
7 Correct 157 ms 216148 KB Output is correct
8 Correct 151 ms 211732 KB Output is correct
9 Correct 166 ms 204368 KB Output is correct
10 Correct 142 ms 211192 KB Output is correct
11 Correct 149 ms 208208 KB Output is correct
12 Correct 150 ms 204368 KB Output is correct
13 Correct 142 ms 204496 KB Output is correct
14 Correct 147 ms 205392 KB Output is correct
15 Correct 147 ms 206460 KB Output is correct
16 Correct 150 ms 205428 KB Output is correct
17 Correct 132 ms 203856 KB Output is correct
18 Correct 160 ms 204212 KB Output is correct
19 Correct 112 ms 203392 KB Output is correct
20 Correct 114 ms 203580 KB Output is correct
21 Correct 140 ms 204116 KB Output is correct
22 Correct 139 ms 204624 KB Output is correct
23 Correct 138 ms 210776 KB Output is correct
24 Correct 156 ms 214460 KB Output is correct
25 Correct 113 ms 203408 KB Output is correct
26 Correct 114 ms 203436 KB Output is correct
27 Correct 147 ms 215508 KB Output is correct
28 Correct 144 ms 212484 KB Output is correct
29 Correct 175 ms 206416 KB Output is correct
30 Correct 148 ms 210772 KB Output is correct
31 Correct 145 ms 208208 KB Output is correct
32 Correct 145 ms 204208 KB Output is correct
33 Correct 144 ms 204368 KB Output is correct
34 Correct 171 ms 206504 KB Output is correct
35 Correct 149 ms 205140 KB Output is correct
36 Correct 153 ms 205648 KB Output is correct
37 Correct 117 ms 203332 KB Output is correct
38 Correct 113 ms 203580 KB Output is correct
39 Correct 200 ms 213516 KB Output is correct
40 Correct 214 ms 213584 KB Output is correct
41 Correct 220 ms 213532 KB Output is correct
42 Correct 233 ms 213772 KB Output is correct
43 Correct 268 ms 213584 KB Output is correct
44 Correct 273 ms 213588 KB Output is correct
45 Correct 143 ms 212560 KB Output is correct
46 Correct 142 ms 212604 KB Output is correct
47 Correct 191 ms 213588 KB Output is correct
48 Correct 191 ms 213584 KB Output is correct
49 Correct 194 ms 213588 KB Output is correct
50 Correct 218 ms 213588 KB Output is correct
51 Correct 205 ms 213168 KB Output is correct
52 Correct 235 ms 213332 KB Output is correct
53 Correct 266 ms 213516 KB Output is correct
54 Correct 252 ms 213584 KB Output is correct
55 Incorrect 125 ms 206420 KB Output isn't correct
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 146 ms 204024 KB Output is correct
2 Correct 142 ms 204204 KB Output is correct
3 Correct 160 ms 210996 KB Output is correct
4 Correct 144 ms 214520 KB Output is correct
5 Correct 111 ms 203344 KB Output is correct
6 Correct 114 ms 203308 KB Output is correct
7 Correct 157 ms 216148 KB Output is correct
8 Correct 151 ms 211732 KB Output is correct
9 Correct 166 ms 204368 KB Output is correct
10 Correct 142 ms 211192 KB Output is correct
11 Correct 149 ms 208208 KB Output is correct
12 Correct 150 ms 204368 KB Output is correct
13 Correct 142 ms 204496 KB Output is correct
14 Correct 147 ms 205392 KB Output is correct
15 Correct 147 ms 206460 KB Output is correct
16 Correct 150 ms 205428 KB Output is correct
17 Correct 132 ms 203856 KB Output is correct
18 Correct 160 ms 204212 KB Output is correct
19 Correct 112 ms 203392 KB Output is correct
20 Correct 114 ms 203580 KB Output is correct
21 Correct 140 ms 204116 KB Output is correct
22 Correct 139 ms 204624 KB Output is correct
23 Correct 138 ms 210776 KB Output is correct
24 Correct 156 ms 214460 KB Output is correct
25 Correct 113 ms 203408 KB Output is correct
26 Correct 114 ms 203436 KB Output is correct
27 Correct 147 ms 215508 KB Output is correct
28 Correct 144 ms 212484 KB Output is correct
29 Correct 175 ms 206416 KB Output is correct
30 Correct 148 ms 210772 KB Output is correct
31 Correct 145 ms 208208 KB Output is correct
32 Correct 145 ms 204208 KB Output is correct
33 Correct 144 ms 204368 KB Output is correct
34 Correct 171 ms 206504 KB Output is correct
35 Correct 149 ms 205140 KB Output is correct
36 Correct 153 ms 205648 KB Output is correct
37 Correct 117 ms 203332 KB Output is correct
38 Correct 113 ms 203580 KB Output is correct
39 Correct 200 ms 213516 KB Output is correct
40 Correct 214 ms 213584 KB Output is correct
41 Correct 220 ms 213532 KB Output is correct
42 Correct 233 ms 213772 KB Output is correct
43 Correct 268 ms 213584 KB Output is correct
44 Correct 273 ms 213588 KB Output is correct
45 Correct 143 ms 212560 KB Output is correct
46 Correct 142 ms 212604 KB Output is correct
47 Correct 191 ms 213588 KB Output is correct
48 Correct 191 ms 213584 KB Output is correct
49 Correct 194 ms 213588 KB Output is correct
50 Correct 218 ms 213588 KB Output is correct
51 Correct 205 ms 213168 KB Output is correct
52 Correct 235 ms 213332 KB Output is correct
53 Correct 266 ms 213516 KB Output is correct
54 Correct 252 ms 213584 KB Output is correct
55 Correct 284 ms 228672 KB Output is correct
56 Correct 240 ms 223568 KB Output is correct
57 Correct 288 ms 229360 KB Output is correct
58 Correct 265 ms 225560 KB Output is correct
59 Correct 245 ms 222032 KB Output is correct
60 Correct 323 ms 229728 KB Output is correct
61 Correct 210 ms 217956 KB Output is correct
62 Correct 204 ms 218112 KB Output is correct
63 Correct 279 ms 229648 KB Output is correct
64 Correct 290 ms 229576 KB Output is correct
65 Correct 311 ms 229500 KB Output is correct
66 Correct 330 ms 229764 KB Output is correct
67 Correct 318 ms 229364 KB Output is correct
68 Correct 304 ms 229472 KB Output is correct
69 Correct 307 ms 230152 KB Output is correct
70 Correct 316 ms 229384 KB Output is correct
71 Correct 303 ms 229692 KB Output is correct
72 Correct 311 ms 229404 KB Output is correct
73 Correct 299 ms 228176 KB Output is correct
74 Correct 297 ms 229528 KB Output is correct
75 Correct 310 ms 229616 KB Output is correct
76 Correct 309 ms 229476 KB Output is correct
77 Correct 330 ms 229408 KB Output is correct
78 Correct 357 ms 229456 KB Output is correct
79 Correct 280 ms 226132 KB Output is correct
80 Correct 312 ms 225936 KB Output is correct
81 Correct 276 ms 229232 KB Output is correct
82 Incorrect 125 ms 206420 KB Output isn't correct
83 Halted 0 ms 0 KB -