Submission #605220

#TimeUsernameProblemLanguageResultExecution timeMemory
605220EvirirGlobal Warming (CEOI18_glo)C++17
100 / 100
88 ms10080 KiB
#include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> using namespace std; //using namespace __gnu_pbds; #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2") #define watch(x) cout<<(#x)<<"="<<(x)<<'\n' #define mset(d,val) memset(d,val,sizeof(d)) #define cbug if(DEBUG) cout #define setp(x) cout<<fixed<<setprecision(x) #define sz(x) (int)(x).size() #define all(x) begin(x), end(x) #define forn(i,a,b) for(int i=(a);i<(b);i++) #define fore(i,a,b) for(int i=(a);i<=(b);i++) #define pb push_back #define F first #define S second #define fbo find_by_order #define ook order_of_key typedef long long ll; typedef long double ld; typedef pair<ll,ll> ii; typedef vector<ll> vi; typedef vector<ii> vii; //template<typename T> //using pbds = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; void SD(int t=0){ cout<<"PASSED "<<t<<endl; } ostream& operator<<(ostream &out, ii x){ out<<"("<<x.F<<","<<x.S<<")"; return out; } template<typename T> void amax(T &a, T b){ a=max(a,b); } template<typename T> void amin(T &a, T b){ a=min(a,b); } const ll INF = ll(1e18); const int MOD = 998244353; const bool DEBUG = 0; const int MAXN = 200005; const int LG = 21; int n; ll X; ll a[MAXN]; vi dpl, dpr; vii chg; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>n>>X; forn(i,0,n) cin>>a[i]; dpl.resize(n + 1, INF); dpl[0] = -INF; dpr.resize(n + 1, -INF); dpr[0] = INF; chg.resize(n); for (int i = n - 1; i >= 0; i--) { int p = lower_bound(all(dpr), a[i], greater<ll>()) - dpr.begin(); chg[i] = {p, dpr[p]}; dpr[p] = a[i]; } int ans = 0; forn(i, 0, n) { int pl = lower_bound(all(dpl), a[i]) - dpl.begin(); int pr = chg[i].F; dpl[pl] = a[i]; dpr[pr] = chg[i].S; int q = lower_bound(all(dpr), dpl[pl] - X, greater<ll>()) - dpr.begin() - 1; ans = max(ans, pl + q); q = lower_bound(all(dpl), dpr[pr] + X) - dpl.begin() - 1; ans = max(ans, q + pr); } int cur = 0; while (cur + 1 <= n && dpl[cur + 1] != INF) cur++; ans = max(ans, cur); 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...