이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
const int N=2e5+100;
int a[N],cpy[N],n,x;
long long dp[N];
int suf[N];
int LIS()
{
int ans=0;
for(int i=0;i<=n;i++)
dp[i]=3e9;
dp[0]=-3e9;
for(int i=0;i<n;i++)
dp[lower_bound(dp,dp+n+1,cpy[i])-dp]=cpy[i];
for(int i=0;i<=n;i++)
if(dp[i]!=3e9)
ans=max(ans,i);
return ans;
}
int val[N];
void find_suf()
{
int ans=0;
for(int i=0;i<=n;i++)
{
val[i]=-3e9;
dp[i]=3e9;
}
val[0]=3e9;
dp[0]=-3e9;
suf[n]=0;
for(int i=n-1;i>=0;i--)
{
cpy[i]=-cpy[i];
int xc=lower_bound(dp,dp+n+1,cpy[i])-dp;
val[xc]=max(-cpy[i],val[xc]);// inside if or outside??
if(xc>ans)
{
ans=xc;
}
dp[xc]=cpy[i];
suf[i]=xc;
cpy[i]=-cpy[i];
}
// for(int i=1;i<=n;i++)
// val[i]=min(val[i-1],val[i]);
// for(int i=n-1;i>0;i--)
// val[i]=max(val[i],val[i+1]);
// We LIS of length i we have maximum value of the first element equal to val[i]
// for(int i=0;i<=n;i++)
// {
// cout<<val[i]<<' ';
// }
// cout<<endl;
}
long long dp1[N];
void find_suf1(int tpl)
{
int ans=0;
for(int i=0;i<=n;i++)
{
val[i]=-3e9;
dp1[i]=3e9;
}
val[0]=3e9;
dp1[0]=-3e9;
for(int i=n-1;i>=tpl;i--)
{
cpy[i]=-cpy[i];
int xc=lower_bound(dp1,dp1+n+1,cpy[i])-dp1;
val[xc]=max(-cpy[i],val[xc]);
if(xc>ans)
ans=xc;
dp1[xc]=cpy[i];
cpy[i]=-cpy[i];
}
}
void reset()
{
for(int i=0;i<n;i++)
cpy[i]=a[i];
}
int main()
{
cin>>n>>x;
for(int i=0;i<n;i++)
cin>>a[i];
reset();
int ans=0;
int final=LIS();
for(int i=0;i<=n;i++)
dp[i]=3e9;
dp[0]=-3e9;
for(int i=0;i<n;i++)
{
cpy[i]-=x;
int xc=lower_bound(dp,dp+n+1,cpy[i])-dp;
dp[xc]=cpy[i];
find_suf1(i+1);
int s=0;
int e=n+1;
while(s+1<e)
{
int mid=(s+e)/2;
if(val[mid]>(cpy[i]))
{
s=mid;
}
else
{
e=mid;
}
}
// if(i==3)
// {
// cout<<"st "<<i<<endl;
// cout<<cpy[i]<<endl;
// cout<<"for "<<xc<<' '<<s<<endl;
// for(int j=0;j<=n;j++)
// {
// cout<<dp[j]<<' ';
// }
// cout<<endl;
// }
final=max(final,xc+s);
}
cout<<final<<'\n';
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
glo.cpp: In function 'void find_suf()':
glo.cpp:29:10: warning: overflow in conversion from 'double' to 'int' changes value from '-3.0e+9' to '-2147483648' [-Woverflow]
29 | val[i]=-3e9;
| ^~~~
glo.cpp:32:9: warning: overflow in conversion from 'double' to 'int' changes value from '3.0e+9' to '2147483647' [-Woverflow]
32 | val[0]=3e9;
| ^~~
glo.cpp: In function 'void find_suf1(int)':
glo.cpp:65:10: warning: overflow in conversion from 'double' to 'int' changes value from '-3.0e+9' to '-2147483648' [-Woverflow]
65 | val[i]=-3e9;
| ^~~~
glo.cpp:68:9: warning: overflow in conversion from 'double' to 'int' changes value from '3.0e+9' to '2147483647' [-Woverflow]
68 | val[0]=3e9;
| ^~~
glo.cpp: In function 'int main()':
glo.cpp:92:6: warning: unused variable 'ans' [-Wunused-variable]
92 | int ans=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... |