답안 #386986

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
386986 2021-04-07T18:40:01 Z keko37 푸드 코트 (JOI21_foodcourt) C++14
68 / 100
388 ms 47524 KB
#include<bits/stdc++.h>

using namespace std;

typedef long long llint;
typedef pair <llint, llint> pi;

const int MAXN = 250005;

int n, m, q, ofs = 1;
llint tip[MAXN], lef[MAXN], rig[MAXN], k[MAXN], col[MAXN], sol[MAXN];
pi t[MAXN * 4]; llint sum[MAXN];
vector <pi> v[MAXN];
vector <int> u[MAXN];

pi spoji (pi a, pi b) {
    return {a.first + b.first, max(a.second + b.first, b.second)};
}

void update (int pos, llint val) {
    pos += ofs;
    t[pos].first += val;
    t[pos].second = max(t[pos].first, 0LL);
    sum[pos] = t[pos].second;
    pos /= 2;
    while (pos > 0) {
        t[pos] = spoji(t[pos * 2], t[pos * 2 + 1]);
        sum[pos] = sum[2 * pos] + sum[2 * pos + 1];
        pos /= 2;
    }
}

pi upit (int x, int from, int to, int lo, int hi) {
    if (from <= lo && hi <= to) return t[x];
    if (to < lo || hi < from) return {0, 0};
    return spoji(upit(2 * x, from, to, lo, (lo + hi) / 2), upit(2 * x + 1, from, to, (lo + hi) / 2 + 1, hi));
}

int nadi (int x, llint val) {
    if (x >= ofs) return x;
    if (val <= sum[2 * x + 1]) return nadi(2 * x + 1, val);
    return nadi(2 * x, val - sum[2 * x + 1]);
}

int bs (int pos, llint val) {
    int curr = pos + ofs;
    llint curr_sum = sum[curr];
    if (val <= curr_sum) return pos;
    while (curr > 1) {
        if (curr % 2 == 0) {
            curr /= 2;
        } else {
            if (val > curr_sum + sum[curr - 1]) {
                curr_sum += sum[curr - 1];
                curr /= 2;
            } else {
                return nadi(curr - 1, val - curr_sum) - ofs;
            }
        }
    }
    return 0;
}

