-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path3152.cpp
More file actions
29 lines (26 loc) · 746 Bytes
/
3152.cpp
File metadata and controls
29 lines (26 loc) · 746 Bytes
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
class Solution {
public:
vector<bool> isArraySpecial(vector<int>& nums, vector<vector<int>>& queries) {
map<int, int> mp;
int start = 0;
int n = nums.size();
for (int i = 1; i < n; ++i) {
if (((nums[i - 1] & 1) ^ (nums[i] & 1)) == 0) {
mp[start] = i - 1;
start = i;
}
}
mp[start] = n - 1;
int m = queries.size();
vector<bool> res(m, false);
for (int j = 0; j < m; ++j) {
int a = queries[j][0];
int b = queries[j][1];
auto t = mp.upper_bound(a);
t--;
int end = t->second;
if (end >= b) res[j] = true;
}
return res;
}
};