제출 #393927

#제출 시각아이디문제언어결과실행 시간메모리
393927tostesGlobal Warming (CEOI18_glo)C++17
0 / 100
2090 ms17476 KiB
#include<bits/stdc++.h> //#include<iostream> //#include<vector> using namespace std; #define _ << ' ' << #define pb push_back #define all(x) begin(x), end(x) #define mp make_pair #define f first #define s second #define sz(x) int((x).size()) using ll = long long; using db = long double; using pl = pair<ll,ll>; using pi = pair<int,int>; void trad(vector<ll>a, ll x){ int n=a.size(); set < pl > lis; vector < ll > tr(n,1); for(int i=n-1; i>=0; i--){ auto p = lis.upper_bound({a[i],1e15}); if(p!=lis.end()){ tr[i]+=p->s; } lis.insert({a[i],tr[i]}); auto pp = lis.find({a[i],tr[i]}); if(pp!=lis.end() and (next(pp)->s == tr[i])) lis.erase(pp); if(pp!=lis.begin() and (prev(pp)->s == tr[i])) lis.erase(prev(pp)); } ll ans = *max_element(all(tr)); set < pl > Lis; for(int i=0; i<n-1; i++){ auto p = Lis.upper_bound({a[i]-x,1e15}); if(p!=Lis.end()){ if(p->f > a[i]-x){ Lis.insert({a[i]-x, p->s}); Lis.erase(p); } } else Lis.insert({a[i]-x, Lis.size()+1}); auto w = Lis.lower_bound({a[i+1],0}); ll ct=Lis.size(); if(w!=Lis.end()) ct = (w->s)-1; ans = max(ans, ct + tr[i+1]); } cout << ans << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(0); //freopen("nocross.in", "r", stdin); //freopen("nocross.out", "w", stdout); int n; ll x; cin >> n >> x; vector < ll > a(n); for(auto &w: a) cin >> w; trad(a,x); }
#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...