#include "plants.h"
static std:: vector<int> inc,dec,rank;
static int l,m;
// void print(std::vector<int> &v) {for(int elem: v) std::cout << elem << " "; std::cout << std::endl;}
int findMax(int k, std::vector<int> &r) {
int i=2*m-1;
while (r[i%m]!=0) {i--;}
// std::cout << i << std::endl;
int j = i-1;
while (j > i-k) {
if (r[j%m]==0) i = j;
j--;
}
for(int j=i; j>i-k; j--) r[j%m]--;
// std::cout << i%n << std::endl;
// print(r);
return i%m;
}
void init2(int k, std::vector<int> r) {
n = r.size();
rank.resize(n);
for(int i=n-1; i>=0; i--) {
rank[findMax(k,r)] = i;
// print(rank);
}
return;
}
int compare_plants2(int x, int y) {
if (rank[x]>rank[y]) return 1;
else return -1;
}
void init1(int k, std::vector<int> r) {
int n = r.size();
inc.resize(n); dec.resize(n);
for(int i=0; i<n; i++) {inc[i] = dec[i] = i;}
int s,incVal,decVal;
for(s=2*n-1; s>=0; s--) {
if (r[s%n]==0) incVal = s;
else decVal = s;
inc[s%n] = incVal; dec[s%n] = decVal;
}
return;
}
int compare_plants1(int x, int y) {
if (y <= dec[x] or x+n <= inc[y]) return 1;
else if (y <= inc[x] or x+n <= dec[y]) return -1;
return 0;
}
void init(int k, std::vector<int> r) {
int n = r.size();
m=n; l=k;
if(k==2) init1(k, r);
if(n<=5000 and 2*k>n) init2(k, r);
return;
}
int compare_plants(int x, int y) {
if(l==2) return compare_plants1(x,y);
if(m<=5000 and 2*l>m) return compare_plants2(x,y);
return 0;
}
Compilation message
plants.cpp: In function 'void init2(int, std::vector<int>)':
plants.cpp:21:5: error: 'n' was not declared in this scope
21 | n = r.size();
| ^
plants.cpp: In function 'int compare_plants1(int, int)':
plants.cpp:46:26: error: 'n' was not declared in this scope
46 | if (y <= dec[x] or x+n <= inc[y]) return 1;
| ^