이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("Ofast,fast-math,unroll-loops")
#pragma GCC target("avx2,fma")
#include "bits/stdc++.h"
using namespace std;
#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif
const int N = 2e6 + 6;
int a[N];
int ct[N];
int low[N];
int lz[N * 2];
int slow[N * 2];
pair<int, int> seg[N * 2];
inline int merge(int lx, int rx) {
return low[lx] < low[rx] ? lx : rx;
}
void lowupd(int nd, int l, int r, int p, int v) {
if (l == r) {
slow[nd] = l;
return;
}
int mid = (l + r) >> 1;
int rs = nd + ((mid - l + 1) << 1);
if (p <= mid) {
lowupd(nd + 1, l, mid, p, v);
} else {
lowupd(rs, mid + 1, r, p, v);
}
slow[nd] = merge(slow[nd + 1], slow[rs]);
}
int lowget(int nd, int l, int r, int s, int e) {
if (l >= s && r <= e) {
return slow[nd];
}
int mid = (l + r) >> 1;
int rs = nd + ((mid - l + 1) << 1);
if (mid >= e) {
return lowget(nd + 1, l, mid, s, e);
} else {
if (mid < s) {
return lowget(rs, mid + 1, r, s, e);
} else {
return merge(lowget(nd + 1, l, mid, s, e), lowget(rs, mid + 1, r, s, e));
}
}
}
inline void push(int nd, int l, int r) {
if (!lz[nd]) return;
seg[nd].first += lz[nd];
if (l != r) {
int mid = (l + r) >> 1;
int rs = nd + ((mid - l + 1) << 1);
lz[nd + 1] += lz[nd];
lz[rs] += lz[nd];
}
lz[nd] = 0;
}
void build(int nd, int l, int r) {
seg[nd] = {0, l};
if (l == r) {
return;
}
int mid = (l + r) >> 1;
int rs = nd + ((mid - l + 1) << 1);
build(nd + 1, l, mid);
build(rs, mid + 1, r);
}
void upd(int nd, int l, int r, int s, int e, int v) {
push(nd, l, r);
if (l >= s && r <= e) {
lz[nd] = v;
push(nd, l, r);
return;
}
int mid = (l + r) >> 1;
int rs = nd + ((mid - l + 1) << 1);
if (mid >= e) {
push(rs, mid + 1, r);
upd(nd + 1, l, mid, s, e, v);
} else {
if (mid < s) {
push(nd + 1, l, mid);
upd(rs, mid + 1, r, s, e, v);
} else {
upd(nd + 1, l, mid, s, e, v);
upd(rs, mid + 1, r, s, e, v);
}
}
seg[nd] = max(seg[nd + 1], seg[rs]);
}
pair<int, int> get(int nd, int l, int r, int s, int e) {
push(nd, l, r);
if (l >= s && r <= e) {
return seg[nd];
}
int mid = (l + r) >> 1;
int rs = nd + ((mid - l + 1) << 1);
if (mid >= e) {
return get(nd + 1, l, mid, s, e);
} else {
if (mid < s) {
return get(rs, mid + 1, r, s, e);
} else {
return max(get(nd + 1, l, mid, s, e), get(rs, mid + 1, r, s, e));
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, d, t;
cin >> n >> d >> t;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
build(0, 1, n);
stack<int> stk;
low[0] = n + 1;
for (int i = 1; i <= n; ++i) {
stk.push(i);
while (!stk.empty() && a[stk.top()] + i - stk.top() > t) {
stk.pop();
}
if (!stk.empty()) {
low[i] = stk.top();
if (low[i] < i) {
upd(0, 1, n, low[i] + 1, i, 1);
}
} else {
low[i] = n + 1;
}
lowupd(0, 1, n, i, low[i]);
}
for (int iter = 1; iter <= d; ++iter) {
int mx = get(0, 1, n, 1, n).second;
while (true) {
int ind = lowget(0, 1, n, mx, n);
if (low[ind] >= mx) {
break;
}
upd(0, 1, n, low[ind] + 1, ind, -1);
low[ind] = n + 1;
lowupd(0, 1, n, ind, n + 1);
}
}
int ans = 0;
for (int i = 1; i <= n; ++i) {
if (low[i] <= n) {
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... |