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>
#define sz(x) (int)x.size()
#define chmin(x, v) x = min(x, v)
#define chmax(x, v) x = max(x, v)
#define all(x) x.begin(), x.end()
#define pb push_back
#define pii pair<int, int>
#define deb first
#define fin second
#define int long long
using namespace std;
const int N = (1 << 19);
int dateVal[N];
int arbre[N * 2];
int getMax(int gauche, int droite){
if (droite < gauche) return 0;
if (gauche%2 == 1) return max(arbre[gauche], getMax(gauche + 1, droite));
if (droite%2 == 0) return max(arbre[droite], getMax(gauche, droite - 1));
return getMax(gauche/2, droite/2);
}
int temps = 0;
void update(int noeud, int val){
dateVal[val] = temps++;
arbre[noeud] = val;
noeud /= 2;
for (; noeud > 0; noeud /= 2)
arbre[noeud] = max(arbre[noeud * 2], arbre[noeud * 2 + 1]);
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int nVals, distMax; cin >> nVals >> distMax;
vector<int> vals(nVals), triees;
for (int& val : vals){
cin >> val;
triees.pb(val);
}
sort(all(triees));
map<int, int> conv;
for (int i = 0; i < nVals; ++i)
conv[triees[i]] = i;
for (int& val : vals)
val = conv[val];
for (int iVal = 0; iVal < nVals; ++iVal){
if (iVal > distMax && dateVal[vals[iVal - distMax - 1]] == iVal - distMax - 1)
update(N + vals[iVal - distMax - 1], -1);
update(N + vals[iVal], getMax(N, N + vals[iVal] - 1) + 1);
}
cout << arbre[1] << endl;
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... |