This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
// #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("avx2")
using namespace std;
typedef long long ll;
typedef pair<int, int> pp;
#define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
#define per(i,r,l) for(int i = (r); i >= (l); i--)
#define rep(i,l,r) for(int i = (l); i < (r); i++)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define ss second
#define ff first
void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
void IOS(){
cin.tie(0) -> sync_with_stdio(0);
// #ifndef ONLINE_JUDGE
// freopen("in.in", "r", stdin);
// freopen("out.out", "w", stdout);
// #endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 1e9 + 7, maxn = 5e5 + 5, lg = 22, inf = ll(1e9) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll);return k*k%md*(b&1ll?a:1)%md;}
struct Node{
int prf, suf, vl, mx;
};
Node seg[maxn<<2];
int n, d;
void add(int i, int k, int x = 1, int lx = 0, int rx = n){
if(lx + 1 == rx){
seg[x].prf = seg[x].suf = seg[x].mx = 1;
seg[x].vl = k;
return;
}
int mid = (lx + rx)>>1;
if(i < mid) add(i, k, x<<1, lx, mid);
else add(i, k, x<<1|1, mid, rx);
seg[x].prf = seg[x<<1].prf + (seg[x<<1].prf == mid - lx? seg[x<<1|1].prf: 0);
seg[x].suf = seg[x<<1|1].suf + (seg[x<<1|1].suf == rx - mid? seg[x<<1].suf: 0);
seg[x].mx = max({
seg[x<<1].mx,
seg[x<<1|1].mx,
seg[x<<1].suf + seg[x<<1|1].prf
});
seg[x].vl = max(seg[x<<1].vl, seg[x<<1|1].vl);
}
int prf;
int ans;
int get(int i, int x = 1, int lx = 0, int rx = n){
if(i <= lx){
if(lx + 1 == rx){
ans = max(ans, seg[x].vl);
if(prf + seg[x].prf == d) return lx;
prf = seg[x].prf + (seg[x].prf? prf: 0);
return rx;
}
int mid = (lx + rx)>>1;
if(max(seg[x<<1].prf + prf, seg[x<<1].mx) < d) {
prf = seg[x<<1].suf + (seg[x<<1].suf == mid - lx? prf: 0);
ans = max(ans, seg[x<<1].vl);
return get(i, x<<1|1, mid, rx);
}
return get(i, x<<1, lx, mid);
}
int mid = (lx + rx)>>1;
if(i < mid){
int res = get(i, x<<1, lx, mid);
if(res == mid) return get(i, x<<1|1, mid, rx);
return res;
}else return get(i, x<<1|1, mid, rx);
}
int main(){ IOS();
cin >> n >> d;
vector<int> a(n);
vector<pp> p(n);
rep(i,0,n) cin >> a[i];
rep(i,0,n) p[i] = {-a[i], i};
sort(all(p));
int ANS = 0;
for(auto[d, i]: p){
d = -d;
prf = ans = 0;
if(i < n-1) get(i + 1);
ans++;
ANS = max(ANS, ans);
add(i, ans);
}
cout << ANS << '\n';
return 0;
}
# | 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... |