Submission #1358512

#TimeUsernameProblemLanguageResultExecution timeMemory
1358512vjudge1Matryoshka (JOI16_matryoshka)C++20
11 / 100
0 ms344 KiB
#pragma GCC optimize("O3") 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("tree-vectorize")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long
#define endl '\n'
#define F first
#define S second
#define pii pair<int, int>
#define pic pair<int, char>
#define pci pair<char, int>
#define psi pair<string, int>
#define pis pair<int, string>
#define pipii pair<int, pair<int, int>>
#define piipi pair<pair<int, int>, int>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yes() cout << "YES" << endl
#define no() cout << "NO" << endl
int dx[] = {2, 2, 1, 1, -1, -1, -2, -2};
int dy[] = {1, -1, -2, 2, -2, 2, -1, 1};
const int MOD = 1e9 + 7;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T>
using ordered_multiset = tree<pair<T,int>, null_type, less<pair<T,int>>, rb_tree_tag, tree_order_statistics_node_update>;
signed main() {
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    int n, q;
    cin >> n >> q;
    int a[n + 1], b[n + 1];
    for(int i = 1;i <= n;i++){
        cin >> a[i] >> b[i];
    }
    while(q--){
        int A, B;
        cin >> A >> B;
        vector<pii> vt;
        for(int i = 1;i <= n;i++){
            if(a[i] >= A && b[i] <= B) vt.push_back({a[i], b[i]});
        }
        sort(all(vt));
        int ans = 0;
        for(int i = 0;i < vt.size();i++){
            for(int j = i;j < vt.size();j++){
                if(vt[i].F < vt[j].F && vt[i].S < vt[j].S){
                    ans++;
                    i = j - 1;
                    break;
                }
            }
        }
        cout << vt.size() - ans << endl;
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...