108212024-04-15 19:50:10bovizdbTelefonközpontcpp17Accepted 100/100216ms26192 KiB
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long
#define pll pair<ll, ll>
#define fs first
#define sc second
#define vll vector<ll>
#define v2ll vector<vll>

ll m, n, q;
priority_queue<pll> calls;
priority_queue<ll> finish;
vll tree;

ll ans(ll a, ll b)
{
    ll res = 0;
    while(a <= b)
    {
        if (a%2 == 1)
            res = max(res, tree[a++]);
        if (b%2 == 0)
            res = max(res, tree[b--]);
        a /= 2;
        b /= 2;
    }
    return res;
}

void solve()
{
    cin >> m >> n >> q;
    ll k = 1;
    while(k < m)
        k *= 2;
    tree.resize(2*k);
    for (ll i = 0; i < n; i++)
    {
        ll k, v;
        cin >> k >> v;
        k--; v--;
        calls.push({-k, -v});
    }
    ll pcs = 0;
    for (ll i = 0; i < m; i++)
    {
        while(!calls.empty() && -(calls.top().fs) == i)
        {
            pcs++;
            finish.push(calls.top().sc);
            calls.pop();
        }
        while(finish.size() > 0 && -finish.top() < i)
        {
            pcs--;
            finish.pop();
        }
        tree[k+i] = pcs;
    }
    for (ll i = 2*k-1; i > 0; i-=2)
    {
        tree[i/2] = max(tree[i], tree[i-1]);
    }
    for (ll i = 0; i < q; i++)
    {
        ll l, r;
        cin >> l >> r;
        l--; r--;
        cout << ans(l+k, r+k) << "\n";
    }
}
 
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1888 KiB
2Accepted3ms2128 KiB
subtask220/20
3Accepted3ms2500 KiB
4Accepted3ms2784 KiB
5Accepted3ms2992 KiB
6Accepted3ms2836 KiB
7Accepted3ms3160 KiB
8Accepted3ms3112 KiB
9Accepted3ms3244 KiB
subtask320/20
10Accepted3ms2500 KiB
11Accepted3ms2784 KiB
12Accepted3ms2992 KiB
13Accepted3ms2836 KiB
14Accepted3ms3160 KiB
15Accepted3ms3112 KiB
16Accepted3ms3244 KiB
17Accepted6ms3860 KiB
18Accepted6ms3976 KiB
19Accepted6ms4224 KiB
20Accepted6ms4296 KiB
21Accepted6ms4224 KiB
22Accepted6ms4332 KiB
23Accepted6ms4444 KiB
subtask460/60
24Accepted3ms2500 KiB
25Accepted3ms2784 KiB
26Accepted3ms2992 KiB
27Accepted3ms2836 KiB
28Accepted3ms3160 KiB
29Accepted3ms3112 KiB
30Accepted3ms3244 KiB
31Accepted6ms3860 KiB
32Accepted6ms3976 KiB
33Accepted6ms4224 KiB
34Accepted6ms4296 KiB
35Accepted6ms4224 KiB
36Accepted6ms4332 KiB
37Accepted6ms4444 KiB
38Accepted216ms24600 KiB
39Accepted210ms25696 KiB
40Accepted209ms24968 KiB
41Accepted209ms25008 KiB
42Accepted208ms25756 KiB
43Accepted209ms26104 KiB
44Accepted210ms26192 KiB