#include "plants.h"
#include "bits/stdc++.h"
using namespace std;
#define ar array
typedef long long ll;
//~ #define int ll
const int inf = 1e9;
const int N = 2e5 + 5;
struct ST{
ar<int, 2> tree[N << 2];
int f[N << 2];
void build(int lx, int rx, int x){
if(lx == rx) { tree[x][1] = lx; return; };
int m = (lx + rx) >> 1;
build(lx, m, x << 1), build(m + 1, rx, x << 1 | 1);
tree[x][1] = lx;
}
ST(){
build(0, N, 1);
}
void push(int x, int lx, int rx){
if(lx == rx) return;
tree[x << 1][0] += f[x];
tree[x << 1 | 1][0] += f[x];
f[x << 1] += f[x], f[x << 1 | 1] += f[x];
f[x] = 0;
}
void add(int l, int r, int v, int lx, int rx, int x){
if(lx > r || rx < l) return;
if(lx >= l && rx <= r){
tree[x][0] += v;
f[x] += v;
return;
}
push(x, lx, rx);
int m = (lx + rx) >> 1;
add(l, r, v, lx, m, x << 1), add(l, r, v, m + 1, rx, x << 1 | 1);
tree[x] = min(tree[x << 1], tree[x << 1 | 1]);
}
void add(int l, int r, int v) { return add(l, r, v, 0, N, 1); }
ar<int, 2> get(int l, int r, int lx, int rx, int x){
if(lx > r || rx < l) return {inf, inf};
if(lx >= l && rx <= r) return tree[x];
push(x, lx, rx);
int m = (lx + rx) >> 1;
return min(get(l, r, lx, m, x << 1), get(l, r, m + 1, rx, x << 1 | 1));
}
ar<int, 2> get(int l, int r){
return get(l, r, 0, N, 1);
}
}tree;
vector<int> a;
int n;
void init(int k, vector<int> r) {
n = r.size();
a.resize(n);
{
int cnt = 0;
for(int i=0;i<k - 1;i++) cnt += (r[i] == 0);
for(int i=k - 1;;){
tree.add(i, i, r[i] + cnt);
cnt -= (r[(i + n - k + 1) % n] == 0);
cnt += (r[i] == 0);
i = (i + 1) % n;
if(i == k - 1) break;
}
}
for(int j=n;j>0;j--){
//~ for(int i=0;i<n;i++) cout<<tree.get(i, i)[0]<<" ";
//~ cout<<"\n";
int p = tree.get(0, n - 1)[1];
a[p] = j;
tree.add(p, p, inf);
{
int l = p - k + 1, r = p;
tree.add(max(l, 0), r, -1);
if(l < 0) tree.add(n + l, n - 1, -1);
}
{
int l = p, r = p + k - 1;
tree.add(l, min(r, n - 1), -1);
if(n <= r) tree.add(0, r - n, -1);
}
}
//~ for(int i=0;i<n;i++) cout<<a[i]<<" ";
//~ cout<<"\n";
return;
}
int compare_plants(int x, int y) {
if(a[x] > a[y]) return 1;
if(a[x] < a[y]) return -1;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4436 KB |
Output is correct |
2 |
Correct |
2 ms |
4436 KB |
Output is correct |
3 |
Correct |
2 ms |
4436 KB |
Output is correct |
4 |
Incorrect |
3 ms |
4436 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4436 KB |
Output is correct |
2 |
Correct |
3 ms |
4436 KB |
Output is correct |
3 |
Correct |
2 ms |
4384 KB |
Output is correct |
4 |
Correct |
2 ms |
4436 KB |
Output is correct |
5 |
Incorrect |
3 ms |
4436 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4436 KB |
Output is correct |
2 |
Correct |
3 ms |
4436 KB |
Output is correct |
3 |
Correct |
2 ms |
4384 KB |
Output is correct |
4 |
Correct |
2 ms |
4436 KB |
Output is correct |
5 |
Incorrect |
3 ms |
4436 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4436 KB |
Output is correct |
2 |
Correct |
2 ms |
4436 KB |
Output is correct |
3 |
Incorrect |
48 ms |
7148 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4436 KB |
Output is correct |
2 |
Correct |
2 ms |
4436 KB |
Output is correct |
3 |
Incorrect |
2 ms |
4436 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4436 KB |
Output is correct |
2 |
Correct |
2 ms |
4436 KB |
Output is correct |
3 |
Incorrect |
2 ms |
4436 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4436 KB |
Output is correct |
2 |
Correct |
2 ms |
4436 KB |
Output is correct |
3 |
Correct |
2 ms |
4436 KB |
Output is correct |
4 |
Incorrect |
3 ms |
4436 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |