This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
/* In the name of God, aka Allah */
// let this be mytemp.cpp
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define endl '\n'
#define mk make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 1e9 + 50;
const int N = 2e6 + 5;
int n, d, t[N], T, b[N], L[N];
int seg[N<<2];
pii out[N<<2];
int ers[N<<2];
int lazy[N<<2];
vector<int> vc[N<<2];
void build(int u=1, int tl=1, int tr=n) {
if (tl == tr) {
seg[u] = inf;
return;
}
int md = (tl+tr)/2;
int lc = u<<1;
int rc = u<<1|1;
build(lc, tl, md), build(rc, md+1, tr);
seg[u] = min(seg[lc], seg[rc]);
}
void upd(int id, int x, int u=1, int tl=1, int tr=n) {
if (tl == tr) {
seg[u] = min(seg[u], x);
return;
}
int md = (tl+tr)/2;
int lc = u<<1;
int rc = u<<1|1;
if (id <= md) upd(id, x, lc, tl, md);
else upd(id, x, rc, md+1, tr);
seg[u] = min(seg[lc], seg[rc]);
}
int get(int x, int u=1, int tl=1, int tr=n) {
if (seg[u] > x) return 0;
if (tl == tr) return tl;
int md = (tl+tr)/2;
int lc = u<<1;
int rc = u<<1|1;
int out = get(x, rc, md+1, tr);
if (!out) out = get(x, lc, tl, md);
return out;
}
void shift(int u) {
int lc = u<<1;
int rc = u<<1|1;
out[lc].F += lazy[u];
lazy[lc] += lazy[u];
out[rc].F += lazy[u];
lazy[rc] += lazy[u];
lazy[u] = 0;
}
void build2(int u=1, int tl=1, int tr=n) {
if (tl == tr) {
out[u] = {0, tl};
return;
}
int md = (tl+tr)/2;
int lc = u<<1;
int rc = u<<1|1;
build2(lc, tl, md), build2(rc, md+1, tr);
out[u] = max(out[lc], out[rc]);
}
void push(int l, int r, int id, int u =1, int tl=1, int tr=n) {
if (l <= tl && tr <= r) {
out[u].F++;
lazy[u]++;
vc[u].push_back(id);
return;
}
shift(u);
int md = (tl+tr)/2;
int lc = u<<1;
int rc = u<<1|1;
if (l <= md) push(l, r, id, lc, tl, md);
if (r > md) push(l, r, id, rc, md+1, tr);
out[u] = max(out[lc], out[rc]);
}
void pop(int l, int r, int id, int u=1, int tl=1, int tr=n) {
if (l <= tl && tr <= r) {
out[u].F--;
lazy[u]--;
ers[u]++;
return;
}
shift(u);
int md = (tl+tr)/2;
int lc = u<<1;
int rc = u<<1|1;
if (l <= md) pop(l, r, id, lc, tl, md);
if (r > md) pop(l, r, id, rc, md+1, tr);
out[u] = max(out[lc], out[rc]);
}
bool cmp (int x, int y) {
pii A = {x-L[x], x};
pii B = {y-L[y], y};
return A < B;
}
int vx[N], sz, pt;
void getvc(int id, int u=1, int tl=1, int tr=n) {
for (int i = (int)vc[u].size()-ers[u]-1; i >= 0; i--) {
int x = vc[u][i];
vx[sz++] = x;
}
if (tl == tr) return;
int md = (tl+tr)/2;
int lc = u<<1;
int rc = u<<1|1;
if (id <= md) getvc(id, lc, tl, md);
else getvc(id, rc, md+1, tr);
}
void solve() {
cin >> n >> d >> T;
for (int i = 1; i <= n; i++) {
cin >> t[i];
}
build();
build2();
int ans = 0;
for (int i = 1; i <= n; i++) {
upd(i, t[i]-i);
L[i] = get(T-i)+1;
if (L[i] > i) continue;
if (L[i] <= 1) {
ans++;
continue;
}
push(L[i], i, i);
}
for (int i = 1; i <= d; i++) {
ans += out[1].F;
int id = out[1].S;
getvc(id);
for (int j = sz-1; j >= pt; j--) {
int x = vx[j];
pop(L[x], x, x);
}
pt = sz;
}
cout << n-ans << endl;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
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... |