이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ioss ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
int n, x;
int arr[200004], dp[200004];
signed main() {
ioss;
cin >> n >> x;
for(int i = 0; i < n; i++) cin >> arr[i];
if(x == 0) {
vector<int> tmp;
for(int i = 0; i < n; i++) {
if(i == 0) {
dp[i] = 1;
tmp.pb(arr[i]);
continue;
}
if(arr[i] > tmp.back()) dp[i] = dp[i-1]+1, tmp.pb(arr[i]);
else {
int cur = lower_bound(tmp.begin(), tmp.end(), arr[i])-tmp.begin();
tmp[cur] = arr[i];
dp[i] = dp[i-1];
// for(auto x : tmp) cout << x << " ";
// cout << endl;
}
// cout << " :: " << arr[i] << " " << tmp.back() << " " << dp[i] << endl;
}
cout << dp[n-1] << endl;
return 0;
}
vector<pii> range;
int maxx[n+2][n+2] = {};
for(int j = 0; j < n; j++) {
int tmp = arr[j];
for(int k = j; k < n; k++) {
range.pb({j, k});
tmp = max(tmp, arr[k]);
maxx[j][k] = tmp;
}
}
int ans = 0;
for(auto [l, r] : range) {
// cout << l << " " << r << endl;
vector<int> tmp;
memset(dp, 0, sizeof(dp));
for(int i = 0; i < n; i++) {
if(i >= l && i <= r && maxx[l][r] <= x) arr[i] -= maxx[l][r];
if(i == 0) {
dp[i] = 1;
tmp.pb(arr[i]);
if(i >= l && i <= r && maxx[l][r] <= x) arr[i] += maxx[l][r];
continue;
}
if(arr[i] > tmp.back()) dp[i] = dp[i-1]+1, tmp.pb(arr[i]);
else {
int cur = lower_bound(tmp.begin(), tmp.end(), arr[i])-tmp.begin();
tmp[cur] = arr[i];
dp[i] = dp[i-1];
// for(auto x : tmp) cout << x << " ";
// cout << endl;
}
if(i >= l && i <= r && maxx[l][r] <= x) arr[i] += maxx[l][r];
}
ans = max(ans, dp[n-1]);
// cout << " :: " << l << " " << r << " " << maxx[l][r] << " " << dp[n-1] << endl;
}
for(auto [l, r] : range) {
// cout << l << " " << r << endl;
vector<int> tmp;
memset(dp, 0, sizeof(dp));
for(int i = 0; i < n; i++) {
if(i >= l && i <= r && maxx[l][r] <= x) arr[i] += maxx[l][r];
if(i == 0) {
dp[i] = 1;
tmp.pb(arr[i]);
if(i >= l && i <= r && maxx[l][r] <= x) arr[i] -= maxx[l][r];
continue;
}
if(arr[i] > tmp.back()) dp[i] = dp[i-1]+1, tmp.pb(arr[i]);
else {
int cur = lower_bound(tmp.begin(), tmp.end(), arr[i])-tmp.begin();
tmp[cur] = arr[i];
dp[i] = dp[i-1];
// for(auto x : tmp) cout << x << " ";
// cout << endl;
}
if(i >= l && i <= r && maxx[l][r] <= x) arr[i] -= maxx[l][r];
}
ans = max(ans, dp[n-1]);
// cout << " :: " << l << " " << r << " " << maxx[l][r] << " " << dp[n-1] << endl;
}
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |