Submission #1257012

#TimeUsernameProblemLanguageResultExecution timeMemory
1257012iamhereforfunMatryoshka (JOI16_matryoshka)C++20
100 / 100
102 ms8116 KiB
// Starcraft 2 enjoyer + luv kd //

#include <bits/stdc++.h>

using namespace std;

#define LSOne(X) ((X) & -(X))

const int N = 2e5 + 5;
const int M = 4e5 + 5;
const int S = 640;
const int O = 2e5 + 5;
const int K = 15;
const int LG = 21;
const int P = 37;
const int INF = 1e9 + 5;
const int MOD = 998244353;
const int nx[] = {0, 1, 0, -1}, ny[] = {1, 0, -1, 0};

int n, q, ans[N];
pair<int, int> doll[N];
array<int, 3> query[N];

void solve()
{
    cin >> n >> q;
    for(int x = 0; x < n; x++)
    {
        int a, b; cin >> a >> b;
        doll[x] = {a, -b};
    }
    for(int x = 0; x < q; x++)
    {
        int a, b; cin >> a >> b;
        query[x] = {a, -b, x};
    }
    sort(doll, doll + n);
    reverse(doll, doll + n);
    sort(query, query + n);
    reverse(query, query + n);
    vector<pair<int, int>> dp;
    for(int x = 0, y = 0; x < q; x++)
    {
        while(y < n && query[x][0] <= doll[y].first)
        {
            auto it = upper_bound(dp.begin(), dp.end(), make_pair(-doll[y].second, INF));
            if(it == dp.end()) dp.push_back({-doll[y].second, doll[y].first});
            else dp[it - dp.begin()] = {-doll[y].second, doll[y].first};
            y++;
        }
        ans[query[x][2]] = upper_bound(dp.begin(), dp.end(), make_pair(-query[x][1], INF)) - dp.begin();
    }
    for(int x = 0; x < q; x++)
    {
        cout << ans[x] << "\n";
    }
}

signed main()
{
    // freopen("CP.INP", "r", stdin);
    // freopen("CP.OUT", "w", stdout);
    // freopen("art2.in", "r", stdin);
    // freopen("art2.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    for (int x = 1; x <= t; x++)
    {
        solve();
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...