#include "plants.h"
#include <bits/stdc++.h>
using namespace std;
struct tree{
pair<int,int> mn;
tree *lc, *rc;
int l,r,lz = 0;
tree(int i, int j, vector<int> &a){
l = i, r = j;
if(l == r){
mn = {a[l], l};
lc = nullptr , rc = nullptr;
}else{
int m = (l + r) / 2;
lc = new tree(l, m, a), rc = new tree(m + 1, r, a);
mn = min(lc->mn, rc->mn);
}
}
void push(){
mn.first = max(mn.first - lz, 0);
if(l != r){
lc->lz += lz;
rc->lz += lz;
}
lz = 0;
}
void dec(int i, int j){
push();
if(i > j){
dec(0, j), dec(i, r);
return;
}else if(r < i || j < l) return;
else if(i <= l && r <= j){
lz++;
push();
}else{
lc->dec(i, j), rc->dec(i, j);
mn = min(lc->mn, rc->mn);
}
}
pair<int,int> qry(int i, int j){
push();
if(i > j) return min(qry(0, j), qry(i, r));
if(r < i || j < l) return {1e9, 1e9};
if(i <= l && r <= j) return mn;
return min(lc->qry(i,j), rc->qry(i,j));
}
void rem(int i){
push();
if(l == r){
mn.first = 1e9;
}else{
if(i <= lc->r) lc->rem(i);
else rc->rem(i);
mn = min(lc->mn, rc->mn);
}
}
};
vector<int> ans;
void init(int k, std::vector<int> r) {
int n = r.size();
ans.assign(n, -1);
tree *t = new tree(0, n - 1, r);
set<int> st;
for(int i = 0; i < n; i++) if(r[i] == 0){
st.insert(i);
}
for(int val = n - 1; val >= 0; val--){
vector<int> a;
for(int x: st){
a.push_back(x);
}
int x = -1;
for(int i = 0; i < a.size(); i++){
int prv = (i - 1 + a.size()) % a.size();
int d = (i == 0 ? a[i] + n - a[prv] : a[i] - a[prv]);
if(d >= k){
x = a[i];
}
}
t->dec((x - k + 1 + n) % n, (x - 1 + n) % n);
while(true){
auto [v, i] = t->qry((x - k + 1 + n) % n, (x - 1 + n) % n);
if(v != 0) break;
else{
t->rem(i);
st.insert(i);
}
}
ans[x] = val;
st.erase(x);
t->rem(x);
}
}
int compare_plants(int x, int y) {
if(ans[x] > ans[y]) return 1;
else return -1;
}
Compilation message
plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:76:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
76 | for(int i = 0; i < a.size(); i++){
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
Incorrect |
0 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 |
1 ms |
212 KB |
Output is correct |
3 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Incorrect |
44 ms |
5076 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |