Submission #837339

#TimeUsernameProblemLanguageResultExecution timeMemory
837339pavementComparing Plants (IOI20_plants)C++17
27 / 100
4059 ms32452 KiB
#include "plants.h" #include <bits/stdc++.h> using namespace std; #define mp make_pair using ii = pair<int, int>; int n; vector<int> r, h; struct node { node *left, *right; int S, E, pv; ii val; node(int _s, int _e) : S(_s), E(_e), pv(0) { if (S == E) { val = mp(r[S], S); return; } int M = (S + E) / 2; left = new node(S, M); right = new node(M + 1, E); val = min(left->val, right->val); } void prop() { if (S == E || !pv) { return; } left->val.first += pv; left->pv += pv; right->val.first += pv; right->pv += pv; pv = 0; } void upd(int l, int r, int v) { if (l > E || r < S) { return; } if (l <= S && E <= r) { val.first += v; pv += v; return; } prop(); left->upd(l, r, v); right->upd(l, r, v); val = min(left->val, right->val); } } *root; void init(int k, vector<int> r) { n = (int)r.size(); ::r = r; h.resize(n); root = new node(0, n - 1); set<int> zeroes; for (int i = n - 1; i >= 0; i--) { while (root->val.first == 0) { int cur_pos = root->val.second; zeroes.insert(cur_pos); root->upd(cur_pos, cur_pos, (int)1e9); } assert(!zeroes.empty()); int prv = *zeroes.rbegin(), pos = -1; for (int j : zeroes) { int dist = j - prv; if (dist < 0) { dist += n; } if (j == prv || dist >= k) { pos = j; zeroes.erase(j); break; } prv = j; } assert(pos != -1); h[pos] = i; if (pos - k + 1 < 0) { root->upd(pos - k + 1 + n, n - 1, -1); root->upd(0, pos - 1, -1); } else { root->upd(pos - k + 1, pos - 1, -1); } } } int compare_plants(int x, int y) { return (h[x] < h[y] ? -1 : 1); }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...