107072024-04-10 09:43:34szilTelefonközpontcpp17Accepted 100/100128ms7432 KiB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int MAXN = 300'001;

int pref[MAXN], a[MAXN], tree[2*MAXN], n, m, q;

void upd(int u, int k) {
    tree[u += m] = k;
    for (u /= 2; u >= 1; u /= 2) {
        tree[u] = max(tree[2*u], tree[2*u+1]);
    }
}

int qry(int l, int r) {
    int res = 0; l += m; r += m;
    while (l <= r) {
        if (l % 2 == 1) res = max(res, tree[l++]);
        if (r % 2 == 0) res = max(res, tree[r--]);
        l /= 2; r /= 2;
    }
    return res;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> m >> n >> q;
    for (int i = 1; i <= n; i++) {
        int l, r; cin >> l >> r;
        pref[l]++;
        pref[r+1]--;
    }
    for (int i = 1; i <= m; i++) {
        pref[i] += pref[i-1];
        upd(i, pref[i]);
    }
    while (q--) {
        int l, r; cin >> l >> r;
        cout << qry(l, r) << "\n";
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1900 KiB
2Accepted3ms2108 KiB
subtask220/20
3Accepted3ms2304 KiB
4Accepted3ms2648 KiB
5Accepted3ms2604 KiB
6Accepted3ms2688 KiB
7Accepted3ms2860 KiB
8Accepted3ms2940 KiB
9Accepted3ms3024 KiB
subtask320/20
10Accepted3ms2304 KiB
11Accepted3ms2648 KiB
12Accepted3ms2604 KiB
13Accepted3ms2688 KiB
14Accepted3ms2860 KiB
15Accepted3ms2940 KiB
16Accepted3ms3024 KiB
17Accepted4ms3332 KiB
18Accepted4ms3284 KiB
19Accepted4ms3316 KiB
20Accepted4ms3280 KiB
21Accepted4ms3280 KiB
22Accepted4ms3284 KiB
23Accepted4ms3292 KiB
subtask460/60
24Accepted3ms2304 KiB
25Accepted3ms2648 KiB
26Accepted3ms2604 KiB
27Accepted3ms2688 KiB
28Accepted3ms2860 KiB
29Accepted3ms2940 KiB
30Accepted3ms3024 KiB
31Accepted4ms3332 KiB
32Accepted4ms3284 KiB
33Accepted4ms3316 KiB
34Accepted4ms3280 KiB
35Accepted4ms3280 KiB
36Accepted4ms3284 KiB
37Accepted4ms3292 KiB
38Accepted128ms6884 KiB
39Accepted127ms6900 KiB
40Accepted125ms7100 KiB
41Accepted123ms7212 KiB
42Accepted123ms7432 KiB
43Accepted123ms7424 KiB
44Accepted123ms7432 KiB