#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);
}
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 < 1) {
root->upd(pos - k + 1 + n, n, -1);
root->upd(1, 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 time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
296 KB |
Output is correct |
3 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |