108192024-04-15 19:14:44bovizdbTelefonközpontcpp17Wrong answer 0/100200ms25888 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--;
        if (a > b)
            break;
        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 answer3ms2084 KiB
subtask20/20
3Wrong answer3ms2200 KiB
4Wrong answer3ms2520 KiB
5Wrong answer3ms2664 KiB
6Wrong answer3ms2876 KiB
7Wrong answer3ms3208 KiB
8Wrong answer3ms3152 KiB
9Wrong answer3ms3372 KiB
subtask30/20
10Wrong answer3ms2200 KiB
11Wrong answer3ms2520 KiB
12Wrong answer3ms2664 KiB
13Wrong answer3ms2876 KiB
14Wrong answer3ms3208 KiB
15Wrong answer3ms3152 KiB
16Wrong answer3ms3372 KiB
17Wrong answer6ms3676 KiB
18Wrong answer6ms3796 KiB
19Wrong answer6ms3776 KiB
20Wrong answer6ms3548 KiB
21Wrong answer6ms3672 KiB
22Wrong answer6ms3680 KiB
23Wrong answer6ms3928 KiB
subtask40/60
24Wrong answer3ms2200 KiB
25Wrong answer3ms2520 KiB
26Wrong answer3ms2664 KiB
27Wrong answer3ms2876 KiB
28Wrong answer3ms3208 KiB
29Wrong answer3ms3152 KiB
30Wrong answer3ms3372 KiB
31Wrong answer6ms3676 KiB
32Wrong answer6ms3796 KiB
33Wrong answer6ms3776 KiB
34Wrong answer6ms3548 KiB
35Wrong answer6ms3672 KiB
36Wrong answer6ms3680 KiB
37Wrong answer6ms3928 KiB
38Wrong answer200ms24304 KiB
39Wrong answer197ms25296 KiB
40Wrong answer195ms24592 KiB
41Wrong answer195ms24584 KiB
42Wrong answer199ms25092 KiB
43Wrong answer197ms25508 KiB
44Wrong answer197ms25888 KiB