/**
* author: wxhtzdy
* created: 19.08.2023 16:20:10
**/
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
vector<int> x(q), y(q);
for (int i = 0; i < q; i++) {
cin >> x[i] >> y[i];
}
vector<int> xs;
vector<int> ys;
for (int i = 0; i < n; i++) {
xs.push_back(a[i]);
ys.push_back(b[i]);
}
for (int i = 0; i < q; i++) {
xs.push_back(x[i]);
ys.push_back(y[i]);
}
sort(xs.begin(), xs.end());
sort(ys.begin(), ys.end());
xs.erase(unique(xs.begin(), xs.end()), xs.end());
ys.erase(unique(ys.begin(), ys.end()), ys.end());
for (int i = 0; i < n; i++) {
a[i] = (int) (lower_bound(xs.begin(), xs.end(), a[i]) - xs.begin());
b[i] = (int) (lower_bound(ys.begin(), ys.end(), b[i]) - ys.begin());
}
for (int i = 0; i < q; i++) {
x[i] = (int) (lower_bound(xs.begin(), xs.end(), x[i]) - xs.begin());
y[i] = (int) (lower_bound(ys.begin(), ys.end(), y[i]) - ys.begin());
}
vector<int> order(n);
iota(order.begin(), order.end(), 0);
sort(order.begin(), order.end(), [&](int i, int j) {
if (a[i] == a[j]) {
return b[i] < b[j];
} else {
return a[i] > a[j];
}
});
{
vector<int> new_a(n);
for (int i = 0; i < n; i++) {
new_a[i] = a[order[i]];
}
a = new_a;
}
{
vector<int> new_b(n);
for (int i = 0; i < n; i++) {
new_b[i] = b[order[i]];
}
b = new_b;
}
int sz = (int) ys.size();
vector<int> st(8 * sz);
function<void(int, int, int, int, int, int)> Modify = [&](int x, int l, int r, int ll, int rr, int v) {
if (l > r || l > rr || r < ll || ll > rr) {
return;
}
if (ll <= l && r <= rr) {
st[x] = max(st[x], v);
return;
}
int mid = l + r >> 1;
Modify(x * 2, l, mid, ll, rr, v);
Modify(x * 2 + 1, mid + 1, r, ll, rr, v);
};
function<int(int, int, int, int)> Query = [&](int x, int l, int r, int i) {
if (l == r) {
return st[x];
}
int mid = l + r >> 1;
if (i <= mid) {
return max(Query(x * 2, l, mid, i), st[x]);
} else {
return max(Query(x * 2 + 1, mid + 1, r, i), st[x]);
}
};
vector<vector<int>> qs(n);
for (int i = 0; i < q; i++) {
int low = 0, high = n - 1, pos = 0;
while (low <= high) {
int mid = low + high >> 1;
if (a[mid] >= x[i]) {
pos = mid;
low = mid + 1;
} else {
high = mid - 1;
}
}
if (a[pos] >= x[i]) {
qs[pos].push_back(i);
}
}
vector<int> ans(q);
for (int i = 0; i < n; i++) {
Modify(1, 0, sz - 1, b[i], sz - 1, Query(1, 0, sz - 1, b[i]) + 1);
for (int j : qs[i]) {
ans[j] = Query(1, 0, sz - 1, y[j]);
}
}
for (int i = 0; i < q; i++) {
cout << ans[i] << '\n';
}
return 0;
}
Compilation message
matryoshka.cpp: In lambda function:
matryoshka.cpp:77:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
77 | int mid = l + r >> 1;
| ~~^~~
matryoshka.cpp: In lambda function:
matryoshka.cpp:85:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
85 | int mid = l + r >> 1;
| ~~^~~
matryoshka.cpp: In function 'int main()':
matryoshka.cpp:96:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
96 | int mid = low + high >> 1;
| ~~~~^~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
460 KB |
Output is correct |
6 |
Correct |
0 ms |
600 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
460 KB |
Output is correct |
6 |
Correct |
0 ms |
600 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
460 KB |
Output is correct |
6 |
Correct |
0 ms |
600 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
604 KB |
Output is correct |
23 |
Correct |
3 ms |
804 KB |
Output is correct |
24 |
Correct |
3 ms |
604 KB |
Output is correct |
25 |
Correct |
3 ms |
604 KB |
Output is correct |
26 |
Correct |
3 ms |
796 KB |
Output is correct |
27 |
Correct |
3 ms |
604 KB |
Output is correct |
28 |
Correct |
3 ms |
720 KB |
Output is correct |
29 |
Correct |
3 ms |
600 KB |
Output is correct |
30 |
Correct |
2 ms |
604 KB |
Output is correct |
31 |
Correct |
3 ms |
604 KB |
Output is correct |
32 |
Correct |
3 ms |
604 KB |
Output is correct |
33 |
Correct |
3 ms |
808 KB |
Output is correct |
34 |
Correct |
3 ms |
604 KB |
Output is correct |
35 |
Correct |
3 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
460 KB |
Output is correct |
6 |
Correct |
0 ms |
600 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
604 KB |
Output is correct |
23 |
Correct |
3 ms |
804 KB |
Output is correct |
24 |
Correct |
3 ms |
604 KB |
Output is correct |
25 |
Correct |
3 ms |
604 KB |
Output is correct |
26 |
Correct |
3 ms |
796 KB |
Output is correct |
27 |
Correct |
3 ms |
604 KB |
Output is correct |
28 |
Correct |
3 ms |
720 KB |
Output is correct |
29 |
Correct |
3 ms |
600 KB |
Output is correct |
30 |
Correct |
2 ms |
604 KB |
Output is correct |
31 |
Correct |
3 ms |
604 KB |
Output is correct |
32 |
Correct |
3 ms |
604 KB |
Output is correct |
33 |
Correct |
3 ms |
808 KB |
Output is correct |
34 |
Correct |
3 ms |
604 KB |
Output is correct |
35 |
Correct |
3 ms |
604 KB |
Output is correct |
36 |
Correct |
455 ms |
27100 KB |
Output is correct |
37 |
Correct |
278 ms |
21292 KB |
Output is correct |
38 |
Correct |
142 ms |
13504 KB |
Output is correct |
39 |
Correct |
248 ms |
17580 KB |
Output is correct |
40 |
Correct |
245 ms |
18152 KB |
Output is correct |
41 |
Correct |
321 ms |
21356 KB |
Output is correct |
42 |
Correct |
120 ms |
17036 KB |
Output is correct |
43 |
Correct |
69 ms |
16824 KB |
Output is correct |
44 |
Correct |
474 ms |
37236 KB |
Output is correct |
45 |
Correct |
482 ms |
37180 KB |
Output is correct |
46 |
Correct |
461 ms |
37436 KB |
Output is correct |
47 |
Correct |
474 ms |
36836 KB |
Output is correct |
48 |
Correct |
437 ms |
37172 KB |
Output is correct |
49 |
Correct |
456 ms |
36728 KB |
Output is correct |
50 |
Correct |
445 ms |
37176 KB |
Output is correct |