제출 #953272

#제출 시각아이디문제언어결과실행 시간메모리
953272AlphaMale06Global Warming (CEOI18_glo)C++14
0 / 100
58 ms11100 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back const int N = 2e5+3; vector<int> dp[N]; int ndp[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, d; cin >> n >> d; int a[n]; for(int i=0; i< n; i++)cin >> a[i]; dp[0].pb(2e9+1); int mx=0; for(int i = n-1; i>=0; i--){ if(a[i]<dp[mx].back()){ mx++; dp[mx].pb(a[i]); continue; } int l = 1, r = mx; while(l<=r){ int s = l+r>>1; if(dp[s].back()>=a[i])l=s+1; else r=s-1; } if(dp[l].back()<=a[i])dp[l].pb(a[i]); } int ans=mx; for(int i = 1; i<=n; i++)ndp[i]=1e9+i; ndp[0]=-1e9; int mxx=0; for(int i=0; i < n; i++){ if(a[i]==dp[mx].back()){ dp[mx].pop_back(); if(!dp[mx].size())mx--; } else{ int l = 1, r = mx; while(l<=r){ int s = l+r>>1; if(dp[s].back()>=a[i])l=s+1; else r=s-1; } if(dp[r].size() && dp[r].back()==a[i])dp[r].pop_back(); } int l = 0, r = n; if(a[i]-d>ndp[mxx]){ mxx++; ndp[mxx]=a[i]-d; } else{ while(l<=r){ int s = l+r>>1; if(ndp[s]>a[i]-d)r=s-1; else l=s+1; } ndp[l]=min(ndp[l], a[i]-d); } l=1 , r=mx; while(l<=r){ int s = l+r>>1; if(dp[s].back()>ndp[mxx]){ ans=max(ans, mxx+s); l=s+1; } else{ r=s-1; } } } cout << ans << '\n'; }

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

glo.cpp: In function 'int main()':
glo.cpp:29:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   29 |             int s = l+r>>1;
      |                     ~^~
glo.cpp:47:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   47 |                 int s = l+r>>1;
      |                         ~^~
glo.cpp:60:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   60 |                 int s = l+r>>1;
      |                         ~^~
glo.cpp:68:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   68 |             int s = l+r>>1;
      |                     ~^~
#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...