#include <bits/stdc++.h>
#include "plants.h"
using namespace std;
#define fi first
const int nax=2e5+5;
set<pair<int,int>> st;
int tab[nax];
void init(int k, std::vector<int> r) {
int n=r.size();
for (int i = 0; i < n; ++i)
{
tab[i]=r[i];
if(r[i]==0&&r[(i+1)%n]==1){
st.insert({(i+1)%n,0});
}else if(r[i]==1&&r[(i+1)%n]==0){
st.insert({(i+1)%n,1});
}
}
return;
}
int compare_plants(int x, int y) {
if(st.size()==0){
return (tab[x]==1 ? 1 : -1);
}
pair<int,int> a=*st.upper_bound({x,1});
pair<int,int> b=(st.upper_bound({y,1}) != st.end() ? *st.upper_bound({y,1}): *st.begin());
if(a.fi<y&&b.fi<x){
return 0;
}else if(a.fi<y) return (tab[y]==1 ? 1 : -1);
else return (tab[x]==1 ? -1 : 1);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |