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>
using namespace std;
#define rep(i,s,e) for (int i = s; i <= e; ++i)
#define rrep(i,s,e) for (int i = s; i >= e; --i)
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define len(a) (int)a.size()
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, d; cin >> n >> d;
int a[n+1] = {};
rep (i,1,n) cin >> a[i];
set<ii> st;
multiset<int> mi;
a[0]= 1e9;
rep (i,1,n) {
mi.insert(a[i-1]);
if (i-d-1>=0) mi.erase(mi.find(a[i-d-1]));
while (len(st) && *mi.begin() > (*st.begin()).fi) st.erase(st.begin());
auto it = st.lower_bound({a[i],0});
if (it==st.end()) {
if (it==st.begin()) st.insert({a[i], 1});
else st.insert({a[i], (*--it).se+1});
}
else if ((*it).fi!=a[i]) {
if (it==st.begin()) {
if ((*it).se==1) st.erase(it);
st.insert({a[i],1});
}
else {
int x = (*--it).se+1;
if ((*++it).se == x) st.erase(it);
st.insert({a[i], x});
}
}
}
cout << (*st.rbegin()).se << "\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... |