Submission #1143786

#TimeUsernameProblemLanguageResultExecution timeMemory
1143786DON_FMatryoshka (JOI16_matryoshka)C++20
100 / 100
1513 ms37168 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; #define all(x) x.begin(), x.end() #define L(i, b, e) for (int i = b; i < e; ++i) #define R(i, b, e) for (int i = b; i >= e; --i) #define pb emplace_back #define vi vector<int> #define sz(x) ((int) x.size()) const int N = 2e5 + 7, Mx = 1e9 + 9; int n, q; pair<int, int> s[N]; vi f[N]; vector<pair<int, int>> t[N]; int ans[N]; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> q; vi p; L(i, 0, n){ cin >> s[i].first >> s[i].second; p.pb(s[i].first); } sort(all(p)); p.erase(unique(all(p)), p.end()); map<int, int> c; L(i, 0, sz(p))c[p[i]] = i; L(i, 0, n){ f[c[s[i].first]].pb(s[i].second); } L(i, 0, q){ int a, b; cin >> a >> b; auto it = lower_bound(all(p), a); if (it != p.end()){ t[it - p.begin()].pb(b, i); } } vi a; R(i, sz(p) - 1, 0){ sort(all(f[i])); sort(all(t[i])); deque<int> cur; int k = 0, w = 0, l = 0; t[i].pb(1e9, -1); L(j, 0, sz(t[i])){ while (k < sz(f[i]) && f[i][k] <= t[i][j].first){ cur.pb(f[i][k]); ++k; } while (!cur.empty() && w < sz(a) && a[w] <= t[i][j].first){ if (cur.front() < a[w]){ a[w] = cur.front(); cur.pop_front(); } ++w; } while (l < sz(a) && a[l] <= t[i][j].first)++l; if (t[i][j].second != -1)ans[t[i][j].second] = l + sz(cur); } for (auto &j : cur)a.pb(j); } L(i, 0, q)cout << ans[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...