Submission #539170

#TimeUsernameProblemLanguageResultExecution timeMemory
539170UncoolAnonGlobal Warming (CEOI18_glo)C++17
0 / 100
7 ms4308 KiB
#include <bits/stdc++.h> using namespace std; const int mx=1e6+5; vector<int> tw(mx,1e9); int query(int i,int l,int r,int v){ if(l==r) return l; if(tw[i*2+1]<v) return query(i*2+1,(l+r)/2+1,r,v); return query(i*2,l,(r+l)/2,v); } void update(int i,int l,int r,int target,int v){ if(target<l||r<target) return; if(l==r) tw[i]=min(tw[i],v); else{ update(i*2,l,(r+l)/2,target,v); update(i*2+1,(r+l)/2+1,r,target,v); tw[i]=min(tw[i*2],tw[i*2+1]); } } int main(){ ios_base::sync_with_stdio(0); cin.tie(nullptr); #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif int n,x; cin>>n>>x; vector<int> a(n); for(int&x:a)cin>>x; vector<int> on(n+1,2e9+1); on[0]=0; update(1,0,n,0,0); int answer=0; for(int i=0;i<n;i++){ int l=0,r=n+1; while(r-l!=1){int md=(r+l)/2; if(on[md]<a[i]) l=md;else r=md;} int one=l+1; l=0,r=n+1; while(r-l!=1){int md=(r+l)/2; if(on[md]-x<a[i]) l=md; else r=md;} int two=l+1; l=query(1,0,n,a[i]); on[one]=min(a[i],on[one]); answer=max({answer,l+1,two,one}); update(1,0,n,max({l+1,two,one}),a[i]); } cout<<answer; return 0; }

Compilation message (stderr)

glo.cpp: In function 'int main()':
glo.cpp:23:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |   freopen("in.txt","r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~
glo.cpp:24:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |   freopen("out.txt","w",stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...