제출 #237569

#제출 시각아이디문제언어결과실행 시간메모리
237569NucleistGlobal Warming (CEOI18_glo)C++14
100 / 100
833 ms30048 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) #define debug(x) cerr << " - " << #x << ": " << x << endl; #define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl; #define all(x) (x).begin(),(x).end() #define sz(x) (ll)x.size() #define ll long long #define INF 1000000000 #define MOD 1000000007 #define pb push_back #define ve vector<ll> #define dos pair<ll,ll> #define vedos vector<dos> #define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) #define EPS 0.000001 struct greateri { template<class T> bool operator()(T const &a, T const &b) const { return a > b; } }; void setIO(string s) { ios_base::sync_with_stdio(0); cin.tie(0); freopen((s+".in").c_str(),"r",stdin); freopen((s+".out").c_str(),"w",stdout); } ll dp[200001],lis[200001],shift[200001],seg[800001],mak[200001],yo[200001]; ll n,x; vedos hed; ve mol; set<dos>kol; void up(ll p,ll l,ll r,ll index,ll val){ if(l>index || r<index)return; if(l==r && l==index){ seg[p]=val; return; } ll med=(l+r)/2; if(med>=index)up(p*2,l,med,index,val); else up(p*2+1,med+1,r,index,val); seg[p]=max(seg[p*2],seg[p*2+1]); } ll quer(ll p,ll l,ll r,ll l1,ll r1){ if(l>r)return 0; if(l>r1 || l1>r)return 0; if(l>=l1 && r<=r1)return seg[p]; ll med=(l+r)/2; return max(quer(p*2,l,med,l1,r1),quer(p*2+1,med+1,r,l1,r1)); } int main() { //flash; cin>>n>>x; for (ll i = 0; i < n; ++i) { ll yo;cin>>yo; hed.pb({yo,i}),mol.pb(yo),kol.insert({yo,i}); } sort(all(hed)); ll last=MOD; ll indexi=n; for (ll i = n-1; i >= 0 ; --i) { if(hed[i].first!=last){ last=hed[i].first; indexi=i+1; } yo[hed[i].second]=indexi; mak[hed[i].second]=i; } for (ll i = n-1; i >= 0; --i) { ll ko=1; ll fo=quer(1,0,n-1,yo[i],n-1); ko=max(ko,fo+1); lis[i]=ko; up(1,0,n-1,mak[i],ko); } for (int i = 0; i < n; ++i) { up(1,0,n-1,i,0); } last=MOD; indexi=-1; for (ll i = 0; i < n; ++i) { if(hed[i].first!=last){ last=hed[i].first; indexi=i-1; } yo[hed[i].second]=indexi; } for (int i = 0; i < n; ++i) { ll ko=1; ll fo=quer(1,0,n-1,0,yo[i]); ko=max(ko,fo+1); dp[i]=ko; up(1,0,n-1,mak[i],ko); } for (int i = 0; i < n; ++i) { up(1,0,n-1,i,0); } ll ans=0; for (int i = 0; i < n; ++i) { ll cur=mol[i]+x; auto u=kol.lower_bound({cur,-INF}); if(u!=kol.begin()){ u--; ll so=quer(1,0,n-1,0,mak[(*u).second]); ans=max(ans,so+lis[i]); } ll ko=1; ll fo=quer(1,0,n-1,0,yo[i]); ko=max(ko,fo+1); up(1,0,n-1,mak[i],ko); ans=max(ans,dp[i]+lis[i]-1); } cout<<ans; return 0; } //code the AC sol ! // BS/queue/map

컴파일 시 표준 에러 (stderr) 메시지

glo.cpp:4:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("O3")
 
glo.cpp:5:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("unroll-loops")
 
glo.cpp: In function 'void setIO(std::__cxx11::string)':
glo.cpp:27:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen((s+".in").c_str(),"r",stdin);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:28:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen((s+".out").c_str(),"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...