# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1031328 |
2024-07-22T17:32:42 Z |
mychecksedad |
Exam (eJOI20_exam) |
C++17 |
|
146 ms |
102916 KB |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+10, K = 20;
#define pb push_back
#define all(v) v.begin(), v.end()
int n, a[N], b[N], rmq[N][K];
map<int, vector<int>> m;
int subtask2(){
int ans = 0;
vector<bool> is_taken(n + 5, 0);
for(int i = 1; i <= n; i++){
if(a[i] == b[1]){
ans++;
int l = i-1, r = i + 1;
is_taken[i] = 1;
for(; l >= 1 && !is_taken[l] && a[l] < b[1]; l--) ans++, is_taken[l] = 1;
for(; r <= n && !is_taken[r] && a[r] < b[1]; r++) ans++, is_taken[r] = 1;
}
}
return ans;
}
int Q(int l, int r){
int k = __lg((r-l+1));
return max(rmq[l][k], rmq[r - (1<<k) + 1][k]);
}
int subtask4(){
map<int, int> m;
for(int i = 1; i <= n; i++) m[a[i]] = i;
vector<int> dp(n+2), v, lis(1);
for(int i = 1; i <= n; i++){
if(a[i] <= b[i]){
int pos = m[b[i]];
if(pos > 0 && Q(min(i, pos), max(i, pos)) <= b[i]){
v.pb(pos);
}
}
}
for(int i = 0; i < v.size(); i++){
int l = upper_bound(all(lis), v[i]) - lis.begin();
if(l == lis.size()) lis.pb(v[i]);
else{
lis[l] = v[i];
}
}
return int(lis.size())-1;
}
void precalc(){
for(int i = 1; i <= n; i++) rmq[i][0] = a[i];
for(int j = 1; j < K; j++){
for(int i = 1; i + (1<<j) <= n + 1; i++){
rmq[i][j] = max(rmq[i][j - 1], rmq[i + (1<<(j-1))][j - 1]);
}
}
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= n; i++) cin >> b[i];
precalc();
bool is_b = 1;
for(int i = 2; i <= n; i++) if(b[i] != b[i - 1]) is_b = 0;
if(is_b){
cout << subtask2();
return 0;
}
if(n > 5000){
cout << subtask4();
return 0;
}
int ans = 0;
vector<vector<int>> dp(n+2, vector<int>(n+2));
for(int i = 1; i <= n; i++){
int mx = 0;
for(int j = 1; j <= n; j++){
int x = Q(min(i, j), max(i, j));
mx = max(mx, dp[i - 1][j]);
if(x > b[i]){
dp[i][j] = mx;
}else{
if(a[i] <= b[i] && x == b[i]){
dp[i][j] = mx + 1;
}else dp[i][j] = mx;
}
if(i==n) ans=max(ans, dp[i][j]);
}
}
cout << ans;
return 0;
}
Compilation message
exam.cpp: In function 'int subtask4()':
exam.cpp:39:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for(int i = 0; i < v.size(); i++){
| ~~^~~~~~~~~~
exam.cpp:41:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | if(l == lis.size()) lis.pb(v[i]);
| ~~^~~~~~~~~~~~~
# |
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 |
0 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
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 |
4 ms |
4956 KB |
Output is correct |
3 |
Correct |
12 ms |
10080 KB |
Output is correct |
4 |
Correct |
10 ms |
9304 KB |
Output is correct |
5 |
Correct |
17 ms |
10868 KB |
Output is correct |
6 |
Correct |
11 ms |
9304 KB |
Output is correct |
7 |
Correct |
11 ms |
9488 KB |
Output is correct |
8 |
Correct |
17 ms |
10688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
2 ms |
3420 KB |
Output is correct |
3 |
Correct |
22 ms |
18320 KB |
Output is correct |
4 |
Correct |
129 ms |
95172 KB |
Output is correct |
5 |
Correct |
134 ms |
102784 KB |
Output is correct |
6 |
Correct |
138 ms |
102740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
24 ms |
9412 KB |
Output is correct |
3 |
Correct |
50 ms |
15124 KB |
Output is correct |
4 |
Correct |
51 ms |
15700 KB |
Output is correct |
5 |
Correct |
56 ms |
16592 KB |
Output is correct |
6 |
Correct |
50 ms |
15792 KB |
Output is correct |
7 |
Correct |
48 ms |
16208 KB |
Output is correct |
8 |
Correct |
57 ms |
15220 KB |
Output is correct |
9 |
Correct |
63 ms |
15824 KB |
Output is correct |
10 |
Correct |
46 ms |
15848 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 |
0 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 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 |
2512 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
1 ms |
2652 KB |
Output is correct |
13 |
Correct |
1 ms |
2652 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 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 |
0 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
2 ms |
3420 KB |
Output is correct |
9 |
Correct |
22 ms |
18320 KB |
Output is correct |
10 |
Correct |
129 ms |
95172 KB |
Output is correct |
11 |
Correct |
134 ms |
102784 KB |
Output is correct |
12 |
Correct |
138 ms |
102740 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2512 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
17 |
Correct |
1 ms |
2652 KB |
Output is correct |
18 |
Correct |
1 ms |
2652 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
6 ms |
6492 KB |
Output is correct |
23 |
Correct |
1 ms |
4700 KB |
Output is correct |
24 |
Correct |
146 ms |
102808 KB |
Output is correct |
25 |
Correct |
143 ms |
102916 KB |
Output is correct |
26 |
Correct |
137 ms |
102740 KB |
Output is correct |
27 |
Correct |
127 ms |
102736 KB |
Output is correct |
28 |
Correct |
120 ms |
102916 KB |
Output is correct |
29 |
Correct |
136 ms |
102740 KB |
Output is correct |
30 |
Correct |
138 ms |
102736 KB |
Output is correct |
31 |
Correct |
134 ms |
102616 KB |
Output is correct |
32 |
Correct |
132 ms |
102744 KB |
Output is correct |