제출 #635574

#제출 시각아이디문제언어결과실행 시간메모리
635574ColourAttilaGlobal Warming (CEOI18_glo)C++17
0 / 100
106 ms3428 KiB
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; int main() { int n,x; cin >>n >> x; vector<int> v(n); for(int&i : v) cin >> i; vector<int> suf(n+1, 0), lds(n+1, -1); lds[0] = INF; for(int i = n-1; i >= 0; i--) { int l = 0, r = n, mo = n; while(l <= r) { int mid = (l + r) / 2; if(lds[mid] >= v[i]) { l = mid+1; mo = mid; } else r = mid-1; } //cout << i << ": " << mo << endl; mo++; suf[i] = mo; lds[mo] = v[i]; } /*for(int i = 0; i < n; i++) cout << suf[i] << ' '; cout << endl;*/ vector<int> dp(n+1, INF); dp[0] = -1; int mo = 0; for(int i = 0; i < n; i++) { int a = upper_bound(dp.begin(), dp.end(), v[i] + x) - dp.begin(); /*cout << i << ": "; for(int i = 0; i <= n; i++) cout << dp[i] << ' '; cout << endl << a << ", " << suf[i] << endl;*/ mo = max(mo, a-2 + suf[i]); int j = upper_bound(dp.begin(), dp.end(), v[i]) - dp.begin(); dp[j] = v[i]; } cout << mo << 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...