2023牛客多校6

E-Sequence

题意

将给定数组的(l,r)分成k份,满足每一份都是偶数。

题解

因为 偶数 + 偶数 = 偶数 偶数+偶数=偶数 偶数+偶数=偶数,显然 ∑ i = l − 1 r a i \sum_{i=l-1}^ra_i i=l1rai 是偶数。
继续分析 s l − 1 s_{l-1} sl1 s b 1 s_{b_1} sb1 s b 2 s_{b_2} sb2,… s r s_{r} sr 奇偶性相同,可利用前缀和记录奇偶性,并判断在(l,r)区间内是否存在k个与 s l − 1 s_{l-1} sl1 奇偶性相同的 s x s_{x} sx
分析原理:若此区间满足为偶数,因为 偶数 + 偶数 = 偶数 偶数+偶数=偶数 偶数+偶数=偶数 偶数 + 奇数 = 奇数 偶数+奇数=奇数 偶数+奇数=奇数,所以 s l − 1 s_{l-1} sl1 s b 1 s_{b_1} sb1 s b 2 s_{b_2} sb2,… s r s_{r} sr奇偶性相同。

#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;

const int N = 1e5 + 5;
int n, q, sum[N], cnt[N][2];

void solve()
{
	memset(sum,0,sizeof sum);
	memset(cnt,0,sizeof cnt);
	int n,q;
	
	cin>>n>>q;
	
	for(int i=1;i<=n;i++)
	{
		long long x;
		
		cin>>x;
		
		sum[i]=sum[i-1]^(x&1);
		cnt[i][0]=cnt[i-1][0]+(sum[i]==0);
		cnt[i][1]=cnt[i-1][1]+(sum[i]==1);
	}
	while(q--)
	{
		int l,r,k;
		
		cin>>l>>r>>k;
		
		if(sum[r]!=sum[l-1]) puts("NO");
		else if(cnt[r][sum[l-1]]-cnt[l-1][sum[l-1]]>=k) puts("YES");
		else puts("NO");
	}
}
int main()
{
	int T;
	
	cin>>T;
	
	while(T--)
	{
		solve();
	}
	return 0;
}

G-Gcd

题解

给定一个数组 s = x , y s={{x,y}} s=x,y
可以有一下操作
1.从数组中任意选择两个元素 a , b a,b ab,并插入 g c d ( a , b ) gcd(a,b) gcdab
2.从数组中任意选择两个元素 a , b a,b ab,并插入 a − b a-b ab到数组中
若任意次操作后数组中可出现z,就输出YES,否则输出NO

题解

裴蜀定理得,两个数辗转相减,只能得出这两个数最大公约数的倍数。
所以只需要判断z是否是gcd(a,b)的整数倍

#include<iostream>
#include<algorithm>
#include<cstring>

#define int long long 
using namespace std;

int gcd(int x,int y)
{
    if(y==0)return x;
    return gcd(y,x%y);
}

void solve()
{
	int x,y,z;
	
	cin>>x>>y>>z;
	
	if(x&&y&&z==0)
	{
		cout<<"NO"<<endl;
		return ;
	}
	if(z%gcd(x,y)==0) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}
signed main()
{
	int T;
	
	cin>>T;
	
	while(T--)
	{
		solve();
	}
	return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值