Submission #1143779

#TimeUsernameProblemLanguageResultExecution timeMemory
1143779DON_FMatryoshka (JOI16_matryoshka)C++20
0 / 100
0 ms320 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; int ans[N]; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> q; map<int, vi> f; vi p; L(i, 0, n){ int a, b; cin >> a >> b; f[a].pb(b); p.pb(a); } sort(all(p)); p.erase(unique(all(p))); map<int, vector<pair<int, int>>> t; L(i, 0, q){ int a, b; cin >> a >> b; auto it = lower_bound(all(p), a); if (it != p.end()){ t[*it].pb(b, i); } } vi a; R(i, sz(p) - 1, 0){ sort(all(f[p[i]])); sort(all(t[p[i]])); deque<int> cur; int k = 0, w = 0, l = 0; t[p[i]].pb(1e9, -1); L(j, 0, sz(t[p[i]])){ while (k < sz(f[p[i]]) && f[p[i]][k] <= t[p[i]][j].first){ cur.pb(f[p[i]][k]); ++k; } while (!cur.empty() && w < sz(a) && a[w] <= t[p[i]][j].first){ if (cur.front() < a[w]){ a[w] = cur.front(); cur.pop_front(); } ++w; } while (l < sz(a) && a[l] <= t[p[i]][j].first)++l; if (t[p[i]][j].second != -1)ans[t[p[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...