107312024-04-10 20:17:25zsebiTelefonközpontcpp17Accepted 100/100165ms15848 KiB
#include <iostream>
#include <queue>
#include <algorithm>
#define ll long long
using namespace std;
ll n, m,q;

vector<ll>x,st;

void epit(ll p, ll l, ll r) {
    if (l == r)	{
        st[p] = x[l];
        return;
    }
    ll k = (l + r) / 2;
    epit(2*p, l, k);
    epit(2*p+1, k + 1, r);
    st[p] = max(st[2 * p], st[2 * p + 1]);
}
ll leker(ll p, ll l, ll r, ll a, ll b) {
    if (a <= l && r <= b) {
        return st[p];
    }
    else if (b < l || r < a)return 0;

    ll k = (l + r) / 2;
    return max(leker(2 * p, l, k, a, b), leker(2 * p + 1, k + 1, r, a, b));
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> m >> n >> q;
    x.resize(m + 2);
    st.resize(4 * m + 1);
    for (int i = 1; i <= n; i++)
    {
        ll a, b;
        cin >> a >> b;
        x[a]++;
        x[b + 1]--;

    }
    for (int i = 1; i <= m; ++i)
    {
        x[i] += x[i - 1];
    }
    epit(1, 1, m);
    for (int i = 1; i <= q; ++i)
    {
        ll a, b;
        cin >> a >> b;
        cout<<leker(1, 1, m, a, b)<<"\n";
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms2040 KiB
2Accepted3ms2248 KiB
subtask220/20
3Accepted3ms2424 KiB
4Accepted3ms2512 KiB
5Accepted3ms2604 KiB
6Accepted3ms2732 KiB
7Accepted3ms2944 KiB
8Accepted3ms3116 KiB
9Accepted3ms3204 KiB
subtask320/20
10Accepted3ms2424 KiB
11Accepted3ms2512 KiB
12Accepted3ms2604 KiB
13Accepted3ms2732 KiB
14Accepted3ms2944 KiB
15Accepted3ms3116 KiB
16Accepted3ms3204 KiB
17Accepted6ms3528 KiB
18Accepted6ms3772 KiB
19Accepted6ms3728 KiB
20Accepted6ms3940 KiB
21Accepted6ms3860 KiB
22Accepted6ms3868 KiB
23Accepted6ms3868 KiB
subtask460/60
24Accepted3ms2424 KiB
25Accepted3ms2512 KiB
26Accepted3ms2604 KiB
27Accepted3ms2732 KiB
28Accepted3ms2944 KiB
29Accepted3ms3116 KiB
30Accepted3ms3204 KiB
31Accepted6ms3528 KiB
32Accepted6ms3772 KiB
33Accepted6ms3728 KiB
34Accepted6ms3940 KiB
35Accepted6ms3860 KiB
36Accepted6ms3868 KiB
37Accepted6ms3868 KiB
38Accepted165ms15500 KiB
39Accepted163ms15536 KiB
40Accepted158ms15564 KiB
41Accepted160ms15600 KiB
42Accepted159ms15700 KiB
43Accepted158ms15848 KiB
44Accepted157ms15848 KiB