제출 #1358916

#제출 시각아이디문제언어결과실행 시간메모리
1358916aylaMatryoshka (JOI16_matryoshka)C++20
51 / 100
2093 ms10560 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<long long, long long>
#define endl '\n'
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define test cout << "yep ";
const int MAX = 1e3 + 5;
const int INF = 8e17;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
bool comp(pair<int, int>a, pair<int, int>b){
    if(a.first == b.first){
        return a.second > b.second;
    }
    return a.first < b.first;
}

signed main(){
    IOS;
    //my code goes here:
    int n, q;
    cin >> n >> q;
    vector<pii>vt;
    for(int i = 1; i <= n; i++){
        int x, y;
        cin >> x >> y;
        vt.push_back({x, y});
    }
    while(q--){
        int a, b;
        cin >> a >> b;
        vector<pii>v;
        for(auto [l, r] : vt){
            if(l >= a && r <= b){
                v.push_back({l, r});
            }
        }
        if(v.size() == 0){
            cout << 0 << endl;
            continue;
        }
        
        sort(v.begin(), v.end(), comp);
        multiset<int>st;
        for(auto [l, r] : v){
            if(st.size() == 0){
                st.insert(r);
                continue;
            }

            auto it = st.lower_bound(r);
            if(it == st.begin()){
                st.insert(r);
            }
            else{
                it--;
                st.erase(it);
                st.insert(r);
            }
        }
        cout << st.size() << endl;
    }
}


#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…