제출 #715893

#제출 시각아이디문제언어결과실행 시간메모리
715893tengiz05Rabbit Carrot (LMIO19_triusis)C++17
35 / 100
11 ms600 KiB
#include <bits/stdc++.h> using i64 = long long; constexpr int inf = 2001111111; struct SegmentTree { int n; std::vector<int> mn, mn2, lazy; SegmentTree(int n) : n(n), mn(4 * n, -inf), mn2(4 * n, inf), lazy(4 * n) {} void push(int p) { mn[2 * p] += lazy[p]; mn[2 * p + 1] += lazy[p]; mn2[2 * p] += lazy[p]; mn2[2 * p + 1] += lazy[p]; mn[2 * p] = std::max(mn[2 * p], mn[p]); mn[2 * p + 1] = std::max(mn[2 * p + 1], mn[p]); lazy[2 * p] += lazy[p]; lazy[2 * p + 1] += lazy[p]; lazy[p] = 0; } void pull(int p) { mn[p] = std::min(mn[2 * p], mn[2 * p + 1]); if (mn[2 * p] == mn[2 * p + 1]) { mn2[p] = std::min(mn2[2 * p], mn2[2 * p + 1]); } else if (mn[2 * p] == mn[p]) { mn2[p] = std::min(mn2[2 * p], mn[2 * p + 1]); } else { mn2[p] = std::min(mn[2 * p], mn2[2 * p + 1]); } } void modify(int p, int l, int r, int x, int y) { if (l == r - 1) { mn[p] = y; mn2[p] = inf; } else { int m = (l + r) / 2; push(p); if (x < m) { modify(2 * p, l, m, x, y); } else { modify(2 * p + 1, m, r, x, y); } pull(p); } } void modify(int x, int y) { modify(1, 0, n, x, y); } void chmax(int p, int l, int r, int x, int y, int v) { if (y <= l || r <= x || v <= mn[p]) return; if (x <= l && r <= y && v < mn2[p]) { // could be here mn[p] = v; return; } int m = (l + r) / 2; push(p); chmax(2 * p, l, m, x, y, v); chmax(2 * p + 1, m, r, x, y, v); mn[p] = std::min(mn[2 * p], mn[2 * p + 1]); pull(p); } void chmax(int l, int r, int v) { chmax(1, 0, n, l, r, v); } int at(int p, int l, int r, int x) { if (l == r - 1) { return mn[p]; } else { int m = (l + r) / 2; push(p); if (x < m) { return at(2 * p, l, m, x); } else { return at(2 * p + 1, m, r, x); } } } int at(int x) { return at(1, 0, n, x); } void add(int p, int l, int r, int x, int y, int v) { if (y <= l || r <= x) return; if (x <= l && r <= y) { lazy[p] += v; mn[p] += v; mn2[p] += v; return; } int m = (l + r) / 2; add(2 * p, l, m, x, y, v); add(2 * p + 1, m, r, x, y, v); pull(p); } void add(int l, int r, int v) { add(1, 0, n, l, r, v); } }; void chmax(int &a, int b) { if (a < b) { a = b; } } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n, M; std::cin >> n >> M; std::vector<int> a(n); for (int i = 0; i < n; i++) { std::cin >> a[i]; } SegmentTree s(n + 1); s.modify(n, 0); for (int i = 0; i < n; i++) { int lo = 0, hi = n + 1; while (lo + 1 < hi) { int m = (lo + hi) / 2; if (a[i] - s.at(m) <= M) { hi = m; } else { lo = m; } } //~ std::cout << hi << "\n"; //~ for (int i = 0; i <= n; i++) { //~ std::cout << s.at(i) << " "; //~ } std::cout << "\n"; s.add(0, n + 1, M); s.chmax(hi - 1, n, a[i]); } //~ for (int i = 0; i <= n; i++) { //~ std::cout << s.at(i) << " "; //~ } std::cout << "\n"; for (int i = 0; i <= n; i++) { if (s.at(i) >= 0) { std::cout << i << "\n"; return 0; } } assert(false); 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...