Submission #1156118

#TimeUsernameProblemLanguageResultExecution timeMemory
1156118vladiliusMatryoshka (JOI16_matryoshka)C++20
51 / 100
2092 ms3612 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;
        multiset<int> st;
        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;
                    auto it = st.lower_bound(b[t]);
                    if (it != st.begin()){
                        st.erase(prev(it));
                    }
                }
                for (int t = i; t < j; t++){
                    if (b[t] > r) continue;
                    st.insert(b[t]);
                }
            }
            i = j;
        }
        
        cout<<st.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...