#include<bits/stdc++.h>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
using namespace std;
const int N = 4e5 + 10;
int s[2][N], a[N];
int n;
void init (int k, vector<int> r) {
n = r.size();
k--;
for(int i = 1; i <= n; i++) a[i] = a[i + n] = r[i - 1];
for(int i = 1; i <= n * 2; i++) {
s[0][i] = s[0][i - 1] + (a[i] == 0);
s[1][i] = s[1][i - 1] + (a[i] == 1);
}
}
int check (int l, int r) {
int s0 = s[0][r - 1] - s[0][l - 1];
int s1 = s[1][r - 1] - s[1][l - 1];
if (s0 && s1) return 0;
if (s0) return 1;
return -1;
}
int compare_plants(int x, int y) {
x++; y++;
int tmp;
tmp = check(x, y);
if (tmp) return tmp;
tmp = check(y, x + n);
if (tmp) return -tmp;
return 0;
}
#ifdef ngu
int main() {
freopen ("task.inp", "r", stdin);
freopen ("task.out", "w", stdout);
int n, k, q; cin >> n >> k >> q;
vector<int> r(n);
for(int i = 0; i < n; i++) cin >> r[i];
init(k, r);
while (q--) {
int x, y; cin >> x >> y;
cout << compare_plants(x, y) << endl;
}
}
#endif // ngu
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
38 ms |
4048 KB |
Output is correct |
7 |
Correct |
43 ms |
5968 KB |
Output is correct |
8 |
Correct |
62 ms |
11748 KB |
Output is correct |
9 |
Correct |
66 ms |
11860 KB |
Output is correct |
10 |
Correct |
57 ms |
11856 KB |
Output is correct |
11 |
Correct |
62 ms |
11856 KB |
Output is correct |
12 |
Correct |
56 ms |
11876 KB |
Output is correct |
13 |
Correct |
54 ms |
11860 KB |
Output is correct |
14 |
Correct |
60 ms |
11972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
1 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 |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
1 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 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
38 ms |
4048 KB |
Output is correct |
7 |
Correct |
43 ms |
5968 KB |
Output is correct |
8 |
Correct |
62 ms |
11748 KB |
Output is correct |
9 |
Correct |
66 ms |
11860 KB |
Output is correct |
10 |
Correct |
57 ms |
11856 KB |
Output is correct |
11 |
Correct |
62 ms |
11856 KB |
Output is correct |
12 |
Correct |
56 ms |
11876 KB |
Output is correct |
13 |
Correct |
54 ms |
11860 KB |
Output is correct |
14 |
Correct |
60 ms |
11972 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |