이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
/*
A suffix as the interval is not optimal
ST3: Calc LIS and range for every interval by getting longest LIS for ending
LIS with std::map tracking
ST4 (LIS): calculate the LIS normally with std::map; O(n log n)
ST5: calculate LIS but 3 states based on whether in interval or not; O(nxlog n)
ST6: arbitrary distance
Change one number at a time; this will change
Only two transition differences can be affected by the shift
*/
int n,x;
int main(){
std::cin>>n>>x;
std::vector<int> vec;
for(int i=0;i<n;i++){
int t;
std::cin>>t;
vec.push_back(t);
}
if(x==0){
std::vector<int> swlis(n+1,1000000001);
int lis=0;
for(int i=0;i<n;i++){
int slis=std::lower_bound(swlis.begin(),swlis.end(),vec[i])-swlis.begin();//first slot not less than
//std::cout<<slis<<'\n';
lis=std::max(lis,slis);
swlis[slis]=vec[i];
}
std::cout<<lis+1<<'\n';
}
//*
if(n*x<2000000){
int lis=0;
for(int l=-x;l<=x;l++){
std::vector<std::vector<int>> vals(3,std::vector<int>(n,0));
std::vector<std::vector<int>> rlis(3,std::vector<int>(n,1000000001));//minimum value with a LIS of (number) (or less?)
for(int i=0;i<n;i++){
int cur=vec[i];
int lb=std::lower_bound(rlis[0].begin(),rlis[0].end(),cur)-rlis[0].begin();
int lb2_1=std::lower_bound(rlis[0].begin(),rlis[0].end(),cur+l)-rlis[0].begin();
int lb2_2=std::lower_bound(rlis[1].begin(),rlis[1].end(),cur)-rlis[1].begin();
int lb3_1=std::lower_bound(rlis[1].begin(),rlis[1].end(),cur-l)-rlis[1].begin();
int lb3_2=std::lower_bound(rlis[2].begin(),rlis[2].end(),cur)-rlis[2].begin();
vals[0][i]=lb;
rlis[0][vals[0][i]]=cur;
vals[1][i]=std::max(lb2_1,lb2_2)%n;
rlis[1][vals[1][i]]=cur;
vals[2][i]=std::max(lb3_1,lb3_2)%n;
rlis[2][vals[2][i]]=cur;
lis=std::max(lis,vals[0][i]);
lis=std::max(lis,vals[1][i]);
lis=std::max(lis,vals[2][i]);
}
}
std::cout<<lis+1<<'\n';
}
//*/
}
# | 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... |