D. Odd Queries

2024-04-03 01:20
文章标签 queries odd

本文主要是介绍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 a1,a2,…,an�1,�2,…,��. Answer q� queries of the following form:

  • If we change all elements in the range al,al+1,…,ar��,��+1,…,�� of the array to 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� (1≤t≤1041≤�≤104). The description of the test cases follows.

The first line of each test case consists of 22 integers n� and q� (1≤n≤2⋅1051≤�≤2⋅105; 1≤q≤2⋅1051≤�≤2⋅105) — the length of the array and the number of queries.

The second line of each test case consists of n� integers ai�� (1≤ai≤1091≤��≤109) — the array a�.

The next q� lines of each test case consists of 33 integers l,r,k�,�,� (1≤l≤r≤n1≤�≤�≤�; 1≤k≤1091≤�≤109) — the queries.

It is guaranteed that the sum of n� over all test cases doesn't exceed 2⋅1052⋅105, and the sum of q� doesn't exceed 2⋅1052⋅105.

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

input

Copy

 

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

output

Copy

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) would get set to 33 the array would become {2,3,3,3,2}{2,3,3,3,2}, the sum would be 2+3+3+3+2=132+3+3+3+2=13 which is odd, so the answer is "YES".
  • If the elements in the range (2,3)(2,3) would get set to 44 the array would become {2,4,4,3,2}{2,4,4,3,2}, the sum would be 2+4+4+3+2=152+4+4+3+2=15 which is odd, so the answer is "YES".
  • If the elements in the range (1,5)(1,5) would get set to 55 the array would become {5,5,5,5,5}{5,5,5,5,5}, the sum would be 5+5+5+5+5=255+5+5+5+5=25 which is odd, so the answer is "YES".
  • If the elements in the range (1,4)(1,4) would get set to 99 the array would become {9,9,9,9,2}{9,9,9,9,2}, the sum would be 9+9+9+9+2=389+9+9+9+2=38 which is even, so the answer is "NO".
  • If the elements in the range (2,4)(2,4) would get set to 33 the array would become {2,3,3,3,2}{2,3,3,3,2}, the sum would be 2+3+3+3+2=132+3+3+3+2=13 which is odd, so the answer is "YES".

解题说明:水题,根据题目意思直接求和累加进行判断即可。

#include<stdio.h>
int a[200005];
int main()
{int t;int n, q;int l, r, k;int sum = 0;int i, j, x;scanf("%d", &t);for (i = 1; i <= t; i++) {scanf("%d %d", &n, &q);for (j = 1; j <= n; j++) {scanf("%d", &x);a[j] = a[j - 1] + x;}for (j = 0; j < q; j++) {scanf("%d %d %d", &l, &r, &k);sum = (a[l - 1] - a[0]) + (a[n] - a[r]) + k * (r - l + 1);if (sum % 2 == 0){printf("NO\n");}else{printf("YES\n");}}}return 0;
}

这篇关于D. Odd Queries的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/871560

相关文章

【CodeForces】266E More Queries to Array... 线段树

E. More Queries to Array... time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standard output You've got an array, consisting of n

B. Ehab Is an Odd Person

B. Ehab Is an Odd Person You’re given an array a of length n. You can perform the following operation on it as many times as you want: Pick two integers i and j (1≤i,j≤n)(1≤i,j≤n) such that ai+aj is

《Efficient Batch Processing for Multiple Keyword Queries on Graph Data》——论文笔记

ABSTRACT 目前的关键词查询只关注单个查询。对于查询系统来说,短时间内会接受大批量的关键词查询,往往不同查询包含相同的关键词。 因此本文研究图数据多关键词查询的批处理。为多查询和单个查询找到最优查询计划都是非常复杂的。我们首先提出两个启发式的方法使关键词的重叠最大并优先处理规模小的关键词。然后设计了一个同时考虑了数据统计信息和搜索语义的基于cardinality的成本估计模型。 1.

Queries for Number of Palindromes

~~~~~~       Queries for Number of Palindromes ~~~~~      总题单链接 思路 ~~~~~       设 g [ L ] [ R ] g[L][R] g[L][R] 表示区间 [ L , R ] [L,R] [L,R] 是否为回文串。 ~~~~~      预处理 g g g,枚举回文串的中点,从每个中点开始向两侧扩展,判断

Leetcode 3275. K-th Nearest Obstacle Queries

Leetcode 3275. K-th Nearest Obstacle Queries 1. 解题思路2. 代码实现 题目链接:3275. K-th Nearest Obstacle Queries 1. 解题思路 这一题的话其实逻辑上非常简单,就是维护一个距离的有序数组,不断取第k大的元素即可。 不过好死不死的题目设置成只要这么干就一定超时,因此我们不得不想办法去优化算法复杂度,但说白

【CF245H】【Queries for Number of Palindromes】

H. Queries for Number of Palindromes time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standard output You've got a string s = s1s2...

实践 HTML5 的 CSS3 Media Queries

先来介绍下 media,确切的说应该是 CSS media queries(CSS 媒体查询),媒体查询包含了一个媒体类型和至少一个使用如宽度、高度和颜色等媒体属性来限制样式表范围的表达式。CSS3 加入的媒体查询使得无需修改内容便可以使样式应用于某些特定的设备范围。  那么该怎么定义 media 呢,看下面的代码,你肯定能猜出个大概。 <!-- link元素中的CSS媒体查询 --><li

【CF】1695D1-Tree Queries(Easy Version) 题解

传送门:1695D1 标签:动态规划 题目大意 给定一棵无根树,其中包含n个顶点。在树中隐藏了一个未知的顶点x,你需要通过查询来找出这个顶点。你可以进行k次查询,每次查询选择一个顶点v_i,在完成所有查询后,你会得到k个数字d_1, d_2, …, d_k,其中d_i表示从v_i到顶点x的最短路径上的边的数量。请注意,你知道每个距离对应哪个查询。请确定最小的k值,使得存在一些查询v_1, v_

ABC 368 G - Add and Multiply Queries

原题链接:G - Add and Multiply Queries 题意:给出数组a和b,三种操作,第一种:以 1 i x 的形式给出。用x替换ai​。第二种:以 2 i x 的形式给出。用x代替 bi​ 。第三种:以3 l r的形式给出,初始值为0,从l到r每个位置上可以选择加上a[i],或者乘上b[i],输出最大值。 思路:链表+set+树状数组+二分。题目中给出了答案的范围不会超过1e1

Add and Multiply Queries

题目链接:G - Add and Multiply Queries 区间修改+区间查询可以用线段树来做,但是这边介绍树状数组的写法。首先将a数组和b数组分开考虑,对于a数组,因为是加法运算求区间和,因此我们可以采用树状数组+差分来写,对于数组b,我们已知如果b[i] =  1 ,那么不如就进行加法运算,所以我们把b数组中大于1的数加入到一个set集合中,记住set记录的是位置,不是数值,然后可以