# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
516832 |
2022-01-22T07:23:04 Z |
nickyrio |
Exam (eJOI20_exam) |
C++17 |
|
106 ms |
14480 KB |
#include <bits/stdc++.h>
using namespace std;
#define all(s) s.begin(), s.end()
const int N = 1e5 + 100;
const int LG = 17;
int a[N], b[N], n, L[N], R[N];
vector<int> e[N];
int BIT[N], RMQ[LG][N], lg2[N];
int query(int u) {
int ans = 0;
for(; u > 0; u -= u & -u) ans = max(ans, BIT[u]);
return ans;
}
void update(int u, int v) {
for (; u < N; u += u & -u) BIT[u] = max(BIT[u], v);
}
void sub2() {
for (int i = 2; i <= n; ++i) if (b[i] != b[1]) return;
int cnt = 0;
for (int i = 1; i <= n; ++i) if (a[i] == b[1]) {
for (int j = i - 1; a[j] < a[i]; --j) a[j] = a[i];
for (int j = i + 1; a[j] < a[i]; ++j) a[j] = a[i];
}
for (int i = 1; i <= n; ++i) if (a[i] == b[1]) ++cnt;
cout << cnt << '\n';
exit(0);
}
int main() {
ios::sync_with_stdio(false); cin.tie(NULL);
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 1; i <= n; ++i) cin >> b[i];
a[0] = a[n + 1] = 2e9;
sub2();
vector<int> Ranking(a + 1, a + n + 1);
sort(all(Ranking));
Ranking.resize(unique(all(Ranking)) - Ranking.begin());
for (int i = 1; i <= n; ++i) {
a[i] = lower_bound(all(Ranking), a[i]) - Ranking.begin();
int temp_b = lower_bound(all(Ranking), b[i]) - Ranking.begin();
if (temp_b != Ranking.size() && Ranking[temp_b] != b[i]) temp_b = Ranking.size();
b[i] = temp_b;
e[b[i]].push_back(i);
}
for (int i = 1; i <= n; ++i) RMQ[0][i] = a[i];
for (int i = 2; i <= n; ++i) lg2[i] = lg2[i >> 1] + 1;
for (int j = 1; j < LG; ++j) {
for (int i = 1; i + (1 << j) - 1 <= n; ++i) {
RMQ[j][i] = max(RMQ[j - 1][i], RMQ[j - 1][i + (1 << (j - 1))]);
}
}
auto getMAX = [&](int l, int r) {
int d = lg2[r - l + 1];
return max(RMQ[d][l], RMQ[d][r - (1 << d) + 1]);
};
int ans = 0;
for (int i = 1; i <= n; ++i) {
int best = 0;
for (int j : e[a[i]]) {
int l = j, r = i;
if (l > r) swap(l, r);
if (getMAX(l, r) > a[i]) continue;
best = max(best, query(j - 1)) + 1;
update(j, best);
ans = max(ans, best);
}
}
cout << ans << '\n';
}
Compilation message
exam.cpp: In function 'int main()':
exam.cpp:46:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | if (temp_b != Ranking.size() && Ranking[temp_b] != b[i]) temp_b = Ranking.size();
| ~~~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
1 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2684 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
1 ms |
2636 KB |
Output is correct |
6 |
Correct |
1 ms |
2636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
5 ms |
2764 KB |
Output is correct |
3 |
Correct |
16 ms |
3268 KB |
Output is correct |
4 |
Correct |
11 ms |
3460 KB |
Output is correct |
5 |
Correct |
23 ms |
3412 KB |
Output is correct |
6 |
Correct |
11 ms |
3404 KB |
Output is correct |
7 |
Correct |
11 ms |
3404 KB |
Output is correct |
8 |
Correct |
20 ms |
3372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2764 KB |
Output is correct |
3 |
Correct |
2 ms |
2892 KB |
Output is correct |
4 |
Correct |
4 ms |
3096 KB |
Output is correct |
5 |
Correct |
4 ms |
3128 KB |
Output is correct |
6 |
Correct |
4 ms |
3204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3148 KB |
Output is correct |
2 |
Correct |
24 ms |
7020 KB |
Output is correct |
3 |
Correct |
64 ms |
13700 KB |
Output is correct |
4 |
Correct |
75 ms |
14480 KB |
Output is correct |
5 |
Correct |
70 ms |
14308 KB |
Output is correct |
6 |
Correct |
56 ms |
13508 KB |
Output is correct |
7 |
Correct |
71 ms |
14324 KB |
Output is correct |
8 |
Correct |
62 ms |
13448 KB |
Output is correct |
9 |
Correct |
73 ms |
13968 KB |
Output is correct |
10 |
Correct |
57 ms |
13884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
1 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2684 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
1 ms |
2636 KB |
Output is correct |
6 |
Correct |
1 ms |
2636 KB |
Output is correct |
7 |
Correct |
2 ms |
2708 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
9 |
Correct |
1 ms |
2636 KB |
Output is correct |
10 |
Correct |
2 ms |
2764 KB |
Output is correct |
11 |
Correct |
1 ms |
2764 KB |
Output is correct |
12 |
Correct |
2 ms |
2764 KB |
Output is correct |
13 |
Correct |
2 ms |
2764 KB |
Output is correct |
14 |
Correct |
2 ms |
2636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
1 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2684 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
1 ms |
2636 KB |
Output is correct |
6 |
Correct |
1 ms |
2636 KB |
Output is correct |
7 |
Correct |
1 ms |
2636 KB |
Output is correct |
8 |
Correct |
2 ms |
2764 KB |
Output is correct |
9 |
Correct |
2 ms |
2892 KB |
Output is correct |
10 |
Correct |
4 ms |
3096 KB |
Output is correct |
11 |
Correct |
4 ms |
3128 KB |
Output is correct |
12 |
Correct |
4 ms |
3204 KB |
Output is correct |
13 |
Correct |
2 ms |
2708 KB |
Output is correct |
14 |
Correct |
2 ms |
2636 KB |
Output is correct |
15 |
Correct |
1 ms |
2636 KB |
Output is correct |
16 |
Correct |
2 ms |
2764 KB |
Output is correct |
17 |
Correct |
1 ms |
2764 KB |
Output is correct |
18 |
Correct |
2 ms |
2764 KB |
Output is correct |
19 |
Correct |
2 ms |
2764 KB |
Output is correct |
20 |
Correct |
2 ms |
2636 KB |
Output is correct |
21 |
Correct |
2 ms |
2764 KB |
Output is correct |
22 |
Correct |
2 ms |
2764 KB |
Output is correct |
23 |
Correct |
4 ms |
2636 KB |
Output is correct |
24 |
Correct |
106 ms |
3020 KB |
Output is correct |
25 |
Correct |
8 ms |
3148 KB |
Output is correct |
26 |
Correct |
3 ms |
3148 KB |
Output is correct |
27 |
Correct |
7 ms |
3148 KB |
Output is correct |
28 |
Correct |
4 ms |
3092 KB |
Output is correct |
29 |
Correct |
4 ms |
3148 KB |
Output is correct |
30 |
Correct |
4 ms |
3148 KB |
Output is correct |
31 |
Correct |
4 ms |
3148 KB |
Output is correct |
32 |
Correct |
4 ms |
3148 KB |
Output is correct |