답안 #1102531

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1102531 2024-10-18T08:36:29 Z ShadowShark Inspections (NOI23_inspections) C++17
100 / 100
291 ms 33924 KB
#include <bits/stdc++.h>
using namespace std;

const int maxN = 2e5 + 5;
long long tick[maxN], ans[maxN];
set<pair<int, int>> seg;
vector<pair<long long, int>> query;
int n, m, q;

bool cmp(pair<long long, int> A, pair<long long, int> B) {
    if (A.first != B.first) return A.first > B.first;
    return A.second < B.second;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> m >> q;

    seg.insert({1, n});
    tick[1] = 1e18;

    long long curr = 1;
    for (int i = 1; i <= m; i++) {
        int L, R; bool kt = false;
        cin >> L >> R;

        /// Left side
        if (L > 1) {
            auto it = seg.lower_bound({L, L}); it--;
            auto [u, v] = *it;
            if (L <= v) {
                seg.erase(it);
                seg.insert({u, L - 1});
                if (v <= R) query.push_back({curr - (tick[u] + L - u) - 1, -1 * (v - L + 1)}); /// update L -> v
                else {
                    kt = true;
                    query.push_back({curr - (tick[u] + L - u) - 1, -1 * (R - L + 1)}); /// save from L -> R
                    seg.insert({R + 1, v}); tick[R + 1] = tick[u] + R + 1 - u;
                }
            }
        }

        if (!kt) {
            /// Middle
            auto it = seg.lower_bound({L, L});
            while (it != seg.end()) {
                auto [u, v] = *it;
                if (R < u) break;
                it = seg.erase(it);

                /// L <= u <= v <= R
                if (L <= u && v <= R) query.push_back({(curr + u - L) - tick[u] - 1, -1 * (v - u + 1)});
                else { /// L <= u <= R < v
                    /// u -> R
                    query.push_back({curr + u - L - tick[u] - 1, -1 * (R - u + 1)});
                    /// R + 1 -> v
                    seg.insert({R + 1, v});
                    tick[R + 1] = tick[u] + (R + 1) - u;
                    break ;
                }
            }
        }

        seg.insert({L, R});
        tick[L] = curr; curr += R - L + 1;
    }

    for (int i = 1; i <= q; i++) {
        long long s;
        cin >> s;

        query.push_back({s, i});
    }

    sort(query.begin(), query.end(), cmp);

    curr = 0;
    for (auto [s, id]: query) {
        if (id < 0) curr += abs(id);
            else ans[id] = curr;
    }

    for (int i = 1; i <= q; i++)
        cout << ans[i] << ' ';

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2552 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2400 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2552 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2400 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 62 ms 9664 KB Output is correct
14 Correct 57 ms 9672 KB Output is correct
15 Correct 50 ms 9672 KB Output is correct
16 Correct 47 ms 9664 KB Output is correct
17 Correct 49 ms 9672 KB Output is correct
18 Correct 45 ms 9672 KB Output is correct
19 Correct 46 ms 9416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 44 ms 9684 KB Output is correct
4 Correct 52 ms 10960 KB Output is correct
5 Correct 131 ms 23644 KB Output is correct
6 Correct 169 ms 24256 KB Output is correct
7 Correct 119 ms 15280 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2552 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2400 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 62 ms 9664 KB Output is correct
14 Correct 57 ms 9672 KB Output is correct
15 Correct 50 ms 9672 KB Output is correct
16 Correct 47 ms 9664 KB Output is correct
17 Correct 49 ms 9672 KB Output is correct
18 Correct 45 ms 9672 KB Output is correct
19 Correct 46 ms 9416 KB Output is correct
20 Correct 53 ms 10696 KB Output is correct
21 Correct 48 ms 10696 KB Output is correct
22 Correct 51 ms 10696 KB Output is correct
23 Correct 46 ms 9988 KB Output is correct
24 Correct 56 ms 10688 KB Output is correct
25 Correct 64 ms 10968 KB Output is correct
26 Correct 60 ms 10424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2552 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2400 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 62 ms 9664 KB Output is correct
14 Correct 57 ms 9672 KB Output is correct
15 Correct 50 ms 9672 KB Output is correct
16 Correct 47 ms 9664 KB Output is correct
17 Correct 49 ms 9672 KB Output is correct
18 Correct 45 ms 9672 KB Output is correct
19 Correct 46 ms 9416 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Correct 1 ms 2384 KB Output is correct
22 Correct 44 ms 9684 KB Output is correct
23 Correct 52 ms 10960 KB Output is correct
24 Correct 131 ms 23644 KB Output is correct
25 Correct 169 ms 24256 KB Output is correct
26 Correct 119 ms 15280 KB Output is correct
27 Correct 1 ms 2384 KB Output is correct
28 Correct 1 ms 2384 KB Output is correct
29 Correct 53 ms 10696 KB Output is correct
30 Correct 48 ms 10696 KB Output is correct
31 Correct 51 ms 10696 KB Output is correct
32 Correct 46 ms 9988 KB Output is correct
33 Correct 56 ms 10688 KB Output is correct
34 Correct 64 ms 10968 KB Output is correct
35 Correct 60 ms 10424 KB Output is correct
36 Correct 184 ms 22964 KB Output is correct
37 Correct 216 ms 24240 KB Output is correct
38 Correct 217 ms 24264 KB Output is correct
39 Correct 151 ms 24244 KB Output is correct
40 Correct 219 ms 24488 KB Output is correct
41 Correct 232 ms 28328 KB Output is correct
42 Correct 231 ms 28776 KB Output is correct
43 Correct 228 ms 33348 KB Output is correct
44 Correct 247 ms 33924 KB Output is correct
45 Correct 219 ms 24252 KB Output is correct
46 Correct 278 ms 25512 KB Output is correct
47 Correct 291 ms 26024 KB Output is correct
48 Correct 187 ms 24248 KB Output is correct