#include "plants.h"
#include <bits/stdc++.h>
using namespace std;
constexpr int maxn = 1<<19;
int n, k;
struct SegmentTree {
int tree[maxn], lazy[maxn];
void flush(int node, int i, int j) {
if(!lazy[node]) return;
if(i != j) {
lazy[node<<1] += lazy[node];
lazy[node<<1|1] += lazy[node];
}
tree[node] += lazy[node];
lazy[node] = 0;
}
void build(int node, int i, int j, const vector<int>& r) {
if(i == j) return (void)(tree[node] = r[i]);
int m = (i+j) >> 1;
build(node<<1, i, m, r);
build(node<<1|1, m+1, j, r);
tree[node] = min(tree[node<<1], tree[node<<1|1]);
}
int find(int l, int r) {
if(l <= r) return find(1, 0, n-1, l, r);
int p1 = find(1, 0, n-1, l, n-1);
if(p1 != -1) return p1;
return find(1, 0, n-1, 0, r);
}
int find(int node, int i, int j, int l, int r) {
flush(node, i, j);
if(tree[node] > 0 || i > r || j < l) return -1;
if(i == j) return i;
int m = (i+j) >> 1;
int p1 = find(node<<1, i, m, l, r);
if(p1 != -1) return p1;
return find(node<<1|1, m+1, j, l, r);
}
void upd(int l, int r, int v) {
if(l <= r) upd(1, 0, n-1, l, r, v);
else upd(1, 0, n-1, l, n-1, v), upd(1, 0, n-1, 0, r, v);
}
void upd(int node, int i, int j, int l, int r, int v) {
flush(node, i, j);
if(i > r || j < l) return;
if(i >= l && j <= r) {
lazy[node] = v;
flush(node, i, j);
return;
}
int m = (i+j) >> 1;
upd(node<<1, i, m, l, r, v);
upd(node<<1|1, m+1, j, l, r, v);
tree[node] = min(tree[node<<1], tree[node<<1|1]);
}
} seg;
int ordem[maxn];
void init(int K, std::vector<int> r) {
n = (int)(r.size());
k = K;
seg.build(1, 0, n-1, r);
for(int i = 0; i < n; i++) {
int mn = seg.find(0, n-1);
mn = seg.find((mn - k + 1 + n) % n, mn); // se tiver algum outro cara maximo para a frente dele mas ele estiver olhando pra mim
ordem[mn] = i;
seg.upd((mn - k + 1 + n) % n, mn, -1); // removo 1 de todo mundo antes de mim
seg.upd(1, 0, n-1, mn, mn, 0x3f3f3f3f);
}
}
int compare_plants(int x, int y) {
return ordem[x] < ordem[y] ? 1 : -1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
3 ms |
340 KB |
Output is correct |
7 |
Correct |
54 ms |
3328 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
51 ms |
3276 KB |
Output is correct |
11 |
Correct |
49 ms |
3180 KB |
Output is correct |
12 |
Correct |
52 ms |
3456 KB |
Output is correct |
13 |
Correct |
52 ms |
3324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
3 ms |
340 KB |
Output is correct |
7 |
Correct |
54 ms |
3328 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
51 ms |
3276 KB |
Output is correct |
11 |
Correct |
49 ms |
3180 KB |
Output is correct |
12 |
Correct |
52 ms |
3456 KB |
Output is correct |
13 |
Correct |
52 ms |
3324 KB |
Output is correct |
14 |
Correct |
72 ms |
3800 KB |
Output is correct |
15 |
Correct |
332 ms |
9108 KB |
Output is correct |
16 |
Correct |
70 ms |
6096 KB |
Output is correct |
17 |
Correct |
336 ms |
12876 KB |
Output is correct |
18 |
Correct |
237 ms |
12408 KB |
Output is correct |
19 |
Correct |
228 ms |
12864 KB |
Output is correct |
20 |
Correct |
342 ms |
12892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
50 ms |
3172 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |