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>
#pragma GCC optimize("Ofast")
#define fs first
#define sc second
#define p_q priority_queue
using namespace std;
int n;
set<pair<int,int> > s;
void init(int K, vector<int> r) {
n=r.size();
for(int i=0;i<n;i++){
int al=(i-1+n)%n,ar=(i+1)%n;
if(r[al]!=r[i]){
if(r[al]==0){
s.insert({i,0});
}
else{
s.insert({i,1});
}
cout << i << "\n";
}
}
}
pair<pair<int,int>,pair<int,int> > get(int r){
auto z=s.lower_bound({r,-1});
if(z==s.end()){
z=s.begin();
}
if(z->fs==r){
return {*z,*z};
}
else{
auto b=z;
if(z==s.begin()){
b=prev(s.end());
}
else{
b=prev(z);
}
return {*b,*z};
}
}
pair<int,int> nxt(pair<int,int> a){
auto b=s.upper_bound(a);
if(b==s.end()){
b=s.begin();
}
return *b;
}
int compare_plants(int x, int y) {
auto c=get(x),d=get(y);
if(c.fs==c.sc && d.fs==d.sc){
if((nxt(c.fs)==d.fs)){
if(c.fs.sc==1){
return 1;
}
else{
return -1;
}
return 1;
}
else if((nxt(d.fs)==c.fs)){
if(c.fs.sc==1){
return 1;
}
else{
return -1;
}
return 1;
}
else{
return 0;
}
}
else if(c.fs==d.fs || c.sc==d.sc){
if(c.fs==c.sc){
if(c.fs.sc==1){
return 1;
}
else{
return -1;
}
}
else if(d.fs==d.sc){
if(d.fs.sc==1){
return -1;
}
else{
return 1;
}
}
else{
int u=(c.sc.fs-x+n)%n;
int v=(c.sc.fs-y+n)%n;
if((c.sc.sc==1) == (v>u)){
return 1;
}
else{
return -1;
}
}
}
else{
return 0;
}
}
Compilation message (stderr)
plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:14:26: warning: unused variable 'ar' [-Wunused-variable]
14 | int al=(i-1+n)%n,ar=(i+1)%n;
| ^~
# | 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... |