제출 #961186

#제출 시각아이디문제언어결과실행 시간메모리
961186SyriusGlobal Warming (CEOI18_glo)C++14
0 / 100
992 ms81740 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define ll long long #define ff first #define ss second #define pint pair < int , int > #define fast ios_base::sync_with_stdio(NULL); cin.tie(NULL) const int inf = 1e9 + 9; const int mxn = 2e5 + 2; const int mod = 1e9 + 7; int prelis[mxn] , suflis[mxn] , a[mxn] , ed[mxn]; int n , x; void find1(int id) { int l = 0 , r = id-1; while (l != r) { int m = (l + r) / 2; if (ed[m+1] >= a[id]) r = m; else l = m+1; } prelis[id] = r + 1; ed[r+1] = min(a[id] , ed[r+1]); } void find2(int id) { int l = 0 , r = n - id; while (l != r) { int m = (l + r) / 2; if (ed[m+1] <= a[id]) r = m; else l = m + 1; } suflis[id] = r + 1; ed[r+1] = max(a[id] , ed[r+1]); } struct node { int tl , tm , tr , val; node *left , *right; node (int l , int r) { tl = l , tr = r , tm = (l + r) / 2; val = -inf; left = right = NULL; } void make() { if (left == NULL) left = new node(tl , tm); if (right == NULL) right = new node(tm+1 , tr); } void update(int p , int v) { if (tl == tr) { val = v; return; } make(); if (p <= tm) left -> update(p , v); else right -> update(p , v); val = max(left -> val , right -> val); } int query(int r) { if (tl == tr) return val; make(); if (r <= tm) return left -> query(r); return max(left -> val , right -> query(r)); } }; map < int , int > mp; int cntr; void compress() { set < int > comp; for (int i = 1; i <= n; i++) { comp.insert(a[i]); comp.insert(a[i] + x - 1); } for (int i : comp) { mp[i] = ++cntr; } } signed main() { cin >> n >> x; for (int i = 1; i <= n; i++) { cin >> a[i]; } ed[0] = 0; for (int i = 1; i <= n; i++) ed[i] = inf; ed[1] = a[1] , prelis[1] = 1; for (int i = 2; i <= n; i++) find1(i); for (int i = 1; i <= n; i++) ed[i] = -inf; ed[0] = inf; ed[1] = a[n] , suflis[n] = 1; for (int i = n-1; i >= 1; i--) find2(i); compress(); node *root = new node(0 , cntr); int ans = prelis[n]; for (int i = 1; i < n; i++) { ans = max(ans , root -> query(mp[a[i]+x-1]) + suflis[i+1]); root -> update(mp[a[i]] , prelis[i]); } cout << ans << '\n'; 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...