Submission #1358519

#TimeUsernameProblemLanguageResultExecution timeMemory
1358519vjudge1Matryoshka (JOI16_matryoshka)C++17
51 / 100
2085 ms12996 KiB
#include <bits/stdc++.h>

#define int long long
using namespace std;

const int N = 3e6 + 5, mod = 1e9 + 7, inf = 1e18;

void solve() {
    int n, q;
    cin >> n >> q;

    vector<pair<int, int>> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i].first >> a[i].second;
    
    sort(a.begin(), a.end());
    
    while (q--) {
        int qa, qb;
        cin >> qa >> qb;
        vector<pair<int, int>> v;
        set<int> st1;
        for (int i = 0; i < n; i++) {

            if (a[i].first >= qa && a[i].second <= qb) {
                v.push_back({a[i].first, a[i].second});
                st1.insert(a[i].first);
            }
            
        }
        int m = v.size();
        int cnt = 0;
        multiset<int> st;
        int id = 0;
        for (auto &i : st1) {
            vector<int> d;
            while (id != m && v[id].first == i) {
                int x = v[id].second;
                if (st.size() == 0) {
                    id++;
                    d.push_back(x);
                    continue;
                }
                if (x <= *st.begin())
                    d.push_back(x);
                else {
                    st.erase(--st.lower_bound(x));
                    d.push_back(x);
                }
                id++;
            }

            for (int &x : d) 
                st.insert(x);
            

        }
        cout << st.size() << '\n';
    }
}

signed main() {

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
    // cin >> t;

    while (t--) {
        solve();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...