# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1052588 |
2024-08-10T17:11:07 Z |
juicy |
None (JOI16_matryoshka) |
C++17 |
|
148 ms |
17604 KB |
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 2e5 + 5;
int n, q;
int ft[N], dp[N], res[N];
array<int, 2> pt[N];
void upd(int i, int x) {
for (; i <= n; i += i & -i) {
ft[i] = max(ft[i], x);
}
}
int qry(int i) {
int res = 0;
for (; i; i -= i & -i) {
res = max(res, ft[i]);
}
return res;
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> q;
vector<int> comp;
for (int i = 1; i <= n; ++i) {
cin >> pt[i][0] >> pt[i][1];
comp.push_back(pt[i][1]);
}
sort(pt + 1, pt + n + 1, [&](const auto &a, const auto &b) {
return a[0] == b[0] ? a[1] < b[1] : a[0] > b[0];
});
sort(comp.begin(), comp.end());
comp.erase(unique(comp.begin(), comp.end()), comp.end());
for (int i = 1; i <= n; ++i) {
pt[i][1] = lower_bound(comp.begin(), comp.end(), pt[i][1]) - comp.begin() + 1;
dp[i] = qry(pt[i][1]) + 1;
upd(pt[i][1], dp[i]);
}
vector<array<int, 3>> queries;
for (int i = 1; i <= q; ++i) {
int a, b; cin >> a >> b;
queries.push_back({a, b, i});
}
sort(queries.begin(), queries.end(), [&](const auto &a, const auto &b) {
return a[0] == b[0] ? a[1] < b[1] : a[0] > b[0];
});
fill(ft + 1, ft + n + 1, 0);
for (int i = 0, j = 1; i < q; ++i) {
while (j <= n && pt[j][0] >= queries[i][0]) {
upd(pt[j][1], dp[j]);
++j;
}
int k = upper_bound(comp.begin(), comp.end(), queries[i][1]) - comp.begin();
res[queries[i][2]] = qry(k);
}
for (int i = 1; i <= q; ++i) {
cout << res[i] << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
0 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
0 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
2 ms |
2904 KB |
Output is correct |
24 |
Correct |
2 ms |
2628 KB |
Output is correct |
25 |
Correct |
1 ms |
2652 KB |
Output is correct |
26 |
Correct |
2 ms |
2652 KB |
Output is correct |
27 |
Correct |
2 ms |
2652 KB |
Output is correct |
28 |
Correct |
2 ms |
2652 KB |
Output is correct |
29 |
Correct |
1 ms |
2652 KB |
Output is correct |
30 |
Correct |
1 ms |
2652 KB |
Output is correct |
31 |
Correct |
2 ms |
2652 KB |
Output is correct |
32 |
Correct |
1 ms |
2660 KB |
Output is correct |
33 |
Correct |
1 ms |
2652 KB |
Output is correct |
34 |
Correct |
1 ms |
2652 KB |
Output is correct |
35 |
Correct |
1 ms |
2532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
0 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
2 ms |
2904 KB |
Output is correct |
24 |
Correct |
2 ms |
2628 KB |
Output is correct |
25 |
Correct |
1 ms |
2652 KB |
Output is correct |
26 |
Correct |
2 ms |
2652 KB |
Output is correct |
27 |
Correct |
2 ms |
2652 KB |
Output is correct |
28 |
Correct |
2 ms |
2652 KB |
Output is correct |
29 |
Correct |
1 ms |
2652 KB |
Output is correct |
30 |
Correct |
1 ms |
2652 KB |
Output is correct |
31 |
Correct |
2 ms |
2652 KB |
Output is correct |
32 |
Correct |
1 ms |
2660 KB |
Output is correct |
33 |
Correct |
1 ms |
2652 KB |
Output is correct |
34 |
Correct |
1 ms |
2652 KB |
Output is correct |
35 |
Correct |
1 ms |
2532 KB |
Output is correct |
36 |
Correct |
131 ms |
14248 KB |
Output is correct |
37 |
Correct |
95 ms |
13496 KB |
Output is correct |
38 |
Correct |
47 ms |
7380 KB |
Output is correct |
39 |
Correct |
84 ms |
11796 KB |
Output is correct |
40 |
Correct |
86 ms |
12996 KB |
Output is correct |
41 |
Correct |
106 ms |
13252 KB |
Output is correct |
42 |
Correct |
63 ms |
11008 KB |
Output is correct |
43 |
Correct |
50 ms |
11208 KB |
Output is correct |
44 |
Correct |
142 ms |
16572 KB |
Output is correct |
45 |
Correct |
148 ms |
16572 KB |
Output is correct |
46 |
Correct |
138 ms |
16572 KB |
Output is correct |
47 |
Correct |
131 ms |
16396 KB |
Output is correct |
48 |
Correct |
136 ms |
16868 KB |
Output is correct |
49 |
Correct |
129 ms |
16684 KB |
Output is correct |
50 |
Correct |
131 ms |
17604 KB |
Output is correct |