void get_curr_siz () {
    for (int i = 1; i <= q; i++) {
        if (tip[i] == 1) {
            v[lef[i]].push_back({k[i], i});
            v[rig[i] + 1].push_back({-k[i], i});
        } else if (tip[i] == 2) {
            v[lef[i]].push_back({-k[i], i});
            v[rig[i] + 1].push_back({k[i], i});
        } else {
            u[lef[i]].push_back(i);
        }
    }
    while (ofs < q + 1) ofs *= 2;
    for (int pos = 1; pos <= n; pos++) {
        for (auto pp : v[pos]) {
            llint val = pp.first;
            int ind = pp.second;
            update(ind, val);
        }
        for (auto i : u[pos]) {
            llint siz = upit(1, 0, i, 0, ofs - 1).second;
            if (k[i] <= siz) {
                sol[i] = col[bs(i, siz - k[i] + 1)];
            }
        }
    }
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m >> q;
    for (int i = 1; i <= q; i++) {
        cin >> tip[i];
        if (tip[i] == 1) {
            cin >> lef[i] >> rig[i] >> col[i] >> k[i];
        } else if (tip[i] == 2) {
            cin >> lef[i] >> rig[i] >> k[i];
        } else {
            cin >> lef[i] >> k[i];
        }
    }
    get_curr_siz();
    for (int i = 1; i <= q; i++) {
        if (tip[i] != 3) continue;
        cout << sol[i] << '\n';
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 12396 KB Output is correct
2 Correct 12 ms 12396 KB Output is correct
3 Correct 10 ms 12396 KB Output is correct
4 Correct 11 ms 12396 KB Output is correct
5 Correct 10 ms 12396 KB Output is correct
6 Correct 10 ms 12396 KB Output is correct
7 Correct 10 ms 12396 KB Output is correct
8 Correct 11 ms 12396 KB Output is correct
9 Correct 11 ms 12396 KB Output is correct
10 Correct 11 ms 12396 KB Output is correct
11 Correct 11 ms 12396 KB Output is correct
12 Correct 11 ms 12396 KB Output is correct
13 Correct 10 ms 12396 KB Output is correct
14 Correct 10 ms 12524 KB Output is correct
15 Correct 10 ms 12396 KB Output is correct
16 Correct 10 ms 12524 KB Output is correct
17 Correct 10 ms 12416 KB Output is correct
18 Correct 10 ms 12396 KB Output is correct
19 Correct 10 ms 12396 KB Output is correct
20 Correct 12 ms 12396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 12396 KB Output is correct
2 Correct 12 ms 12396 KB Output is correct
3 Correct 10 ms 12396 KB Output is correct
4 Correct 11 ms 12396 KB Output is correct
5 Correct 10 ms 12396 KB Output is correct
6 Correct 10 ms 12396 KB Output is correct
7 Correct 10 ms 12396 KB Output is correct
8 Correct 11 ms 12396 KB Output is correct
9 Correct 11 ms 12396 KB Output is correct
10 Correct 11 ms 12396 KB Output is correct
11 Correct 11 ms 12396 KB Output is correct
12 Correct 11 ms 12396 KB Output is correct
13 Correct 10 ms 12396 KB Output is correct
14 Correct 10 ms 12524 KB Output is correct
15 Correct 10 ms 12396 KB Output is correct
16 Correct 10 ms 12524 KB Output is correct
17 Correct 10 ms 12416 KB Output is correct
18 Correct 10 ms 12396 KB Output is correct
19 Correct 10 ms 12396 KB Output is correct
20 Correct 12 ms 12396 KB Output is correct
21 Correct 11 ms 12544 KB Output is correct
22 Correct 10 ms 12524 KB Output is correct
23 Correct 11 ms 12416 KB Output is correct
24 Correct 11 ms 12524 KB Output is correct
25 Correct 10 ms 12396 KB Output is correct
26 Correct 10 ms 12396 KB Output is correct
27 Correct 13 ms 12544 KB Output is correct
28 Correct 11 ms 12536 KB Output is correct
29 Correct 11 ms 12524 KB Output is correct
30 Correct 11 ms 12524 KB Output is correct
31 Correct 10 ms 12524 KB Output is correct
32 Correct 11 ms 12524 KB Output is correct
33 Correct 10 ms 12396 KB Output is correct
34 Correct 11 ms 12524 KB Output is correct
35 Correct 11 ms 12396 KB Output is correct
36 Correct 10 ms 12524 KB Output is correct
37 Correct 10 ms 12396 KB Output is correct
38 Correct 11 ms 12396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 21996 KB Output is correct
2 Correct 77 ms 21996 KB Output is correct
3 Correct 76 ms 21868 KB Output is correct
4 Correct 75 ms 21868 KB Output is correct
5 Correct 71 ms 22112 KB Output is correct
6 Correct 86 ms 21996 KB Output is correct
7 Correct 50 ms 20184 KB Output is correct
8 Correct 46 ms 20376 KB Output is correct
9 Correct 74 ms 21996 KB Output is correct
10 Correct 82 ms 22124 KB Output is correct
11 Correct 77 ms 21996 KB Output is correct
12 Correct 69 ms 21996 KB Output is correct
13 Correct 61 ms 21228 KB Output is correct
14 Correct 75 ms 22252 KB Output is correct
15 Correct 71 ms 22380 KB Output is correct
16 Correct 72 ms 22636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 388 ms 47524 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 12396 KB Output is correct
2 Correct 12 ms 12396 KB Output is correct
3 Correct 10 ms 12396 KB Output is correct
4 Correct 11 ms 12396 KB Output is correct
5 Correct 10 ms 12396 KB Output is correct
6 Correct 10 ms 12396 KB Output is correct
7 Correct 10 ms 12396 KB Output is correct
8 Correct 11 ms 12396 KB Output is correct
9 Correct 11 ms 12396 KB Output is correct
10 Correct 11 ms 12396 KB Output is correct
11 Correct 11 ms 12396 KB Output is correct
12 Correct 11 ms 12396 KB Output is correct
13 Correct 10 ms 12396 KB Output is correct
14 Correct 10 ms 12524 KB Output is correct
15 Correct 10 ms 12396 KB Output is correct
16 Correct 10 ms 12524 KB Output is correct
17 Correct 10 ms 12416 KB Output is correct
18 Correct 10 ms 12396 KB Output is correct
19 Correct 10 ms 12396 KB Output is correct
20 Correct 12 ms 12396 KB Output is correct
21 Correct 81 ms 21996 KB Output is correct
22 Correct 77 ms 21996 KB Output is correct
23 Correct 76 ms 21868 KB Output is correct
24 Correct 75 ms 21868 KB Output is correct
25 Correct 71 ms 22112 KB Output is correct
26 Correct 86 ms 21996 KB Output is correct
27 Correct 50 ms 20184 KB Output is correct
28 Correct 46 ms 20376 KB Output is correct
29 Correct 74 ms 21996 KB Output is correct
30 Correct 82 ms 22124 KB Output is correct
31 Correct 77 ms 21996 KB Output is correct
32 Correct 69 ms 21996 KB Output is correct
33 Correct 61 ms 21228 KB Output is correct
34 Correct 75 ms 22252 KB Output is correct
35 Correct 71 ms 22380 KB Output is correct
36 Correct 72 ms 22636 KB Output is correct
37 Correct 68 ms 21228 KB Output is correct
38 Correct 63 ms 20460 KB Output is correct
39 Correct 37 ms 19288 KB Output is correct
40 Correct 44 ms 20108 KB Output is correct
41 Correct 87 ms 22124 KB Output is correct
42 Correct 76 ms 22380 KB Output is correct
43 Correct 78 ms 22380 KB Output is correct
44 Correct 75 ms 22252 KB Output is correct
45 Correct 86 ms 22380 KB Output is correct
46 Correct 75 ms 22508 KB Output is correct
47 Correct 59 ms 21140 KB Output is correct
48 Correct 66 ms 22252 KB Output is correct
49 Correct 53 ms 19436 KB Output is correct
50 Correct 68 ms 20844 KB Output is correct
51 Correct 80 ms 22388 KB Output is correct
52 Correct 79 ms 22380 KB Output is correct
53 Correct 60 ms 20460 KB Output is correct
54 Correct 77 ms 22636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 21484 KB Output is correct
2 Correct 89 ms 22508 KB Output is correct
3 Correct 92 ms 22636 KB Output is correct
4 Correct 63 ms 19564 KB Output is correct
5 Correct 73 ms 21228 KB Output is correct
6 Correct 87 ms 22636 KB Output is correct
7 Correct 49 ms 20064 KB Output is correct
8 Correct 51 ms 19676 KB Output is correct
9 Correct 68 ms 21844 KB Output is correct
10 Correct 54 ms 19564 KB Output is correct
11 Correct 78 ms 22252 KB Output is correct
12 Correct 75 ms 22252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 12396 KB Output is correct
2 Correct 12 ms 12396 KB Output is correct
3 Correct 10 ms 12396 KB Output is correct
4 Correct 11 ms 12396 KB Output is correct
5 Correct 10 ms 12396 KB Output is correct
6 Correct 10 ms 12396 KB Output is correct
7 Correct 10 ms 12396 KB Output is correct
8 Correct 11 ms 12396 KB Output is correct
9 Correct 11 ms 12396 KB Output is correct
10 Correct 11 ms 12396 KB Output is correct
11 Correct 11 ms 12396 KB Output is correct
12 Correct 11 ms 12396 KB Output is correct
13 Correct 10 ms 12396 KB Output is correct
14 Correct 10 ms 12524 KB Output is correct
15 Correct 10 ms 12396 KB Output is correct
16 Correct 10 ms 12524 KB Output is correct
17 Correct 10 ms 12416 KB Output is correct
18 Correct 10 ms 12396 KB Output is correct
19 Correct 10 ms 12396 KB Output is correct
20 Correct 12 ms 12396 KB Output is correct
21 Correct 11 ms 12544 KB Output is correct
22 Correct 10 ms 12524 KB Output is correct
23 Correct 11 ms 12416 KB Output is correct
24 Correct 11 ms 12524 KB Output is correct
25 Correct 10 ms 12396 KB Output is correct
26 Correct 10 ms 12396 KB Output is correct
27 Correct 13 ms 12544 KB Output is correct
28 Correct 11 ms 12536 KB Output is correct
29 Correct 11 ms 12524 KB Output is correct
30 Correct 11 ms 12524 KB Output is correct
31 Correct 10 ms 12524 KB Output is correct
32 Correct 11 ms 12524 KB Output is correct
33 Correct 10 ms 12396 KB Output is correct
34 Correct 11 ms 12524 KB Output is correct
35 Correct 11 ms 12396 KB Output is correct
36 Correct 10 ms 12524 KB Output is correct
37 Correct 10 ms 12396 KB Output is correct
38 Correct 11 ms 12396 KB Output is correct
39 Correct 81 ms 21996 KB Output is correct
40 Correct 77 ms 21996 KB Output is correct
41 Correct 76 ms 21868 KB Output is correct
42 Correct 75 ms 21868 KB Output is correct
43 Correct 71 ms 22112 KB Output is correct
44 Correct 86 ms 21996 KB Output is correct
45 Correct 50 ms 20184 KB Output is correct
46 Correct 46 ms 20376 KB Output is correct
47 Correct 74 ms 21996 KB Output is correct
48 Correct 82 ms 22124 KB Output is correct
49 Correct 77 ms 21996 KB Output is correct
50 Correct 69 ms 21996 KB Output is correct
51 Correct 61 ms 21228 KB Output is correct
52 Correct 75 ms 22252 KB Output is correct
53 Correct 71 ms 22380 KB Output is correct
54 Correct 72 ms 22636 KB Output is correct
55 Correct 68 ms 21228 KB Output is correct
56 Correct 63 ms 20460 KB Output is correct
57 Correct 37 ms 19288 KB Output is correct
58 Correct 44 ms 20108 KB Output is correct
59 Correct 87 ms 22124 KB Output is correct
60 Correct 76 ms 22380 KB Output is correct
61 Correct 78 ms 22380 KB Output is correct
62 Correct 75 ms 22252 KB Output is correct
63 Correct 86 ms 22380 KB Output is correct
64 Correct 75 ms 22508 KB Output is correct
65 Correct 59 ms 21140 KB Output is correct
66 Correct 66 ms 22252 KB Output is correct
67 Correct 53 ms 19436 KB Output is correct
68 Correct 68 ms 20844 KB Output is correct
69 Correct 80 ms 22388 KB Output is correct
70 Correct 79 ms 22380 KB Output is correct
71 Correct 60 ms 20460 KB Output is correct
72 Correct 77 ms 22636 KB Output is correct
73 Correct 76 ms 21484 KB Output is correct
74 Correct 89 ms 22508 KB Output is correct
75 Correct 92 ms 22636 KB Output is correct
76 Correct 63 ms 19564 KB Output is correct
77 Correct 73 ms 21228 KB Output is correct
78 Correct 87 ms 22636 KB Output is correct
79 Correct 49 ms 20064 KB Output is correct
80 Correct 51 ms 19676 KB Output is correct
81 Correct 68 ms 21844 KB Output is correct
82 Correct 54 ms 19564 KB Output is correct
83 Correct 78 ms 22252 KB Output is correct
84 Correct 75 ms 22252 KB Output is correct
85 Correct 79 ms 21740 KB Output is correct
86 Correct 92 ms 22892 KB Output is correct
87 Correct 87 ms 21616 KB Output is correct
88 Correct 90 ms 23020 KB Output is correct
89 Correct 59 ms 19308 KB Output is correct
90 Correct 95 ms 22892 KB Output is correct
91 Correct 70 ms 21024 KB Output is correct
92 Correct 69 ms 20460 KB Output is correct
93 Correct 94 ms 22892 KB Output is correct
94 Correct 92 ms 22728 KB Output is correct
95 Correct 98 ms 22596 KB Output is correct
96 Correct 99 ms 22892 KB Output is correct
97 Correct 98 ms 22892 KB Output is correct
98 Correct 77 ms 21356 KB Output is correct
99 Correct 62 ms 21712 KB Output is correct
100 Correct 67 ms 20844 KB Output is correct
101 Correct 75 ms 22788 KB Output is correct
102 Correct 76 ms 22892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 12396 KB Output is correct
2 Correct 12 ms 12396 KB Output is correct
3 Correct 10 ms 12396 KB Output is correct
4 Correct 11 ms 12396 KB Output is correct
5 Correct 10 ms 12396 KB Output is correct
6 Correct 10 ms 12396 KB Output is correct
7 Correct 10 ms 12396 KB Output is correct
8 Correct 11 ms 12396 KB Output is correct
9 Correct 11 ms 12396 KB Output is correct
10 Correct 11 ms 12396 KB Output is correct
11 Correct 11 ms 12396 KB Output is correct
12 Correct 11 ms 12396 KB Output is correct
13 Correct 10 ms 12396 KB Output is correct
14 Correct 10 ms 12524 KB Output is correct
15 Correct 10 ms 12396 KB Output is correct
16 Correct 10 ms 12524 KB Output is correct
17 Correct 10 ms 12416 KB Output is correct
18 Correct 10 ms 12396 KB Output is correct
19 Correct 10 ms 12396 KB Output is correct
20 Correct 12 ms 12396 KB Output is correct
21 Correct 11 ms 12544 KB Output is correct
22 Correct 10 ms 12524 KB Output is correct
23 Correct 11 ms 12416 KB Output is correct
24 Correct 11 ms 12524 KB Output is correct
25 Correct 10 ms 12396 KB Output is correct
26 Correct 10 ms 12396 KB Output is correct
27 Correct 13 ms 12544 KB Output is correct
28 Correct 11 ms 12536 KB Output is correct
29 Correct 11 ms 12524 KB Output is correct
30 Correct 11 ms 12524 KB Output is correct
31 Correct 10 ms 12524 KB Output is correct
32 Correct 11 ms 12524 KB Output is correct
33 Correct 10 ms 12396 KB Output is correct
34 Correct 11 ms 12524 KB Output is correct
35 Correct 11 ms 12396 KB Output is correct
36 Correct 10 ms 12524 KB Output is correct
37 Correct 10 ms 12396 KB Output is correct
38 Correct 11 ms 12396 KB Output is correct
39 Correct 81 ms 21996 KB Output is correct
40 Correct 77 ms 21996 KB Output is correct
41 Correct 76 ms 21868 KB Output is correct
42 Correct 75 ms 21868 KB Output is correct
43 Correct 71 ms 22112 KB Output is correct
44 Correct 86 ms 21996 KB Output is correct
45 Correct 50 ms 20184 KB Output is correct
46 Correct 46 ms 20376 KB Output is correct
47 Correct 74 ms 21996 KB Output is correct
48 Correct 82 ms 22124 KB Output is correct
49 Correct 77 ms 21996 KB Output is correct
50 Correct 69 ms 21996 KB Output is correct
51 Correct 61 ms 21228 KB Output is correct
52 Correct 75 ms 22252 KB Output is correct
53 Correct 71 ms 22380 KB Output is correct
54 Correct 72 ms 22636 KB Output is correct
55 Incorrect 388 ms 47524 KB Output isn't correct
56 Halted 0 ms 0 KB -