Submission #999548

#TimeUsernameProblemLanguageResultExecution timeMemory
999548gmroh06Matryoshka (JOI16_matryoshka)C++14
100 / 100
114 ms18776 KiB
#import <bits/stdc++.h> using namespace std; using ll = long long; inline void init() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } int main() { init(); ll n, q; cin >> n >> q; vector<pair<ll, ll>> v(n); vector<tuple<ll, ll, ll>> query(q); for (auto& [a, b] : v) { cin >> a >> b; b *= -1; } sort(v.rbegin(), v.rend()); for (ll i = 0, a, b; i < q; i++) { cin >> a >> b; query[i] = tie(a, b, i); } sort(query.rbegin(), query.rend()); vector<ll> ans(q); vector<ll> dp; auto it = v.begin(); for (auto& [a, b, idx] : query) { for (; it < v.end() and a <= it -> first; it++) { auto s = upper_bound(dp.begin(), dp.end(), -it -> second); if (s == dp.end()) { dp.emplace_back(-it -> second); } else { *s = -it -> second; } } ans[idx] = upper_bound(dp.begin(), dp.end(), b) - dp.begin(); } for (auto& x : ans) { cout << x << '\n'; } return 0; }

Compilation message (stderr)

matryoshka.cpp:1:2: warning: #import is a deprecated GCC extension [-Wdeprecated]
    1 | #import <bits/stdc++.h>
      |  ^~~~~~
matryoshka.cpp: In function 'int main()':
matryoshka.cpp:22:16: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   22 |     for (auto& [a, b] : v) {
      |                ^
matryoshka.cpp:40:16: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   40 |     for (auto& [a, b, idx] : query) {
      |                ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...