B. Integral Array- Codeforces Round #775 (Div. 1, based on Moscow Open Olympiad in Informatics)

Problem - 1648B - Codeforces

B. Integral Array

time limit per test

2 seconds

memory limit per test

512 megabytes

input

standard input

output

standard output

You are given an array aa of nn positive integers numbered from 11 to nn. Let's call an array integral if for any two, not necessarily different, numbers xx and yy from this array, x≥yx≥y, the number ⌊xy⌋⌊xy⌋ (xx divided by yy with rounding down) is also in this array.

You are guaranteed that all numbers in aa do not exceed cc. Your task is to check whether this array is integral.

Input

The input consists of multiple test cases. The first line contains a single integer tt (1≤t≤1041≤t≤104) — the number of test cases. Description of the test cases follows.

The first line of each test case contains two integers nn and cc (1≤n≤1061≤n≤106, 1≤c≤1061≤c≤106) — the size of aa and the limit for the numbers in the array.

The second line of each test case contains nn integers a1a1, a2a2, ..., anan (1≤ai≤c1≤ai≤c) — the array aa.

Let NN be the sum of nn over all test cases and CC be the sum of cc over all test cases. It is guaranteed that N≤106N≤106 and C≤106C≤106.

Output

For each test case print Yes if the array is integral and No otherwise.

Examples

input

Copy

4
3 5
1 2 5
4 10
1 3 3 7
1 2
2
1 1
1

output

Copy

Yes
No
No
Yes

input

Copy

1
1 1000000
1000000

output

Copy

No

Note

In the first test case it is easy to see that the array is integral:

  • ⌊11⌋=1⌊11⌋=1, a1=1a1=1, this number occurs in the arry
  • ⌊22⌋=1⌊22⌋=1
  • ⌊55⌋=1⌊55⌋=1
  • ⌊21⌋=2⌊21⌋=2, a2=2a2=2, this number occurs in the array
  • ⌊51⌋=5⌊51⌋=5, a3=5a3=5, this number occurs in the array
  • ⌊52⌋=2⌊52⌋=2, a2=2a2=2, this number occurs in the array

Thus, the condition is met and the array is integral.

In the second test case it is enough to see that

⌊73⌋=⌊213⌋=2⌊73⌋=⌊213⌋=2, this number is not in aa, that's why it is not integral.

In the third test case ⌊22⌋=1⌊22⌋=1, but there is only 22 in the array, that's why it is not integral.

==================================================================================================================================================

我们可以on遍历数组,对于每个数字,遍历其在c内的倍数,但由于要验证的是一个区间内的数字,所以可以利用前缀和来进行判断。要验证【L,R]区间内是否有数,用sum[R]-sum[L-1],判断是否为0即可。

但这样仍然超时,本题对时间的控制还是比较严格,考虑到1的特殊性,元素的重复性,故对2-c进行判断即可。

#include<bits/stdc++.h>
using namespace std;
int n,c,T,mat[1000005],s[1000005];
bool check(){
	scanf("%d%d",&n,&c);
	for(int i=1;i<=c;i++) mat[i]=s[i]=0;
	for(int i=1,x;i<=n;i++){
		scanf("%d",&x);
		mat[x]=1;
	}
	if(!mat[1]) return false;
	for(int i=1;i<=c;i++) s[i]=s[i-1]+mat[i];
	for(int i=2;i<=c;i++){
		if(!mat[i]) continue;
		for(int j=i;j<=c;j+=i)
			if(s[min(c,j+i-1)]-s[j-1])
				if(!mat[j/i]) return false;
	}
	return true;
} 
int main(){
	scanf("%d",&T);
	while(T--){
		if(check()) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
} 

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

秦三码

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值