This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "plants.h"
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
int val[400010],tree[1600000],n;
void init(int node,int a,int b){
  if(a==b){
    tree[node]=val[a];
    return;
  }
  int mid=(a+b)/2;
  init(2*node+1,a,mid);
  init(2*node+2,mid+1,b);
  if(tree[2*node+1]==tree[2*node+2]){
    if(tree[2*node+1]==-1) tree[node]=-1;
    else tree[node]=tree[2*node+1];
  }
  else{
    tree[node]=-1;
  }
}
int query(int node,int a,int b,int l,int r){
  if(a>r or b<l) return -2;
  if(l<=a and b<=r) return tree[node];
  int mid=(a+b)/2;
  int le=query(2*node+1,a,mid,l,r);
  int ri=query(2*node+2,mid+1,b,l,r);
  if(le==-2 || ri==-2){
    if(le==-2) return ri;
    else return le;
  }
  if(le==ri){
    if(le==-1) return -1;
    else return le;
  }
  else return -1;
}
void init(int k, std::vector<int> r) {
  int j=0;
  for(int i=0;i<r.size();i++){
    val[j]=r[i];
    //cout<<val[j]<<" ";
    j++;
  }
  for(int i=0;i<r.size();i++){
    val[j]=r[i];
    // cout<<val[j]<<" ";
    j++;
  }
  //cout<<j<<endl;
  n=j;
  init(0,0,n-1);
}
int compare_plants(int x, int y) {
  int o1,o2;
  int l1,l2;
  int aux=n/2;
  l1=((y-x)+aux)%aux;
  l2=((x-y)+aux)%aux;
  l1+=x;
  l2+=y;
  o1=query(0,0,n-1,x,l1-1);
  o2=query(0,0,n-1,y,l2-1);
  //cout<<o1<<" "<<o2<<" "<<x<<" - "<<l1<<" "<<y<<" - "<<l2<<endl;
  if(o1==o2 and o1==-1){
    return 0;
  }
  if(o1!=-1){
    if(o1==1) return -1;
    else return 1;
  }
  if(o2!=-1){
    if(o2==1) return 1;
    else return -1;
  }
}
Compilation message (stderr)
plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:40:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |   for(int i=0;i<r.size();i++){
      |               ~^~~~~~~~~
plants.cpp:45:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |   for(int i=0;i<r.size();i++){
      |               ~^~~~~~~~~
plants.cpp: In function 'int compare_plants(int, int)':
plants.cpp:77:1: warning: control reaches end of non-void function [-Wreturn-type]
   77 | }
      | ^| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |