This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/* In the name of God, aka Allah */
// Believe Me - Takeshi Abo
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = 2e6 + 50;
int n, d, t[N], T, f[N], pr[N];
bool mark[N];
int fen[N];
priority_queue<pii> pq;
int get(int i) {
int out = 0;
for (; i > 0; i -= i&-i) out += fen[i];
return out;
}
void upd(int i, int x) {
for (; i <= n; i += i&-i) fen[i] += x;
}
void solve() {
cin >> n >> d >> T;
for (int i = 1; i <= n; i++) {
cin >> t[i];
}
int ans = n;
for (int i = 1; i <= n; i++) {
f[i] = i;
while (f[i] > 0 && t[f[i]]+i-f[i] > T) {
pr[f[i]-1] = i;
f[i] = f[f[i]-1];
}
if (f[i] == 0) {
mark[i] = 1;
ans--;
continue;
}
upd(f[i]+1, 1);
upd(i+1, -1);
}
for (int i = 1; i <= n; i++) {
if (get(i)) pq.push({get(i), i});
}
int t = 0;
mark[0] = 1;
while (pq.size() && t <= d) {
while (pq.top().F != get(pq.top().S)) {
if (get(pq.top().S)) pq.push({get(pq.top().S), pq.top().S});
pq.pop();
}
int u = pq.top().S;
pq.pop();
while (!mark[u]) {
mark[u] = 1;
ans--;
upd(f[u]+1, -1);
upd(u+1, 1);
u = pr[u];
}
}
cout << ans << endl;
}
int main() {
ios::sync_with_stdio(0), cin.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... |