#include "plants.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void debug_out(){cerr<<endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
cerr << H << ' ';
debug_out(T...);
}
#define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", debug_out(__VA_ARGS__)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)
const int maxn = 2e5 + 10;
const int inf = 1e6;
int n, k, a[maxn], val[maxn], seg[maxn << 2][2], lazy[maxn << 2][2];
void shift(int v, int x, int l, int r);
void add(int v, int x, int l, int r, int ql, int qr, int val){
//if (v == 1) debug(ql, qr, val);
if (qr <= l || r <= ql) return;
if (ql <= l && r <= qr){
// debug(l, r, ql, qr, val);
seg[v][x] += val;
lazy[v][x] += val;
return;
}
shift(v, x, l, r);
int mid = (l + r) >> 1;
add(v << 1, x, l, mid, ql, qr, val);
add(v << 1 | 1, x, mid, r, ql, qr, val);
seg[v][x] = min(seg[v<<1][x], seg[v<<1|1][x]);
}
int find0(int v, int x, int l, int r){
if (seg[v][x] != 0) return -1;
if (l + 1 == r) return l;
shift(v, x, l, r);
int mid = (l + r) >> 1;
int res = find0(v << 1, x, l, mid);
if (res == -1) return find0(v << 1 | 1, x, mid, r);
return res;
}
void shift(int v, int x, int l, int r){
if (lazy[v][x] == 0) return;
int mid = (l + r) >> 1;
add(v << 1, x, l, mid, l, mid, lazy[v][x]);
add(v << 1 | 1, x, mid, r, mid, r, lazy[v][x]);
lazy[v][x] = 0;
}
void init(int _k, std::vector<int> r) {
n = r.size();
k = _k;
for (int i = 0; i < n; i++){
a[i] = r[i];
add(1, 0, 0, n, i, i+1, a[i]);
add(1, 1, 0, n, i, i+1, a[i]);
}
vector<int> topol;
for (int i = 0; i < n; i++){
int tmp;
while((tmp = find0(1, 1, 0, n)) != -1){
//debug(tmp);
add(1, 0, 0, n, tmp+1, tmp+k, 1);
if (tmp+k > n){
add(1, 0, 0, n, 0, tmp+k-n, 1);
}
add(1, 1, 0, n, tmp, tmp+1, inf);
}
tmp = find0(1, 0, 0, n);
// debug(tmp);
add(1, 0, 0, n, tmp+1, tmp+k, -1);
if (tmp+k > n){
add(1, 0, 0, n, 0, tmp+k-n, -1);
}
add(1, 0, 0, n, tmp-k+1, tmp, -1);
add(1, 1, 0, n, tmp-k+1, tmp, -1);
if (tmp-k+1 < 0){
add(1, 0, 0, n, tmp-k+1+n, n, -1);
add(1, 1, 0, n, tmp-k+1+n, n, -1);
}
assert(tmp != -1);
topol.push_back(tmp);
val[tmp] = n-i;
add(1, 0, 0, n, tmp, tmp+1, inf);
}
k = _k;
}
int compare_plants(int x, int y) {
return (val[x] > val[y]? 1: -1);
return 0;
}
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
308 KB |
Output is correct |
6 |
Correct |
4 ms |
468 KB |
Output is correct |
7 |
Correct |
55 ms |
5440 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
4 ms |
412 KB |
Output is correct |
10 |
Correct |
55 ms |
5344 KB |
Output is correct |
11 |
Correct |
51 ms |
5344 KB |
Output is correct |
12 |
Correct |
52 ms |
5472 KB |
Output is correct |
13 |
Correct |
54 ms |
5344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
308 KB |
Output is correct |
6 |
Correct |
4 ms |
468 KB |
Output is correct |
7 |
Correct |
55 ms |
5440 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
4 ms |
412 KB |
Output is correct |
10 |
Correct |
55 ms |
5344 KB |
Output is correct |
11 |
Correct |
51 ms |
5344 KB |
Output is correct |
12 |
Correct |
52 ms |
5472 KB |
Output is correct |
13 |
Correct |
54 ms |
5344 KB |
Output is correct |
14 |
Correct |
106 ms |
6796 KB |
Output is correct |
15 |
Correct |
849 ms |
18756 KB |
Output is correct |
16 |
Correct |
105 ms |
6780 KB |
Output is correct |
17 |
Correct |
842 ms |
18800 KB |
Output is correct |
18 |
Correct |
591 ms |
18176 KB |
Output is correct |
19 |
Correct |
574 ms |
18628 KB |
Output is correct |
20 |
Correct |
739 ms |
18900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
44 ms |
4896 KB |
Output is correct |
4 |
Correct |
473 ms |
17728 KB |
Output is correct |
5 |
Correct |
566 ms |
17960 KB |
Output is correct |
6 |
Correct |
673 ms |
18436 KB |
Output is correct |
7 |
Correct |
776 ms |
18532 KB |
Output is correct |
8 |
Correct |
837 ms |
18780 KB |
Output is correct |
9 |
Correct |
508 ms |
17936 KB |
Output is correct |
10 |
Correct |
509 ms |
18108 KB |
Output is correct |
11 |
Correct |
427 ms |
16712 KB |
Output is correct |
12 |
Correct |
488 ms |
18004 KB |
Output is correct |
13 |
Correct |
595 ms |
18016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
- |
# |
Verdict |
Execution time |
Memory |
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 |
- |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |