今天这场比前天的Educational Codeforces Round 125打得舒服?
A. Good Pairs
容易知道只需输出序列中最大和最小的数的位置即可
B. Subtract Operation
以前的某场round有过类似操作的题,消减后我们可以发现只需查找是否存在$a_i+k=a_j$,有输出YES
即可,否则为NO
C. Make Equal With Mod
分类讨论,当序列中不存在1时,答案为YES,存在1时,我们需要判断序列中是否存在$a_i-a_j=1$,存在输出NO
,否则输出YES
D. K-good
题意是对于$n$是否存在$k$使得$n=\frac{k\times(k+1)}{2}+a\times k,a\in N$
容易发现$n$为奇数的时候答案为2
下面考虑$n$为奇数的情况,不妨设有$n \bmod k =0$,则此时上式可化为
$$\frac{2n}{k}=k+1+2 \times a \times k$$
于是我们发现需要将$n$分成奇数乘于偶数的形式,其中奇数要大于2,所以我们可以将$n$一直除2分解成$n=2^c\times p$,其中p为奇数
所以有p等于1时答案为-1,否则答案为min(2(c+1),p)
code:
//A
#include <algorithm>
#include <bitset>
#include <map>
#include <vector>
#include <string>
#include <iostream>
#include <cmath>
#include <stack>
#include <set>
/*
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
*/
using namespace std;
const double eps = 1e-10;
const double pi = 3.1415926535897932384626433832795;
const double eln = 2.718281828459045235360287471352;
#define f(i, a, b) for (int i = a; i <= b; i++)
#define LL long long
#define IN freopen("in.txt", "r", stdin)
#define OUT freopen("out.txt", "w", stdout)
#define scan(x) scanf("%d", &x)
#define mp make_pair
#define pb push_back
#define sqr(x) (x) * (x)
#define pr1(x) printf("Case %d: ",x)
#define pn1(x) printf("Case %d:\n",x)
#define pr2(x) printf("Case #%d: ",x)
#define pn2(x) printf("Case #%d:\n",x)
#define lowbit(x) (x&(-x))
#define fi first
#define se second
#define sz(x) int((x).size())
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define summ(a) (accumulate(all(a), 0ll))
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
LL tt,n,x;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>tt;
f(sb,1,tt){
cin>>n;
vi v(n);
int mi=0x3f3f3f3f,mib,ma=-1,mab=-1;
f(i,1,n){
cin>>x;
if(x>ma){
ma=x;
mab=i;
}
if(x<mi){
mi=x;
mib=i;
}
}
cout<<mib<<" "<<mab<<"\n";
}
return 0;
}
//B
#include <algorithm>
#include <bitset>
#include <map>
#include <vector>
#include <string>
#include <iostream>
#include <cmath>
#include <stack>
#include <set>
#include<numeric>
/*
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
*/
using namespace std;
const double eps = 1e-10;
const double pi = 3.1415926535897932384626433832795;
const double eln = 2.718281828459045235360287471352;
#define f(i, a, b) for (int i = a; i <= b; i++)
#define LL long long
#define IN freopen("in.txt", "r", stdin)
#define OUT freopen("out.txt", "w", stdout)
#define scan(x) scanf("%d", &x)
#define mp make_pair
#define pb push_back
#define sqr(x) (x) * (x)
#define pr1(x) printf("Case %d: ",x)
#define pn1(x) printf("Case %d:\n",x)
#define pr2(x) printf("Case #%d: ",x)
#define pn2(x) printf("Case #%d:\n",x)
#define lowbit(x) (x&(-x))
#define fi first
#define se second
#define sz(x) int((x).size())
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define summ(a) (accumulate(all(a), 0ll))
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<LL> vi;
LL tt,n,k;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>tt;
f(sb,1,tt){
cin>>n>>k;
vi v(n);
map<LL,int> vis;
for(auto &it:v)cin>>it,vis[it]=1;
int ok=0;
for(auto it:v){
if(vis.count(it+k)){
ok=1;
break;
}
}
cout<<(ok?"YES\n":"NO\n");
}
return 0;
}
//C
#include <algorithm>
#include <bitset>
#include <map>
#include <vector>
#include <string>
#include <iostream>
#include <cmath>
#include <stack>
#include <set>
#include <numeric>
/*
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
*/
using namespace std;
const double eps = 1e-10;
const double pi = 3.1415926535897932384626433832795;
const double eln = 2.718281828459045235360287471352;
#define f(i, a, b) for (int i = a; i <= b; i++)
#define LL long long
#define IN freopen("in.txt", "r", stdin)
#define OUT freopen("out.txt", "w", stdout)
#define scan(x) scanf("%d", &x)
#define mp make_pair
#define pb push_back
#define sqr(x) (x) * (x)
#define pr1(x) printf("Case %d: ", x)
#define pn1(x) printf("Case %d:\n", x)
#define pr2(x) printf("Case #%d: ", x)
#define pn2(x) printf("Case #%d:\n", x)
#define lowbit(x) (x & (-x))
#define fi first
#define se second
#define sz(x) int((x).size())
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define summ(a) (accumulate(all(a), 0ll))
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<LL> vi;
LL tt, n;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> tt;
f(sb, 1, tt)
{
cin >> n;
int ok = 1, ck1 = 0, cnt1 = 0,cnt2=0;
vi v(n);
for (auto &it : v)
{
cin >> it;
if (it == 1)
cnt1 += 1;
}
if(cnt1){
sort(all(v));
int len=v.size();
for(int i=1;i<len;++i){
if(v[i]-v[i-1]==1){
ok=0;
break;
}
}
}else ok=1;
cout<<(ok?"YES\n":"NO\n");
}
return 0;
}
//D
#include <algorithm>
#include <bitset>
#include <map>
#include <vector>
#include <string>
#include <iostream>
#include <cmath>
#include <stack>
#include <set>
/*
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
*/
using namespace std;
const double eps = 1e-10;
const double pi = 3.1415926535897932384626433832795;
const double eln = 2.718281828459045235360287471352;
#define f(i, a, b) for (int i = a; i <= b; i++)
#define LL long long
#define IN freopen("in.txt", "r", stdin)
#define OUT freopen("out.txt", "w", stdout)
#define scan(x) scanf("%d", &x)
#define mp make_pair
#define pb push_back
#define sqr(x) (x) * (x)
#define pr1(x) printf("Case %d: ",x)
#define pn1(x) printf("Case %d:\n",x)
#define pr2(x) printf("Case #%d: ",x)
#define pn2(x) printf("Case #%d:\n",x)
#define lowbit(x) (x&(-x))
#define fi first
#define se second
#define sz(x) int((x).size())
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define summ(a) (accumulate(all(a), 0ll))
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
LL tt,n;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>tt;
f(sb,1,tt){
cin>>n;
if(n&1){
cout<<"2\n";
}else {
LL cn=1;
while((n&1)==0){
n>>=1;
cn+=1;
}
if(n==1)cout<<"-1\n";
else cout<<min(1ll<<cn,n)<<"\n";
}
}
return 0;
}