109742024-04-24 20:35:10MagyarKendeSZLGTelefonközpontcpp17Time limit exceeded 40/100582ms7432 KiB
#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 2e5, INF = 1e9;

int t[4 * MAXN + 1], lazy[4 * MAXN + 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;
}

void update(int curr, int tl, int tr, int l, int r) {
    if (tr < tl || r < l) {
        return;
    }
    if (tr == tl) {
        t[curr]++;
        lazy[curr]++;
    } else {
        push(curr);
        int tmid = (tl + tr) / 2;
        update(curr * 2, tl, tmid, l, min(tmid, r));
        update(curr * 2 + 1, tmid + 1, tr, max(tmid + 1, l), r);
        t[curr] = max(t[curr * 2], t[curr * 2 + 1]);
    }
}

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;

    while (N--) {
        int B, E;
        cin >> B >> E;
        update(1, 0, M - 1, B - 1, E - 1);
    }

    while (Q--) {
        int B, E;
        cin >> B >> E;
        cout << query(1, 0, M - 1, B - 1, E - 1) << "\n";
    }
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1912 KiB
2Accepted3ms2108 KiB
subtask220/20
3Accepted4ms2468 KiB
4Accepted4ms2676 KiB
5Accepted4ms2992 KiB
6Accepted4ms3204 KiB
7Accepted4ms3516 KiB
8Accepted4ms3852 KiB
9Accepted4ms3944 KiB
subtask320/20
10Accepted4ms2468 KiB
11Accepted4ms2676 KiB
12Accepted4ms2992 KiB
13Accepted4ms3204 KiB
14Accepted4ms3516 KiB
15Accepted4ms3852 KiB
16Accepted4ms3944 KiB
17Accepted111ms3956 KiB
18Accepted179ms4012 KiB
19Accepted111ms4096 KiB
20Accepted112ms4248 KiB
21Accepted144ms4224 KiB
22Accepted178ms4080 KiB
23Accepted203ms4068 KiB
subtask40/60
24Accepted4ms2468 KiB
25Accepted4ms2676 KiB
26Accepted4ms2992 KiB
27Accepted4ms3204 KiB
28Accepted4ms3516 KiB
29Accepted4ms3852 KiB
30Accepted4ms3944 KiB
31Accepted111ms3956 KiB
32Accepted179ms4012 KiB
33Accepted111ms4096 KiB
34Accepted112ms4248 KiB
35Accepted144ms4224 KiB
36Accepted178ms4080 KiB
37Accepted203ms4068 KiB
38Time limit exceeded575ms7100 KiB
39Time limit exceeded574ms7176 KiB
40Time limit exceeded565ms7248 KiB
41Time limit exceeded546ms7164 KiB
42Time limit exceeded582ms7432 KiB
43Time limit exceeded550ms7372 KiB
44Time limit exceeded582ms7376 KiB