# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
306493 | giorgikob | Comparing Plants (IOI20_plants) | C++14 | 0 ms | 0 KiB |
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 <cstdio>
#include <cassert>
#include <vector>
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
using namespace std;
static int k, q;
static std::vector<int> r;
static std:: vector<int> x;
static std:: vector<int> y;
static std:: vector<int> answer;
vector<int>v;
int n;
void init(int k, std::vector<int> r) {
n = r.size();
if(k == 2){
v = r;
}
return;
}
bool check(int x,int y){
for(int i = x; i != y; i--){
if(v[i] != 1){
return false;
}
if(i == 0) i = n;
}
return true;
}
int compare_plants(int x, int y) {
if(check((x-1+n)%n,(y-1+n)%n)) return 1;
if(check((y-1+n)%n,(x-1+n)%n)) return -1;
return 0;
}
int main() {
assert(scanf("%d%d%d", &n, &k, &q) == 3);
r.resize(n);
answer.resize(q);
for (int i = 0; i < n; i++) {
int value;
assert(scanf("%d", &value) == 1);
r[i] = value;
}
x.resize(q);
y.resize(q);
for (int i = 0; i < q; i++) {
assert(scanf("%d%d", &x[i], &y[i]) == 2);
}
fclose(stdin);
init(k, r);
for (int i = 0; i < q; i++) {
answer[i] = compare_plants(x[i], y[i]);
}
for (int i = 0; i < q; i++) {
printf("%d\n", answer[i]);
}
fclose(stdout);
return 0;
}