-
Notifications
You must be signed in to change notification settings - Fork 0
/
302A.cc
129 lines (129 loc) · 3.66 KB
/
302A.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define cint const int
#define fo(number1, number2, number3) for (int number1 = number2; number1 < number3; ++number1)
#define rfo(number1, number2, number3) for (int number1 = number2 - 1; number1 >= number3; --number1)
#define pi pair<int, int>
#define vLL vector<ll>
#define vi vector<int>
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define lbd lower_bound
#define ubd upper_bound
#define mp make_pair
#define cps CLOCKS_PER_SEC
#define decimal(k) fixed << setprecision(k)
#define PI 3.14159265359
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define ff first
#define ss second
#define all(V) (V).begin(), (V).end()
#define alla(a, n) a, a + n
#define sz(v) (ll) v.size()
#define SORT(v) sort(all(v))
#define REV reverse
#define SUM(v) accumulate(v.begin(), v.end(), 0)
#define MAX max_element
#define MIN min_element
#define UNIQUE(v) \
SORT(v); \
v.erase(unique(v.begin(), v.end()), v.end())
#define UNIQUEA(a, n) unique(a, a + n) - a
#define MAXA(a, n) max_element(a, a + n)
#define MINA(a, n) min_element(a, a + n)
#define SORTA(a, n) sort(alla(a, n))
#define REVA(a, n) reverse(alla(a, n))
#define mem1(a) memset(a, -1, sizeof(a));
#define mem0(a) memset(a, 0, sizeof(a));
#define mymax 1000000000000000100
#define mymin -1000000001
#define bitcount __builtin_popcount
#define gcd __gcd
#define MOD (ll)1000000007
#define TEST(t) \
int tc; \
cin >> tc; \
fo(t, 1, tc)
#define VECT(v, n) \
ll n; \
cin >> n; \
vLL v(n); \
fo(i, 0, n - 1) cin >> v[i];
#define NUM(n) \
ll n; \
cin >> n;
#define STRING(s) \
string s; \
cin >> s;
#define TS to_string
#define len(s) (s).length()
#define line cout << "\n";
#define el "\n"
#define vec vector<int>
#define clkstart auto start = high_resolution_clock::now();
#define clkend \
auto stop = high_resolution_clock::now(); \
auto duration = duration_cast<microseconds>(stop - start);
#define TIME \
line; \
line; \
cout << "Time taken by function: " << duration.count() / 1e6 << " seconds" << endl;
#define open {
#define close }
#define goog(tno) cout << "Case #" << tno << ": "
#define deb(x) cout << #x << " = " << x << el;
#define deb2(x, y) cout << #x << " = " << x << " : " << #y << " = " << y << el;
// #ifndef SEGMENTTREE_H
#define SEGMENTTREE_H
#define left(i) (2 * i + 1)
#define right(i) (2 * i + 2)
#define parent(i) ((i - 1) / 2)
using namespace std;
// bool is_perfect_square(ll n) {
// if (n < 0)
// return false;
// ll root(round(sqrt(n)));
// return n == root * root;
// }
// bool isPrime(ll N) { // a good enough deterministic prime tester
// if (N <= _sieve_size) return bs[N]; // O(1) for small primes
// for (int i = 0; i < (int)primes.size(); i++)
// if (N % primes[i] == 0) return false;
// return true; // it takes longer time if N is a large prime!
// }
int main()
{
fastio
ll n,
m, c1 = 0, c0 = 0;
cin >> n >> m;
vLL v(n);
for (auto &i : v)
{
cin >> i;
if (i == 1)
c1++;
else
c0++;
}
while (m--)
{
ll a, b;
cin >> a >> b;
if (a == b || c1 == 0 || c0 == 0)
cout << "0" << endl;
else if ((b - a + 1) % 2 != 0)
cout << "0" << endl;
else if ((b - a + 1) <= 2 * min(c1, c0))
{
cout << "1" << endl;
}
else
cout << "0" << endl;
}
}