Submission #580464

#TimeUsernameProblemLanguageResultExecution timeMemory
580464juggernautGlobal Warming (CEOI18_glo)C++14
100 / 100
693 ms139480 KiB
#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=1e9+5; 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)>>1; 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)>>1; 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 pref[200005]; int suff[200005]; int main(){ scanf("%d%d",&n,&x); for(int i=1;i<=n;i++)scanf("%d",&a[i]); int ans=0; dp[0].build(); for(int i=1;i<=n;i++){ int cur=1; umax(cur,dp[0].get(1,0,inf,0,a[i]-1)+1); dp[0].update(1,0,inf,a[i],cur); pref[i]=cur; } dp[1].build(); for(int i=n;i>0;i--){ int cur=1; umax(cur,dp[1].get(1,0,inf,a[i]+1,inf)+1); dp[1].update(1,0,inf,a[i],cur); suff[i]=cur; } ans=suff[1]; dp[2].build(); for(int i=1;i<=n;i++){ dp[2].update(1,0,inf,a[i],pref[i]); umax(ans,suff[i+1]+dp[2].get(1,0,inf,0,min(a[i+1]-1+x,inf))); } cout<<ans; }

Compilation message (stderr)

glo.cpp: In function 'int main()':
glo.cpp:65:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |  scanf("%d%d",&n,&x);
      |  ~~~~~^~~~~~~~~~~~~~
glo.cpp:66:28: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |  for(int i=1;i<=n;i++)scanf("%d",&a[i]);
      |                       ~~~~~^~~~~~~~~~~~
#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...