Submission #1153872

#TimeUsernameProblemLanguageResultExecution timeMemory
1153872justin271828Po (COCI21_po)C++20
0 / 70
129 ms12564 KiB
#include <bits/stdc++.h> using namespace std; const int INF = 1234567890; set<int> nz; struct node { int s, e, m, val, lazy; node *l, *r; node (int S, int E) : s(S), e(E), m((S+E)/2), val(0), lazy(0) { if (s != e) { l = new node(s, m); r = new node(m+1, e); } } void prop() { l->val += lazy; l->lazy += lazy; r->val += lazy; r->lazy += lazy; if (l->s == l->e && nz.find(l->s) != nz.end()) nz.erase(nz.find(l->s)); if (r->s == r->e && nz.find(r->s) != nz.end()) nz.erase(nz.find(r->s)); lazy = 0; } void up(int x, int y, int k) { if (x <= s && e <= y) { val += k; lazy += k; return; } else if (x > e || y < s) return; prop(); l->up(x, y, k); r->up(x, y, k); val = min(l->val, r->val); } int q(int x, int y) { if (x <= s && e <= y) return val; else if (x > e || y < s) return INF; prop(); return min(l->q(x, y), r->q(x, y)); } int bsta(int x) { if (s == e) { if (val == 0) return s; else return INF; } prop(); if (x <= m && l->val == 0) { if (l->bsta(x) != INF) return l->bsta(x); } if (r->val == 0) { return r->bsta(x); } else return INF; } }*tree; int main() { int n; cin >> n; tree = new node(0, 123456); int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; if (arr[i] != 0) { nz.insert(i); cout << nz.size() << " ";} tree->up(i, i, arr[i]);} set<int>::iterator it; for (it = nz.begin(); it != nz.end(); it++) { cout << *it << " "; } int ans = 0; while (nz.begin() != nz.end()) { int temp = tree->bsta(*(nz.begin())); int temp2 = tree->q(*(nz.begin()), temp-1); tree->up(*(nz.begin()), temp-1, temp2); ans++; } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...