Submission #422484

#TimeUsernameProblemLanguageResultExecution timeMemory
422484Emin2004Global Warming (CEOI18_glo)C++14
25 / 100
65 ms7468 KiB
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define pii pair <int, int> #define pb push_back #define F first #define S second #define ll long long #define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define M_PI 3.14159265358979323846 const int N = 200005; const int mod = 1e9 + 7; int lis[N], lds[N], a[N]; int mp[N]; int main() { io; int n, d; cin >> n >> d; for(int i = 0; i < n; i++){ cin >> a[i]; mp[i + 1] = INT_MAX; } int ans = 0; mp[1] = a[0]; lis[0] = 1; for(int i = 1; i < n; i++){ int l = 1, r = n; while(l <= r){ int mid = (l + r) / 2; if(mp[mid] < a[i]){ mp[mid + 1] = min(mp[mid + 1], a[i]); lis[i] = max(lis[i], mid + 1); l = mid + 1; ans = max(ans, l); } else{ r = mid - 1; } } mp[1] = min(mp[1], a[i]); } if(d == 0){ cout << ans; return 0; } for(int i = 1; i <= n; i++){ mp[i] = 0; } mp[1] = a[n - 1]; lds[n - 1] = 1; for(int i = n - 2; i >= 0; i--){ int l = 1, r = n; while(l <= r){ int mid = (l + r) / 2; if(mp[mid] > a[i]){ mp[mid + 1] = max(mp[mid + 1], a[i]); lds[i] = max(lds[i], mid + 1); l = mid + 1; } else{ r = mid - 1; } } mp[1] = max(mp[1], a[i]); } for(int i = 1; i <= n; i++){ mp[i] = -1; } set<pii> s; s.insert({a[0], 1}); mp[1] = a[0]; for(int i = 1; i < n; i++){ int cur = lds[i]; int k = a[i] + d; set<pii>::iterator itr = s.lower_bound({k, 0}); if(itr != s.begin()) itr--; cur += (*itr).S; if(mp[lis[i]] > a[i]){ s.erase(s.find({mp[lis[i]], lis[i]})); s.insert({a[i], lis[i]}); } if(mp[lis[i]] == -1){ s.insert({a[i], lis[i]}); } ans = max(ans, cur); } cout << ans; }
#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...