제출 #697098

#제출 시각아이디문제언어결과실행 시간메모리
697098KahouThe short shank; Redemption (BOI21_prison)C++14
0 / 100
2031 ms8760 KiB
/* 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...