이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define FOR(i, l, r, d) for(int i=(l); i<=(r); i+=(d))
#define szof(x) ((int)(x).size())
#define vi vector<int>
#define pii pair<int, int>
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define mkp make_pair
const int INF = 2147483647;
const int LNF = INF*INF;
const int MOD = 1000000007;
const int mod = 998244353;
const double eps = 1e-12;
const int MAX = 200010;
int n, x;
int arr[MAX][3];
int dp[MAX][3];
vi qu[3];
void modify(int i, int j, int k){
int pos = dp[i][j] - 1;
assert(pos <= szof(qu[k]));
if(pos == szof(qu[k])){
qu[k].pb(arr[i][j]);
}
else{
qu[k][pos] = min(qu[k][pos], arr[i][j]);
}
}
int query(int j, int T){
/// find max{dp[i][j]} s.t. arr[i] < T
if(qu[j].empty()){
return 0;
}
if(T <= qu[j][0]){
return 0;
}
int L = 0, R = szof(qu[j]) - 1, mid;
while(L < R){
mid = (L + R + 1) / 2;
if(T > qu[j][mid]){
L = mid;
}
else{
R = mid - 1;
}
}
/// qu[i] : dp = i + 1
return L + 1;
}
int solve(int d){
//cerr<<"solve("<<d<<") : "<<endl;
/// init
FOR(j, 0, 2, 1){
qu[j].clear();
}
FOR(i, 1, n, 1){
arr[i][1] = arr[i][0] + d;
}
/// dp
FOR(i, 1, n, 1){
FOR(j, 0, 2, 1){
dp[i][j] = query(j, arr[i][j]) + 1;
//cerr<<"dp["<<i<<"]["<<j<<"] = "<<dp[i][j]<<"\t";
}
//cerr<<endl;
FOR(j, 0, 2, 1){
FOR(k, 0, j, 1){
modify(i, k, j);
}
/*
cerr<<"qu["<<j<<"] : ";
for(int i : qu[j]){
cerr<<i<<" ";
}
cerr<<endl;
*/
}
}
int ret = 0;
FOR(i, 1, n, 1){
FOR(j, 0, 2, 1){
ret = max(ret, dp[i][j]);
}
}
return ret;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>x;
FOR(i, 1, n, 1){
cin>>arr[i][0];
arr[i][2] = arr[i][0];
}
int res = 0;
FOR(d, -x, x, 1){
res = max(res, solve(d));
}
cout<<res<<'\n';
return 0;
}
# | 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... |