Codeforces Round 900 (Div. 3)

A

#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const int N = 30;
int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}

inline void solve(){
	int n, k; cin >> n >> k;
	vector<int>a(n);
	bool ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] == k)
			ans = 1;
	}
	if (ans)
		cout << "Yes" << '\n';
	else
		cout << "No" << '\n';
}
signed main(){

	ios::sync_with_stdio(false);
	cin.tie(0);
	std::cout.tie(0);

	int t = 1;
	cin >> t;
	while (t--)
		solve();

	return 0;
}

B

#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const int N = 30;
int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}

inline void solve(){
	int n; cin >> n;
	vector<ll>a(n);

	a[0] = 2, a[1] = 3;

	for (int i = 2; i < n ; i++) {
		a[i] = a[i - 1] + 1;
		if (3 * a[i] % (a[i - 1] + a[i - 2])==0)a[i]++;
	}

	for (int i = 0; i < n; i++)
		cout << a[i] << ' ';
	cout << '\n';
	return;
}
signed main(){

	ios::sync_with_stdio(false);
	cin.tie(0);
	std::cout.tie(0);

	int t = 1;
	cin >> t;
	while (t--)
		solve();

	return 0;
}

C

找出x范围,因为给了k,所以好找

#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const int N = 30;
int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}

inline void solve(){
	ll n, k, x; cin >> n >> k >> x;
	ll flag = (1 + k) * k / 2;
	ll flag2 = (2 * n - k + 1) * k / 2;
	if (x < flag||x>flag2) {
		cout << "NO" << '\n';
		return;
	}
	else {
		cout << "YES" << '\n';
		return;
	}

}
signed main(){

	ios::sync_with_stdio(false);
	cin.tie(0);
	std::cout.tie(0);

	int t = 1;
	cin >> t;
	while (t--)
		solve();

	return 0;
}

E

e题是个好题目啊,预处理的方式非常巧妙

总之就是前缀和+二分

#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const int N = 2e5+5;
int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}

inline void solve(){
	int n; cin >> n;
	
	vector<int>a(n+1);
	vector<vector<int>>f(n + 1);
	for (int i = 0; i <= n; i++)
		f[i].resize(30);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < 30; j++) {
			f[i][j] = f[i - 1][j];

			if ((a[i] >> j) & 1)
				f[i][j]++;
		}
	}

	int q; cin >> q;
	while (q--) {
		int l, k; 
		cin >> l >> k;

		auto check = [&](int r){
			int v = 0;
			for (int i = 0; i < 30; i++)
				if (f[r][i] - f[l-1][i] == r - l + 1)v += (1 << i);
			return v >= k;
		};

		int L = l - 1, R = n + 1;
		while (L+1 < R) {
			int mid = (L + R) >> 1;

			if (check(mid))
				L = mid;
			else
				R = mid;
		}
		if (L == l - 1)
			cout << -1 << ' ';
		else
			cout << L << ' ';
	}
	cout << '\n';
}
signed main(){

	ios::sync_with_stdio(false);
	cin.tie(0);
	std::cout.tie(0);

	int t = 1;
	cin >> t;
	while (t--)
		solve();

	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值