#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cstring>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair <int, int>
#define ull unsigned long long
// #define int long long
// #define int unsigned long long
const ll inf = 1e9 + 7;
const ll weirdMod = 998244353;
map<int, int> mp; int rnk = 0;
int pref[5001][10000], dp[5001];
void solve() {
int n;
cin >> n;
if (n > 5000) {
int a[n + 1], b[n + 1];
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++)
cin >> b[i];
int mx = -1, l = 1, ans = 0;
for (int i = 1; i < n; i++) {
if (max(mx, a[i]) > b[1]) {
if (mx == b[1]) ans += (i - l); mx = -1; l = i + 1;
} else mx = max(mx, a[i]);
} cout << ans;
return;
}
set<int> st;
int a[n + 1], b[n + 1];
for (int i = 1; i <= n; i++) {
cin >> a[i]; st.insert(a[i]);
} for (int i = 1; i <= n; i++) {
cin >> b[i]; st.insert(b[i]);
} for (int v : st) mp[v] = rnk++;
for (int i = 1; i <= n; i++) {
a[i] = mp[a[i]]; b[i] = mp[b[i]];
for (int j = 0; j < 10000; j++) {
pref[i][j] = pref[i - 1][j];
} pref[i][b[i]]++;
} for (int j = 1; j <= n; j++) {
int mx = -1;
for (int i = j; i >= 1; i--) {
mx = max(mx, a[i]);
dp[j] = max(dp[j], dp[i - 1] + pref[j][mx] - pref[i - 1][mx]);
}
} int mx = 0;
for (int i = 1; i <= n; i++)
cout << dp[i] << ' ';
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
cout << '\n';
}
return 0;
}
Compilation message
exam.cpp: In function 'void solve()':
exam.cpp:40:17: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
40 | if (mx == b[1]) ans += (i - l); mx = -1; l = i + 1;
| ^~
exam.cpp:40:49: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
40 | if (mx == b[1]) ans += (i - l); mx = -1; l = i + 1;
| ^~
exam.cpp:63:11: warning: unused variable 'mx' [-Wunused-variable]
63 | } int mx = 0;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
19 ms |
39380 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |