This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//In the name of God
#include <bits/stdc++.h>
#include "plants.h"
using namespace std;
typedef int ll;
typedef pair<ll, ll> pll;
const ll maxn = 2e5 + 100;
const ll mod = 1e9 + 7;
const ll inf = 1e9;
#define fast_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Mp make_pair
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define Sz(x) ll((x).size())
#define lc (id << 1)
#define rc (lc | 1)
ll n, k, a[maxn], b[maxn], l[maxn], r[maxn];
inline ll dis(ll i, ll j){
if(i <= j) return j - i;
return j - i + n;
}
inline ll val(ll i){
return (i % n + n) % n;
}
bool ok(ll i, ll j, ll k){
return dis(i, j) + dis(j, k) == dis(i, k);
}
void init(int K, vector<int> R){
k = K;
n = Sz(R);
ll yek = -1;
for(ll i = 0; i < n; i++){
a[i] = R[i];
if(a[i]) yek = i;
}
assert(~yek);
ll i = yek;
do{
if(a[i] == 0) r[i] = r[val(i + 1)];
else r[i] = i;
i = val(i - 1);
}while(i != yek);
do{
if(a[val(i - 1)] == 1) l[i] = l[val(i - 1)];
else l[i] = i;
i = val(i + 1);
}while(i != yek);
return;
}
int compare_plants(int x, int y){
if(ok(l[x], y, r[x])) return 1;
if(ok(l[y], x, r[y])) return -1;
return 0;
}
# | 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... |