109752024-04-24 20:52:49MagyarKendeSZLGTelefonközpontcpp17Accepted 100/100179ms14052 KiB
#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 2e5, INF = 1e9;

int t[4 * MAXN + 1], lazy[4 * MAXN + 1];

void build(const vector<int>& v, int curr, int tl, int tr) {
    if (tl == tr) {
        t[curr] = v[tl];
    } else {
        int tmid = (tl + tr) / 2;
        build(v, curr * 2, tl, tmid);
        build(v, curr * 2 + 1, tmid + 1, tr);
        t[curr] = max(t[curr * 2], t[curr * 2 + 1]);
    }
}

void push(int curr) {
    t[curr * 2] += lazy[curr];
    t[curr * 2 + 1] += lazy[curr];
    lazy[curr * 2] += lazy[curr];
    lazy[curr * 2 + 1] += lazy[curr];
    lazy[curr] = 0;
}

int query(int curr, int tl, int tr, int l, int r) {
    if (tr < tl || r < l) {
        return -INF;
    }
    if (tl == l && tr == r) {
        return t[curr];
    }
    push(curr);
    int tmid = (tl + tr) / 2;
    return max(
        query(curr * 2, tl, tmid, l, min(tmid, r)),
        query(curr * 2 + 1, tmid + 1, tr, max(l, tmid + 1), r)
    );
}

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

    int M, N, Q;
    cin >> M >> N >> Q;
    vector<int> v(M + 1);
    while (N--) {
        int B, E;
        cin >> B >> E;
        v[B - 1]++;
        v[E]--;
    }
    for (int i = 1; i < M; i++) {
        v[i] += v[i - 1];
    }

    build(v, 1, 0, M - 1);

    while (Q--) {
        int B, E;
        cin >> B >> E;
        cout << query(1, 0, M - 1, B - 1, E - 1) << "\n";
    }
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1836 KiB
2Accepted3ms2044 KiB
subtask220/20
3Accepted3ms2400 KiB
4Accepted3ms2596 KiB
5Accepted3ms2916 KiB
6Accepted3ms2764 KiB
7Accepted3ms3020 KiB
8Accepted3ms2976 KiB
9Accepted3ms3236 KiB
subtask320/20
10Accepted3ms2400 KiB
11Accepted3ms2596 KiB
12Accepted3ms2916 KiB
13Accepted3ms2764 KiB
14Accepted3ms3020 KiB
15Accepted3ms2976 KiB
16Accepted3ms3236 KiB
17Accepted6ms3516 KiB
18Accepted6ms3764 KiB
19Accepted6ms3840 KiB
20Accepted6ms4048 KiB
21Accepted6ms4132 KiB
22Accepted6ms4156 KiB
23Accepted6ms4364 KiB
subtask460/60
24Accepted3ms2400 KiB
25Accepted3ms2596 KiB
26Accepted3ms2916 KiB
27Accepted3ms2764 KiB
28Accepted3ms3020 KiB
29Accepted3ms2976 KiB
30Accepted3ms3236 KiB
31Accepted6ms3516 KiB
32Accepted6ms3764 KiB
33Accepted6ms3840 KiB
34Accepted6ms4048 KiB
35Accepted6ms4132 KiB
36Accepted6ms4156 KiB
37Accepted6ms4364 KiB
38Accepted179ms13740 KiB
39Accepted179ms13952 KiB
40Accepted172ms13920 KiB
41Accepted172ms14048 KiB
42Accepted172ms14052 KiB
43Accepted172ms13932 KiB
44Accepted178ms13952 KiB