Algorithm
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include <bits/stdc++.h>
using namespace std;
int const N = 2e5 + 1;
int n, m, a[N], pos, neg, l, r;
int main() {
scanf("%d %d", &n, &m);
for(int i = 0; i < n; ++i) {
scanf("%d", a + i);
if(a[i] == 1)
++pos;
else
++neg;
}
for(int i = 0; i < m; ++i) {
scanf("%d %d", &l, &r);
int diff = r - l + 1;
if(diff % 2 == 1)
puts("0");
else {
if(diff / 2 <= pos && diff / 2 <= neg)
puts("1");
else
puts("0">;
}
}
return 0;
}
Copy The Code &
Try With Live Editor
Input
2 3
1 -1
1 1
1 2
2 2
1 -1
1 1
1 2
2 2
Output
0
1
0
1
0
Demonstration
Codeforces Solution-Eugeny and Array-Solution in C, C++, Java, Python