이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
using I=int;
using B=bool;
const I N=200000;
I t_arr[N];
multiset<I>liss[N+1];
vector<pair<I,I>>adds;
vector<I>dp1;
vector<I>dp2;
I n,x;
void cmb(I& a,I b){
a=max(a,b);
}
void add(I len,I las){
liss[len].insert(las);
adds.push_back({len,las});
}
void rem(){
auto[len,las]=adds.back();
adds.pop_back();
liss[len].erase(liss[len].find(las));
}
B chk(I i,I las){
return liss[i].lower_bound(las-x-1)!=liss[i].upper_bound(las+x-1);
}
I fnd(I las){
I l=0,r=n;
while(l<r){
I m=l+(r-l+1)/2;
if(chk(m,las))l=m;
else r=m-1;
}
return r;
}
I main(){
cin.tie(0)->sync_with_stdio(0);
cin>>n>>x;
for(I i=0;i<n;i++)cin>>t_arr[i];
for(I i=0;i<n;i++){
I t=t_arr[i];
auto it=lower_bound(dp1.begin(),dp1.end(),t);
I len;
if(it==dp1.end())dp1.push_back(t),len=dp1.size();
else len=it-dp1.begin()+1,*it=t;
add(len,t);
}
I res=0;
for(I i=n-1;i>=0;i--){
I t=t_arr[i];
auto it=lower_bound(dp2.begin(),dp2.end(),t,greater<I>());
I len;
if(it==dp2.end())dp2.push_back(t),len=dp2.size();
else len=it-dp2.begin()+1,*it=t;
rem(),res=max(res,fnd(t)+len);
}
printf("%i\n",res);
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... |