이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/* 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];
cerr << "OK " << i << ' ' << t[i] << endl;
}
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++) {
cerr << "OK " << i << ' ' << f[i] << endl;
if (get(i) && f[i] != i) pq.push({get(i), i});
}
int t = 0;
mark[0] = 1;
while (pq.size() && t < d) {
if (pq.top().F != get(pq.top().S)) {
if (get(pq.top().S)) pq.push({get(pq.top().S), pq.top().S});
pq.pop();
}
t++;
int u = pq.top().S;
cerr << "OK " << u << endl;
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... |