이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 < int > tr(n,1);
for(int i=n-1; i>=0; i--){
auto p = lis.upper_bound({a[i],0});
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 = tr[0];
set < pl > Lis;
for(int i=0; i<n-1; i++){
auto p = Lis.upper_bound({a[i]-x,0});
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});
int ct=Lis.size();
if(w!=Lis.end()) ct = (w->s)-1;
ans = max(ans, (ll)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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |