제출 #666421

#제출 시각아이디문제언어결과실행 시간메모리
666421MilosMilutinovicThe short shank; Redemption (BOI21_prison)C++17
0 / 100
2093 ms4200 KiB
/** * author: wxhtzdy * created: 28.11.2022 15:11:47 **/ #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, d, t; cin >> n >> d >> t; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<int> prv(n); vector<int> stk; for (int i = 0; i < n; i++) { prv[i] = -1; for (int j = 0; j <= i; j++) { if (a[j] + (i - j) <= t) { prv[i] = j; } } /* while (!stk.empty() && a[stk.back()] + i - stk.back() > t) { stk.pop_back(); } while (!stk.empty() && a[stk.back()] - stk.back() > a[i] - i) { stk.pop_back(); } prv[i] = (a[i] <= t ? i : (stk.empty() ? -1 : stk.back())); stk.push_back(i); */ } vector<int> add(4 * n); vector<int> mx(4 * n); vector<int> idx(4 * n); function<void(int, int, int)> Build = [&](int x, int l, int r) { idx[x] = l; if (l == r) { return; } int y = (l + r) >> 1; int z = x + 2 * (y - l + 1); Build(x + 1, l, y); Build(z, y + 1, r); }; function<void(int, int, int)> Pull = [&](int x, int y, int z) { if (mx[y] > mx[z]) { mx[x] = mx[y]; idx[x] = idx[y]; } else { mx[x] = mx[z]; idx[x] = idx[z]; } }; function<void(int, int, int, int, int, int)> Modify = [&](int x, int l, int r, int ll, int rr, int v) { if (ll <= l && r <= rr) { add[x] += v; mx[x] += v; return; } if (l > ll || r < ll || l > r) { return; } int y = (l + r) >> 1; int z = x + 2 * (y - l + 1); if (add[x] != 0) { mx[x + 1] += add[x]; mx[z] += add[x]; add[x + 1] += add[x]; add[z] += add[x]; add[x] = 0; } Modify(x + 1, l, y, ll, rr, v); Modify(z, y + 1, r, ll, rr, v); Pull(x, x + 1, z); }; Build(0, 0, n - 1); int ans = 0; for (int i = 0; i < n; i++) { if (prv[i] != -1) { ans += 1; if (prv[i] < i) { Modify(0, 0, n - 1, prv[i], i - 1, +1); } } } vector<bool> rem(n); while (d--) { int i = idx[0]; ans -= mx[0]; Modify(0, 0, n - 1, i, i, -1e9); rem[i] = true; for (int j = i + 1; j < n; j++) { if (prv[j] != -1 && prv[j] <= i) { if (prv[j] < j) { Modify(0, 0, n - 1, prv[j], j - 1, -1); } prv[j] = -1; } } } cout << ans << '\n'; 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...