#include "plants.h"
#include <bits/stdc++.h>
using namespace std;
#define isz(a) ((signed)a.size())
const int N = 2e5 + 5;
int n, k;
int a[N];
namespace subtask1{
int checked = -1;
bool check(){
if (checked >= 0){
return checked;
}
return (checked = (k == 2));
}
pair <int, bool> pre[N], nxt[N];
void init(){
for (int turn = 0; turn < 2; turn++){
for (int i = 0; i < n; i++){
int j = (i + n - 1) % n;
if (a[(j + n - 1) % n] == a[j]){
pre[i] = pair{pre[j].first + 1, pre[j].second};
}
else{
pre[i] = pair{1, a[j] == 1 ? -1 : 1};
}
}
for (int i = n - 1; i >= 0; i--){
int j = (i + 1) % n;
if (a[(j + 1) % n] == a[j]){
nxt[i] = pair{nxt[j].first + 1, nxt[j].second};
}
else{
nxt[i] = pair{1, a[j] == 1 ? -1 : 1};
}
}
}
}
bool in_circular_range(int l, int r, int i){
if (l <= r){
return l <= i and i <= r;
}
else{
return r <= i or i <= l;
}
}
int solve(int x, int y){
if (in_circular_range(pre[x].first, x, y)){
return pre[x].second;
}
if (in_circular_range(x, nxt[x].first, y)){
return nxt[x].second;
}
return 0;
}
}
void init(int _k, vector <int> _a){
n = isz(_a);
k = _k;
for (int i = 0; i < n; i++){
a[i] = _a[i];
}
if (subtask1::check()){
subtask1::init();
}
return;
}
int compare_plants(int x, int y){
if (subtask1::check()){
return subtask1::solve(x, y);
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Incorrect |
1 ms |
308 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Incorrect |
1 ms |
308 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
312 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
264 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |