Submission #442993

#TimeUsernameProblemLanguageResultExecution timeMemory
442993FocutaiGlobal Warming (CEOI18_glo)C++17
45 / 100
730 ms262152 KiB
#include<bits/stdc++.h> using namespace std; #define pb push_back #define eb emplace_back #define mp make_pair #define Fast_IO ios::sync_with_stdio(false); #define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__) //mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); #define fir first #define sec second #define mod 998244353 #define ll long long #define inf ((int)2e9) #define INF 0x3f3f3f3f3f3f3f3f inline int read() { char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();} int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();} if(nega==-1) return -ans; return ans; } typedef pair<int,int> pii; void print(vector<int> x){for(int i=0;i<(int)x.size();i++) printf("%d%c",x[i]," \n"[i==(int)x.size()-1]);} int max(int x,int y,int z) {return max(max(x,y),z);} #define N 200005 struct SMT { struct Node { int ls,rs,val; }; Node t[N*110]; int cnt=1; void update(int &u,int l,int r,int L,int R,int v) { if(L>R) return ; if(!u) u=++cnt; if(L<=l&&r<=R) {t[u].val=max(t[u].val,v); return ;} int mid=(l+r)/2; if(mid>=L) update(t[u].ls,l,mid,L,R,v); if(mid<R) update(t[u].rs,mid+1,r,L,R,v); } int query(int u,int l,int r,int pos) { if(!u) return 0; int ans=t[u].val,mid=(l+r)/2; if(pos<=mid) ans=max(ans,query(t[u].ls,l,mid,pos)); else ans=max(ans,query(t[u].rs,mid+1,r,pos)); return ans; } void clear() {memset(t,0,sizeof(t)),cnt=1;} }smt; int a[N],f[N],n,d,rt=1; signed main() { cin>>n>>d; for(int i=1;i<=n;i++) a[i]=read(); for(int i=1;i<=n;i++) { f[i]=smt.query(1,1,inf,a[i])+1; smt.update(rt,1,inf,a[i]+1,inf,f[i]); } // for(int i=1;i<=n;i++) printf("%d%c",f[i]," \n"[i==n]); smt.clear(); int ans=0; for(int i=n;i>=1;i--) { int res=smt.query(1,1,inf,a[i]+d); smt.update(rt,1,inf,1,a[i]+d-1,res+1); // printf("%d : %d %d\n",i,f[i-1],smt.query(rt,1,inf,a[i-1]+1)); ans=max(ans,f[i-1]+smt.query(rt,1,inf,a[i-1])); } cout<<ans<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...