#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
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 |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
103 ms |
3192 KB |
Output is correct |
7 |
Correct |
244 ms |
3960 KB |
Output is correct |
8 |
Correct |
324 ms |
9848 KB |
Output is correct |
9 |
Correct |
339 ms |
9848 KB |
Output is correct |
10 |
Correct |
348 ms |
9980 KB |
Output is correct |
11 |
Correct |
362 ms |
9848 KB |
Output is correct |
12 |
Correct |
370 ms |
9976 KB |
Output is correct |
13 |
Correct |
352 ms |
9848 KB |
Output is correct |
14 |
Correct |
353 ms |
9848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Incorrect |
0 ms |
256 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
103 ms |
3192 KB |
Output is correct |
7 |
Correct |
244 ms |
3960 KB |
Output is correct |
8 |
Correct |
324 ms |
9848 KB |
Output is correct |
9 |
Correct |
339 ms |
9848 KB |
Output is correct |
10 |
Correct |
348 ms |
9980 KB |
Output is correct |
11 |
Correct |
362 ms |
9848 KB |
Output is correct |
12 |
Correct |
370 ms |
9976 KB |
Output is correct |
13 |
Correct |
352 ms |
9848 KB |
Output is correct |
14 |
Correct |
353 ms |
9848 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |