• 欢迎光临~

# 复健训练-CF1698(Codeforces Round #803 (Div. 2))

【写完签到题就不会了...

### A. XOR Mixup

```#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define ll long long

using namespace std;

const int N = 105;
int n, a[N];

void Main(){
scanf("%d", &n);
int XOR = 0;
rep (i,1,n) scanf("%d", &a[i]), XOR ^= a[i];
rep (i,1,n)
if ((XOR^a[i]) == a[i]){printf("%dn", a[i]); return;}
return;
}

int main(){
int T; scanf("%d", &T);
while (T--) Main();
return 0;
}```
View Code

### B. Rising Sand

```#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define ll long long

using namespace std;

const int N = 2e5+10;
int n, k, a[N];

void Main(){
scanf("%d%d", &n,&k);
rep (i,1,n) scanf("%d", &a[i]);
if (k==1){
printf("%dn", (n-1)/2);
} else{
int ans = 0;
rep (i,2,n-1)
if ((ll)a[i] > (ll)a[i-1]+a[i+1])
ans++;
printf("%dn", ans);
}
return;
}

int main(){
int T; scanf("%d", &T);
while (T--) Main();
return 0;
}```
View Code

### C. 3SUM Closure

```#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define ll long long

using namespace std;

const int N = 2e5+10;
int n, a[N], b[10];

void Main(){
scanf("%d", &n);
int x = 0, y = 0, z = 0;
rep (i,1,n){
scanf("%d", &a[i]);
if (a[i]>0) x ++;
else if (a[i]<0) y ++;
else z ++;
}
if (x>=3 || y >= 3){puts("NO"); return;}
int tot = 0;
map<int,bool> mp;
rep (i,1,n) if (a[i]!=0) b[++tot] = a[i],mp[a[i]]=1;
if (z) b[++tot] = 0,mp[0]=1;
rep (i,1,tot)
rep (j,i+1, tot)
rep (k,j+1, tot)
if (!mp.count(b[i]+b[j]+b[k])){puts("NO"); return;}
puts("YES");
return;
}

int main(){
int T; scanf("%d", &T);
while (T--) Main();
return 0;
}```
View Code

### D. Fixed Point Guessing

```#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define ll long long

using namespace std;

printf("? %d %dn", l, r);
fflush(stdout);
int t = 0;
rep (i,1,r-l+1){
int x; scanf("%d", &x);
if (l<=x && x<=r) t ++;
}
return t;
}

printf("! %dn" , x);
fflush(stdout);
}

void Main(){
int n;
scanf("%d", &n);
int l = 1, r = n, mid;
while (l < r){
mid = (l+r)>>1;
if (ask(l, mid)%2==1) r = mid;
else l = mid+1;
}
return;
}

int main(){
int T; scanf("%d", &T);
while (T--) Main();
return 0;
}```
View Code

### E. PermutationForces II

```#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define ll long long

using namespace std;

const int N = 2e5+10;
const int mod = 998244353;
int n, s, a[N], b[N], c[N], m, sum[N];

void Main(){
scanf("%d%d", &n, &s);
rep (i,1,n) scanf("%d", &a[i]), sum[i] = 0;
bool flag=1;
rep (i,1,n){
scanf("%d", &b[i]);
if (b[i]!=-1) sum[b[i]]++;
if (b[i]!=-1&&b[i]<a[i]-s) flag=0;
}
for (int i=n-1; i>=1; i--) sum[i]+=sum[i+1];
if (!flag){puts("0"); return;}
m = 0;
rep (i,1,n) if (b[i]==-1) c[++m] = max(a[i]-s, 1);
sort(c+1, c+1+m); reverse(c+1, c+1+m);
int ans = 1;
rep (i,1,m) ans = (ll)ans*max(n-c[i]+1-sum[c[i]]-i+1, 0)%mod;
printf("%dn", ans);
return;
}

int main(){
int T; scanf("%d", &T);
while (T--) Main();
return 0;
}```
View Code

F G 咕咕 还没看题（