108202024-04-15 19:17:36bovizdbTelefonközpontcpp17Wrong answer 0/100217ms25912 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++]);
        if (a > b)
            break;
        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
1Accepted3ms1892 KiB
2Wrong answer3ms2120 KiB
subtask20/20
3Wrong answer3ms2508 KiB
4Wrong answer3ms2816 KiB
5Wrong answer3ms3096 KiB
6Wrong answer3ms3060 KiB
7Wrong answer3ms3396 KiB
8Wrong answer3ms3720 KiB
9Wrong answer3ms3700 KiB
subtask30/20
10Wrong answer3ms2508 KiB
11Wrong answer3ms2816 KiB
12Wrong answer3ms3096 KiB
13Wrong answer3ms3060 KiB
14Wrong answer3ms3396 KiB
15Wrong answer3ms3720 KiB
16Wrong answer3ms3700 KiB
17Wrong answer6ms3888 KiB
18Wrong answer6ms4020 KiB
19Wrong answer6ms4112 KiB
20Wrong answer6ms4112 KiB
21Wrong answer6ms4244 KiB
22Wrong answer6ms4200 KiB
23Wrong answer6ms4316 KiB
subtask40/60
24Wrong answer3ms2508 KiB
25Wrong answer3ms2816 KiB
26Wrong answer3ms3096 KiB
27Wrong answer3ms3060 KiB
28Wrong answer3ms3396 KiB
29Wrong answer3ms3720 KiB
30Wrong answer3ms3700 KiB
31Wrong answer6ms3888 KiB
32Wrong answer6ms4020 KiB
33Wrong answer6ms4112 KiB
34Wrong answer6ms4112 KiB
35Wrong answer6ms4244 KiB
36Wrong answer6ms4200 KiB
37Wrong answer6ms4316 KiB
38Wrong answer217ms24492 KiB
39Wrong answer212ms25668 KiB
40Wrong answer211ms24772 KiB
41Wrong answer215ms24780 KiB
42Wrong answer211ms25372 KiB
43Wrong answer210ms25912 KiB
44Wrong answer210ms25816 KiB