Sorry for misjudging the difficulty of problem D, but we still hope you enjoyed the problems!
$$$a \oplus 1$$$ is equivalent to $$$a - 1$$$ when $$$a$$$ is an odd number, otherwise it is equivalent to $$$a + 1$$$.
If you apply $$$a \gets a \oplus 1$$$ when $$$a$$$ is odd, then that operation should make $$$a = b$$$.
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;
int t, a, b, x, y;
int main(){scanf("%d", &t);
while (t --){scanf("%d%d%d%d", &a, &b, &x, &y);
if (a > b) printf("%d\n", (a ^ 1) == b ? y : -1);
else {int c0 = b - a, c1 = (b + 1 >> 1) - (a + 1 >> 1);
printf("%lld\n", y > x ? 1ll * c0 * x : 1ll * (c0 - c1) * x + 1ll * c1 * y);}
}
}
Transform $$$(p_x,p_y)$$$ to $$$(q_x,q_y)$$$ into an operation where $$$a_i$$$ is the distance between the two points.
When $$$n+1=3$$$, there is a solution if and only if the largest $$$a_i$$$ is less than or equal to the sum of the remaining $$$a_i$$$.
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
#define N 100010
#define int long long
int t,n,sx,sy,tx,ty;
double a[N];
signed main()
{
cin>>t;
while(t--)
{
cin>>n;
cin>>sx>>sy>>tx>>ty;
for(int i=1;i<=n;i++)
cin>>a[i];
a[++n]=sqrt((sx-tx)*(sx-tx)+(sy-ty)*(sy-ty));
sort(a+1,a+n+1);
double sum=a[n];
for(int i=1;i<n;i++)
sum-=a[i];
if(sum<=0)
puts("Yes");
else
puts("No");
}
}
#include<iostream>
#include<algorithm>
using namespace std;
#define N 100010
#define int long long
int t,n,sx,sy,tx,ty,a[N];
signed main()
{
cin>>t;
while(t--)
{
cin>>n;
cin>>sx>>sy>>tx>>ty;
for(int i=1;i<=n;i++)
cin>>a[i];
sort(a+1,a+n+1);
int p=(sx-tx)*(sx-tx)+(sy-ty)*(sy-ty);
if(p>a[n]*a[n])
{
int sum=0;
for(int i=1;i<=n;i++)
{
sum+=a[i];
if(sum*sum>=p)
break;
}
if(sum*sum>=p)
puts("Yes");
else
puts("No");
}
else
{
int sum=a[n];
for(int i=1;i<=n-1;i++)
sum-=a[i];
if(sum<=0||sum*sum<=p)
puts("Yes");
else
puts("No");
}
}
}
For odd $$$n$$$, setting $$$a_i = l$$$ for all $$$i$$$ suffices.
For even $$$n$$$, there does not exist a valid array $$$a$$$ that satisfies $$$a_1=a_2=\dots=a_{n-1}=l$$$.
For even $$$n$$$, try to satisfy $$$\oplus_{i=1}^{n}a_i=0$$$.
#include<iostream>
using namespace std;
#define int long long
int t,n,l,r,k;
signed main()
{
cin>>t;
while(t--)
{
cin>>n>>l>>r>>k;
if(n%2==1)
{
cout<<l<<endl;
continue;
}
if(n==2)
{
cout<<-1<<endl;
continue;
}
int res=1;
bool fl=0;
while(res<=r)
{
if(res>l)
{
fl=1;
if(k<=n-2)
cout<<l<<endl;
else
cout<<res<<endl;
break;
}
res*=2;
}
if(!fl)
cout<<-1<<endl;
}
}
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;
const int N = 5005;
int t, n, mod, f[N][N], ans;
inline void add(int& x, int y){x += y;if (x >= mod) x -= mod;}
int main(){scanf("%d", &t);
while (t --){scanf("%d%d", &n, &mod), f[0][0] = 1, ans = 0;
for (int i = 1;i <= n;i ++) for (int j = 0;j <= i;j ++) f[i][j] = 0;
for (int i = 1;i <= n;i ++)
for (int j = 0, now;j < i;j ++)
if (now = f[i - 1][j]) add(f[i][j + 1], now),
f[i][j] = (f[i][j] + (n - i + 1ll) * (j + 1) * now) % mod;
for (int j = 0;j <= n;j ++) add(ans, f[n][j]);printf("%d\n", ans);
}
}




