Submission #884952

#TimeUsernameProblemLanguageResultExecution timeMemory
884952aykhnMatryoshka (JOI16_matryoshka)C++17
100 / 100
122 ms18516 KiB
#include <bits/stdc++.h> // author : aykhn using namespace std; typedef long long ll; #define pb push_back #define ins insert #define mpr make_pair #define all(v) v.begin(), v.end() #define bpc __builtin_popcountll #define pii pair<ll, ll> #define pll pair<ll, ll> #define fi first #define se second #define int ll #define infll 0x3F3F3F3F3F3F3F3F #define inf 0x3F3F3F3F const int MXN = 2e5 + 5; int n; array<int, 2> p[MXN]; array<int, 3> q[MXN]; int res[MXN]; signed main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); int Q; cin >> n >> Q; for (int i = 0; i < n; i++) cin >> p[i][0] >> p[i][1]; for (int i = 0; i < Q; i++) cin >> q[i][0] >> q[i][1], q[i][2] = i; sort(p, p + n, [&](const array<int, 2> &a, const array<int, 2> &b) { return (a[0] == b[0] ? a[1] < b[1] : a[0] > b[0]); }); sort(q, q + Q, [&](const array<int, 3> &a, const array<int, 3> &b) { return a[0] > b[0]; }); vector<int> s; int j = 0; for (int i = 0; i < Q; i++) { while (j < n && p[j][0] >= q[i][0]) { auto it = upper_bound(all(s), p[j][1]); if (it == s.end()) s.pb(p[j][1]); else *it = p[j][1]; j++; } res[q[i][2]] = upper_bound(all(s), q[i][1]) - s.begin(); } for (int i = 0; i < Q; i++) cout << res[i] << '\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...