每日一题 第六十期 Codeforces Round 859 (Div. 4)

D. Odd Queries

time limit per test: 2 seconds

memory limit per test: 256 megabytes

input: standard input

output: standard output

You have an array a 1 , a 2 , … , a n a_1, a_2, \dots, a_n a1,a2,,an. Answer q q q queries of the following form:

  • If we change all elements in the range a l , a l + 1 , … , a r a_l, a_{l+1}, \dots, a_r al,al+1,,ar of the array to k k k, will the sum of the entire array be odd?

Note that queries are independent and do not affect future queries.

Input

Each test contains multiple test cases. The first line contains the number of test cases t t t ( 1 ≤ t ≤ 1 0 4 1 \le t \le 10^4 1t104). The description of the test cases follows.

The first line of each test case consists of 2 2 2 integers n n n and q q q ( 1 ≤ n ≤ 2 ⋅ 1 0 5 1 \le n \le 2 \cdot 10^5 1n2105; 1 ≤ q ≤ 2 ⋅ 1 0 5 1 \le q \le 2 \cdot 10^5 1q2105) — the length of the array and the number of queries.

The second line of each test case consists of n n n integers a i a_i ai ( 1 ≤ a i ≤ 1 0 9 1 \le a_i \le 10^9 1ai109) — the array a a a.

The next q q q lines of each test case consists of 3 3 3 integers l , r , k l,r,k l,r,k ( 1 ≤ l ≤ r ≤ n 1 \le l \le r \le n 1lrn; 1 ≤ k ≤ 1 0 9 1 \le k \le 10^9 1k109) — the queries.

It is guaranteed that the sum of n n n over all test cases doesn’t exceed 2 ⋅ 1 0 5 2 \cdot 10^5 2105, and the sum of q q q doesn’t exceed 2 ⋅ 1 0 5 2 \cdot 10^5 2105.

Output

For each query, output “YES” if the sum of the entire array becomes odd, and “NO” otherwise.

You can output the answer in any case (upper or lower). For example, the strings “yEs”, “yes”, “Yes”, and “YES” will be recognized as positive responses.

Example
inputCopy
2
5 5
2 2 1 3 2
2 3 3
2 3 4
1 5 5
1 4 9
2 4 3
10 5
1 1 1 1 1 1 1 1 1 1
3 8 13
2 5 10
3 8 10
1 10 2
1 9 100
outputCopy
YES
YES
YES
NO
YES
NO
NO
NO
NO
YES

Note

For the first test case:

  • If the elements in the range ( 2 , 3 ) (2, 3) (2,3) would get set to 3 3 3 the array would become { 2 , 3 , 3 , 3 , 2 } \{2, 3, 3, 3, 2\} {2,3,3,3,2}, the sum would be 2 + 3 + 3 + 3 + 2 = 13 2+3+3+3+2 = 13 2+3+3+3+2=13 which is odd, so the answer is “YES”.
  • If the elements in the range ( 2 , 3 ) (2, 3) (2,3) would get set to 4 4 4 the array would become { 2 , 4 , 4 , 3 , 2 } \{2, 4, 4, 3, 2\} {2,4,4,3,2}, the sum would be 2 + 4 + 4 + 3 + 2 = 15 2+4+4+3+2 = 15 2+4+4+3+2=15 which is odd, so the answer is “YES”.
  • If the elements in the range ( 1 , 5 ) (1, 5) (1,5) would get set to 5 5 5 the array would become { 5 , 5 , 5 , 5 , 5 } \{5, 5, 5, 5, 5\} {5,5,5,5,5}, the sum would be 5 + 5 + 5 + 5 + 5 = 25 5+5+5+5+5 = 25 5+5+5+5+5=25 which is odd, so the answer is “YES”.
  • If the elements in the range ( 1 , 4 ) (1, 4) (1,4) would get set to 9 9 9 the array would become { 9 , 9 , 9 , 9 , 2 } \{9, 9, 9, 9, 2\} {9,9,9,9,2}, the sum would be 9 + 9 + 9 + 9 + 2 = 38 9+9+9+9+2 = 38 9+9+9+9+2=38 which is even, so the answer is “NO”.
  • If the elements in the range ( 2 , 4 ) (2, 4) (2,4) would get set to 3 3 3 the array would become { 2 , 3 , 3 , 3 , 2 } \{2, 3, 3, 3, 2\} {2,3,3,3,2}, the sum would be 2 + 3 + 3 + 3 + 2 = 13 2+3+3+3+2 = 13 2+3+3+3+2=13 which is odd, so the answer is “YES”.

AC代码:

#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<queue>
#include<string>
#include<bitset>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<numeric>
#include<iomanip>
#define endl '\n'
using namespace std;

typedef long long ll;
typedef pair<int, int>PII;
const int N=3e5+10;
const int MOD=1e9 + 7;
const int INF=0X3F3F3F3F;
const int dx[]={-1,1,0,0,-1,-1,+1,+1};
const int dy[]={0,0,-1,1,-1,+1,-1,+1};
const int M = 1e6 + 10;

int t;
int n, q;
int a[N];
ll s[N];
int main()
{
	cin >> t;
	while(t --){
		cin >> n >> q;
		int flag = 0;
		for(int i = 1; i <= n; i ++)
		{
			cin >> a[i];
			s[i] = s[i - 1] + a[i];
		}
		if(s[n] & 1) flag = 1;
		while(q --){
			int l, r, k;
			cin >> l >> r >> k;
			ll res = abs(s[r] - s[l - 1] - k * (l - r  +1));
			if((res & 1 && flag == 1) || (res % 2 == 0 && flag == 0) ) puts("NO");
			else puts("YES");
		}
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值