이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define chmin(x, v) x = min(x, v)
#define chmax(x, v) x = max(x, v)
#define all(v) v.begin(), v.end()
#define pb push_back
#define int long long
using namespace std;
const int N = 1 << 19;
int dynMax[2 * N][2];
int getMax(int gauche, int droite, int mod){
if (gauche > droite) return 0;
if (gauche%2 == 1) return max(dynMax[gauche][mod], getMax(gauche + 1, droite, mod));
if (droite%2 == 0) return max(dynMax[droite][mod], getMax(gauche, droite - 1, mod));
return getMax(gauche/2, droite/2, mod);
}
void update(int ind, int val, int mod){
for (; ind > 0; ind /= 2)
chmax(dynMax[ind][mod], val);
}
signed main(){
int nVals, toAdd; cin >> nVals >> toAdd;
vector<int> triees, vals(nVals), pointeur(nVals);
map<int, int> conversion;
for (int& val : vals) cin >> val, triees.pb(val);
sort(all(triees));
pointeur[nVals - 1] = nVals - 1;
for (int ind = nVals - 2; ind >= 0; --ind){
pointeur[ind] = pointeur[ind + 1];
while (pointeur[ind] > ind && triees[pointeur[ind]] - toAdd >= triees[ind])
--pointeur[ind];
}
for (int ind = 0; ind < nVals; ++ind)conversion[triees[ind]] = ind;
for (int& val : vals) val = conversion[val];
for (int ind = 0; ind < nVals; ++ind){
for (int xAjoute = 1; xAjoute >= 0; --xAjoute){
update(N + vals[ind], getMax(N, N + vals[ind] - 1, xAjoute) + 1, xAjoute);
if (xAjoute == 1 && toAdd != 0) update(N + vals[ind], getMax(N, N + pointeur[vals[ind]], 0) + 1, xAjoute);
//cout << dynMax[N + vals[ind]][xAjoute] << " " << vals[ind] << " " << pointeur[ind] << endl;
}
// cout << endl;
}
cout << max(dynMax[1][0], dynMax[1][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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |