Submission #1156117

#TimeUsernameProblemLanguageResultExecution timeMemory
1156117vladiliusMatryoshka (JOI16_matryoshka)C++20
11 / 100
1 ms328 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n, q; cin>>n>>q;
    vector<pii> all = {{}};
    for (int i = 1; i <= n; i++){
        int x, y; cin>>x>>y;
        all.pb({x, y});
    }
    sort(all.begin() + 1, all.end());
    vector<int> a(n + 1), b(n + 1);
    for (int i = 1; i <= n; i++){
        a[i] = all[i].ff; b[i] = all[i].ss;
    }
    while (q--){
        int l, r; cin>>l>>r;
        priority_queue<int, vector<int>, greater<int>> pq;
        int i = 1;
        while (i <= n){
            int j = i;
            while (j <= n && a[i] == a[j]){
                j++;
            }
            
            if (l <= a[i]){
                for (int t = i; t < j; t++){
                    if (b[t] > r) continue;
                    if (!pq.empty()){
                        int f = pq.top();
                        if (f < b[t]){
                            pq.pop();
                        }
                    }
                }
                for (int t = i; t < j; t++){
                    if (b[t] > r) continue;
                    pq.push(b[t]);
                }
            }
            i = j;
        }
        
        cout<<pq.size()<<"\n";
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...