This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |