이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define fr first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
#define USING_ORDERED_SET 0
#if USING_ORDERED_SET
#include<bits/extc++.h>
using namespace __gnu_pbds;
template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
#endif
template<class T>void umax(T &a,T b){if(a<b)a=b;}
template<class T>void umin(T &a,T b){if(b<a)a=b;}
#ifdef juggernaut
#define printl(args...) printf(args)
#else
#define printl(args...) 0
#endif
int n,x;
int a[200005];
int inf=2e9;
struct node{
int l,r,val;
node(){
l=r=val=0;
}
};
struct SegmentTree{
vector<node>tree;
void build(){
tree.clear();
tree.push_back(node());
tree.push_back(node());
}
int get(int v,int l,int r,int ql,int qr){
if(qr<l||r<ql)return 0;
if(!v)return 0;
if(ql<=l&&r<=qr)return tree[v].val;
int mid=(l+r)/2;
return max(get(tree[v].l,l,mid,ql,qr),get(tree[v].r,mid+1,r,ql,qr));
}
void update(int v,int l,int r,int pos,int val){
umax(tree[v].val,val);
int mid=(l+r)/2;
if(l==r)return;
if(pos<=mid){
if(!tree[v].l){
tree[v].l=(int)tree.size();
tree.push_back(node());
}
update(tree[v].l,l,mid,pos,val);
}else{
if(!tree[v].r){
tree[v].r=(int)tree.size();
tree.push_back(node());
}
update(tree[v].r,mid+1,r,pos,val);
}
}
}dp[3];
int opt[1005][2];
int pref[200005];
int suff[200005];
int main(){
scanf("%d%d",&n,&x);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
if(n<=1000){
int ans=1;
opt[1][0]=opt[1][1]=1;
for(int i=2;i<=n;i++){
opt[i][0]=opt[i][1]=1;
for(int j=1;j<i;j++){
if(a[j]<a[i]){
umax(opt[i][0],opt[j][0]+1);
umax(opt[i][1],opt[j][1]+1);
}
if(a[j]<x+a[i])umax(opt[i][1],opt[j][0]+1);
}
umax(ans,opt[i][0]);
umax(ans,opt[i][1]);
}
cout<<ans;
return 0;
}
if(x==(int)1e9){
int ans=0;
dp[0].build();
for(int i=1;i<=n;i++){
int cur=1;
umax(cur,dp[0].get(1,-inf,inf,-inf,a[i]-1)+1);
dp[0].update(1,-inf,inf,a[i],cur);
pref[i]=cur;
}
dp[0].build();
for(int i=n;i>0;i--){
int cur=1;
umax(cur,dp[0].get(1,-inf,inf,a[i]+1,inf)+1);
dp[0].update(1,-inf,inf,a[i],cur);
suff[i]=cur;
}
for(int i=0;i<=n;i++)umax(ans,pref[i]+suff[i+1]);
cout<<ans;
return 0;
}
int ans=0;
for(int pivot=-x;pivot<=x;pivot++){
dp[0].build();
dp[1].build();
dp[2].build();
for(int i=1;i<=n;i++){
int cur[3]={1,1,1};
//if(a[j]<a[i])umax(dp[i][0],dp[j][0]+1);
umax(cur[0],dp[0].get(1,-inf,inf,-inf,a[i]-1)+1);
//if(a[j]<a[i]+pivot)umax(dp[i][1],dp[j][0]+1);
umax(cur[1],dp[0].get(1,-inf,inf,-inf,a[i]+pivot-1)+1);
//if(a[j]<a[i])umax(dp[i][1],dp[j][1]+1);
umax(cur[1],dp[1].get(1,-inf,inf,-inf,a[i]-1)+1);
//if(a[j]<a[i])umax(dp[i][2],dp[j][0]+1);
umax(cur[2],dp[0].get(1,-inf,inf,-inf,a[i]-1)+1);
//if(a[j]<a[i]-pivot)umax(dp[i][2],dp[j][1]+1);
umax(cur[2],dp[1].get(1,-inf,inf,-inf,a[i]-pivot-1)+1);
//if(a[j]<a[i])umax(dp[i][2],dp[j][2]+1);
umax(cur[2],dp[2].get(1,-inf,inf,-inf,a[i]-1)+1);
dp[0].update(1,-inf,inf,a[i],cur[0]);
dp[1].update(1,-inf,inf,a[i],cur[1]);
dp[2].update(1,-inf,inf,a[i],cur[2]);
umax(ans,cur[0]);
umax(ans,cur[1]);
umax(ans,cur[2]);
}
}
cout<<ans;
}
컴파일 시 표준 에러 (stderr) 메시지
glo.cpp: In function 'int main()':
glo.cpp:66:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
66 | scanf("%d%d",&n,&x);
| ~~~~~^~~~~~~~~~~~~~
glo.cpp:67:28: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
67 | for(int i=1;i<=n;i++)scanf("%d",&a[i]);
| ~~~~~^~~~~~~~~~~~
# | 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... |