108172024-04-15 18:58:14bovizdbTelefonközpontcpp17Wrong answer 0/100199ms26276 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)
{
    while(a < b)
    {
        if (a%2 == 1)
            a++;
        if (b%2 == 0)
            b--;
        a /= 2;
        b /= 2;
    }
    return tree[a];
}

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
1Accepted3ms1892 KiB
2Wrong answer3ms2096 KiB
subtask20/20
3Wrong answer3ms2452 KiB
4Wrong answer3ms2412 KiB
5Wrong answer3ms2664 KiB
6Wrong answer3ms2988 KiB
7Wrong answer3ms3216 KiB
8Wrong answer3ms3420 KiB
9Wrong answer3ms3748 KiB
subtask30/20
10Wrong answer3ms2452 KiB
11Wrong answer3ms2412 KiB
12Wrong answer3ms2664 KiB
13Wrong answer3ms2988 KiB
14Wrong answer3ms3216 KiB
15Wrong answer3ms3420 KiB
16Wrong answer3ms3748 KiB
17Wrong answer6ms4256 KiB
18Wrong answer6ms4464 KiB
19Wrong answer6ms4676 KiB
20Wrong answer6ms4704 KiB
21Wrong answer6ms4780 KiB
22Wrong answer6ms4784 KiB
23Wrong answer6ms4860 KiB
subtask40/60
24Wrong answer3ms2452 KiB
25Wrong answer3ms2412 KiB
26Wrong answer3ms2664 KiB
27Wrong answer3ms2988 KiB
28Wrong answer3ms3216 KiB
29Wrong answer3ms3420 KiB
30Wrong answer3ms3748 KiB
31Wrong answer6ms4256 KiB
32Wrong answer6ms4464 KiB
33Wrong answer6ms4676 KiB
34Wrong answer6ms4704 KiB
35Wrong answer6ms4780 KiB
36Wrong answer6ms4784 KiB
37Wrong answer6ms4860 KiB
38Wrong answer199ms25004 KiB
39Wrong answer194ms26080 KiB
40Wrong answer195ms25088 KiB
41Wrong answer197ms25048 KiB
42Wrong answer194ms25596 KiB
43Wrong answer196ms26192 KiB
44Wrong answer194ms26276 KiB