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;
}