Submission #935229

#TimeUsernameProblemLanguageResultExecution timeMemory
935229asdasdqwerMatryoshka (JOI16_matryoshka)C++14
100 / 100
436 ms27520 KiB
#include <bits/stdc++.h> using namespace std; #define pii array<int,2> signed main() { int n,q;cin>>n>>q; vector<pii> dolls(n); for (auto &x:dolls) { cin>>x[0]>>x[1]; } sort(dolls.begin(), dolls.end(), [](const pii &x, const pii &y) { if (x[0] != y[0]) return x[0] > y[0]; return x[1] < y[1]; }); vector<pii> quer(q); for (auto &x:quer)cin>>x[0]>>x[1]; vector<pii> srtQuer = quer; sort(srtQuer.begin(), srtQuer.end(), [](const pii &x, const pii &y) { if (x[0] != y[0]) return x[0] < y[0]; return x[1] < y[1]; }); map<pii,int> ans; while (srtQuer.size() && srtQuer.back()[0] > dolls[0][0]) { ans[srtQuer.back()] = 0; srtQuer.pop_back(); } dolls.push_back({-1, -1}); vector<int> lis; for (int i=0;i<n;i++) { auto it = upper_bound(lis.begin(), lis.end(), dolls[i][1]); if (it == lis.end()) { lis.push_back(dolls[i][1]); } else { int dis = (int)distance(lis.begin(), it); lis[dis] = dolls[i][1]; } while (srtQuer.size() && srtQuer.back()[0] > dolls[i+1][0]) { pii qq = srtQuer.back();srtQuer.pop_back(); auto it2 = upper_bound(lis.begin(), lis.end(), qq[1]); ans[qq] = (int)distance(lis.begin(), it2); } } for (auto x:quer) { cout<<ans[x]<<"\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...