이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
KAMUI!
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▓▓▓▓██████████▓▓▓▓▓▓▓▓▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▓███▓▓▓▓▓▓▓▓▓▓█████▓▓▓▓▓▓▓▓▓
▓▓▓▓▓▓▓███▓▒▒░▒▒▒▒▒░░░▒▒▒▓▓███▓▓▓▓▓▓▓
▓▓▓▓▓▓█▓▒▒▒▓▓████████▓▒▒░▒▒▒▓██▓▓▓▓▓▓
▓▓▓▓██▒▓████████████████▓░▒▒▒▒▓██▓▓▓▓
▓▓▓██▓███████▓▒░░░░░░░▒███▒░░▒▒▒██▓▓▓
▓▓█████████▓░░░░░░░░░░░░░██▓▓██████▓▓
▓▓█▒▓███████████▓▓▒▒▒▓▓██████████▓█▓▓
▓██▒▒▒███████████████████████████▓▓█▓
▓█▓▒▒░░████████▒░░░░▓███████████▓░▒█▓
▓█▒▒▒░██░▒████░░░░░░█████░░████▓░░▒█▓
▓█▒▒▒▒██░░░██▓░░░░░░░███▒░░████▒▒▒▒█▓
▓█▓▒▒▒██▒░░░▓█▓░░░░░▓█▓░░░▓███▓▒▒░▓█▓
▓█▓▒▒▒███░░░░████████▓░░░░░████▒▒▒▓█▓
▓▓█▒▒░▓███░░░▒███████▒░░░▒███▓▒▒▒▒█▓▓
▓▓██▒▒░████▒░░███████░░░▓███▓░▒▒▒██▓▓
▓▓▓██▒▒▒█████▓░░██████▒▓███▓▒░▒▒██▓▓▓
▓▓▓▓██▓▒░▓██████████████▓▒░▒▒▒▓██▓▓▓▓
▓▓▓▓▓▓██▓░▒▓█████████▒░░▒▒▒▒▓██▓▓▓▓▓▓
▓▓▓▓▓▓▓███▓▒▒▓██████▓░▒▒▒▓▓███▓▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▓▓███▓▓▓▓███▓▓▓████▓▓▓▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▓▓▓▓███████████▓▓▓▓▓▓▓▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
*/
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
using namespace std;
template<typename T1, typename T2> inline void chkmin(T1 &a, T2 b) {if (a > b) a = b;}
template<typename T1, typename T2> inline void chkmax(T1 &a, T2 b) {if (a < b) a = b;}
#define files(FILENAME) read(FILENAME); write(FILENAME)
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define left left228
#define right right228
#define y1 y1228
#define mp make_pair
#define pb push_back
#define y2 y2228
#define rank rank228
using ll = long long;
using ld = long double;
const string FILENAME = "input";
const int Mod = 998244353;
int sum(int a, int b) {
return (a + b >= Mod ? a + b - Mod: a + b);
}
int mul(int a, int b) {
return ((ll)a * b) % Mod;
}
int powm(int a, int b) {
int res = 1;
while (b) {
if (b & 1) {
res = mul(res, a);
}
a = mul(a, a);
b >>= 1;
}
return res;
}
int inv(int a) {
return powm(a, Mod - 2);
}
const int MAXN = 300228;
int n, D;
int a[MAXN];
int rl[MAXN];
int dp[MAXN];
vector<int> kill[MAXN];
int where[MAXN];
int td[MAXN];
int d[MAXN * 4];
int ss = 1;
void change(int i, int x) {
d[i] = x;
while (i >> 1 > 0) {
i >>= 1;
d[i] = max(d[i * 2], d[i * 2 + 1]);
}
}
int get(int l, int r) {
l += ss;
r += ss;
int ans = 0;
while (l <= r) {
if (l & 1) {
chkmax(ans, d[l]);
l++;
}
if (!(r & 1)) {
chkmax(ans, d[r]);
r--;
}
l >>= 1;
r >>= 1;
}
return ans;
}
void solve() {
cin >> n >> D;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<pair<int, int> > st;
for (int i = 0; i < n; i++) {
st.pb(mp(a[i], i));
}
sort(all(st));
int uk1 = 0;
for (int i = 0; i < n; i++) {
where[st[i].second] = i;
while (st[uk1].first < st[i].first) {
uk1++;
}
td[st[i].second] = uk1 - 1;
}
int uk = n - 1;
set<pair<int, int> > s, sb;
for (int it = n - 1; it >= 0; it--) {
int i = st[it].second;
while (st[uk].first > st[it].first) {
int j = st[uk].second;
{
auto it = s.lower_bound(mp(j, 0));
vector<pair<int, int> > dels;
vector<pair<int, int> > adds;
int l = j;
int r = j;
if (it != s.end() && it->first == j + 1) {
r = it->second;
dels.pb(*it);
}
if (it != s.begin()) {
it--;
if (it->second == j - 1) {
l = it->first;
dels.pb(*it);
}
}
adds.pb(mp(l, r));
for (auto x: dels) {
s.erase(x);
sb.erase(x);
}
for (auto x: adds) {
s.insert(x);
if (x.second - x.first + 1 > D - 1) {
sb.insert(x);
}
}
}
uk--;
}
auto f = sb.lower_bound(mp(i + 1, 0));
if (f != sb.begin()) {
f--;
}
int last = n - 1;
for (auto cur = f; cur != sb.end(); cur++) {
int ls = max(cur->first, i);
int rs = ls + D - 1;
if (rs <= cur->second) {
last = rs;
break;
}
}
rl[i] = last;
}
while (ss < n) {
ss <<= 1;
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (auto x: kill[i]) {
change(ss + where[x], -1);
}
dp[i] = 1 + get(0, td[i]);
change(ss + where[i], dp[i]);
kill[rl[i] + 1].pb(i);
chkmax(ans, dp[i]);
}
cout << ans << '\n';
}
int main() {
//12:15
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// read(FILENAME);
int t;
t = 1;
// cin >> t;
while (t--) {
solve();
}
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... |