108002024-04-14 11:47:24AblablablaTelefonközpontcpp17Accepted 100/100152ms8996 KiB
#include <bits/stdc++.h>

using namespace std;

struct segTree{
    int meret = 1;
    vector<int> fa;

    void meretez(int n){
        while(meret < n){
            meret *= 2;
        }

        fa.assign(2 * meret - 1, 0);
    }

    int epit(int a, int b, int ind){
        if(a == b){
            return fa[ind];
        }

        int k = (a + b) / 2;
        return fa[ind] = max(epit(a, k, 2 * ind + 1), epit(k + 1, b, 2 * ind + 2));
    }

    int keres(int a, int b, int ind, int kezd, int veg){
        if(veg < a || b < kezd){
            return 0;
        } else if(kezd <= a && b <= veg){
            return fa[ind];
        }

        int k = (a + b) / 2;

        return max(keres(a, k, 2 * ind + 1, kezd, veg), keres(k + 1, b, 2 * ind + 2, kezd, veg));
    }
};

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

    int m, n, q;
    cin >> m >> n >> q;

    vector<int> helyek(m + 1);
    for(int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        a--;

        helyek[a]++;
        helyek[b]--;
    }

    segTree fa;
    fa.meretez(m);
    int akt = 0;
    for(int i = 0; i < m; i++){
        akt += helyek[i];
        fa.fa[i + fa.meret - 1] = akt;
    }

    fa.epit(0, fa.meret -1, 0);

    while(q--){
        int a, b;
        cin >> a >> b;
        a--; b--;

        cout << fa.keres(0, fa.meret - 1, 0, a, b) << "\n";
    }
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1824 KiB
2Accepted3ms2052 KiB
subtask220/20
3Accepted3ms2148 KiB
4Accepted3ms2148 KiB
5Accepted3ms2276 KiB
6Accepted3ms2484 KiB
7Accepted3ms2808 KiB
8Accepted3ms2904 KiB
9Accepted3ms2888 KiB
subtask320/20
10Accepted3ms2148 KiB
11Accepted3ms2148 KiB
12Accepted3ms2276 KiB
13Accepted3ms2484 KiB
14Accepted3ms2808 KiB
15Accepted3ms2904 KiB
16Accepted3ms2888 KiB
17Accepted6ms2968 KiB
18Accepted6ms3228 KiB
19Accepted6ms3216 KiB
20Accepted6ms3232 KiB
21Accepted6ms3224 KiB
22Accepted6ms3508 KiB
23Accepted6ms3412 KiB
subtask460/60
24Accepted3ms2148 KiB
25Accepted3ms2148 KiB
26Accepted3ms2276 KiB
27Accepted3ms2484 KiB
28Accepted3ms2808 KiB
29Accepted3ms2904 KiB
30Accepted3ms2888 KiB
31Accepted6ms2968 KiB
32Accepted6ms3228 KiB
33Accepted6ms3216 KiB
34Accepted6ms3232 KiB
35Accepted6ms3224 KiB
36Accepted6ms3508 KiB
37Accepted6ms3412 KiB
38Accepted152ms8440 KiB
39Accepted151ms8444 KiB
40Accepted148ms8692 KiB
41Accepted146ms8676 KiB
42Accepted145ms8748 KiB
43Accepted146ms8988 KiB
44Accepted149ms8996 KiB