2019 Multi-University Training Contest 7 1010 Just Repeat

题解

（对于我取消流同步的cin比自己写的快读要快这件事，我真的很疑惑……）

代码

```#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
using namespace std;
const int maxn = 1e5+5;
int a[maxn],b[maxn];
unsigned long long mod;
unsigned long long k1, k2;
unsigned long long rng() {
unsigned long long k3 = k1, k4 = k2;
k1 = k4;
k3 ^= k3 << 23;
k2 = k3 ^ k4 ^ (k3 >> 17) ^ (k4 >> 26);
return k2 + k4;
}
int t;
int n,m,p;
int cnt = 0;
int c[maxn<<1];
int q[maxn<<1];
int com[maxn<<1];
struct point{
int val,id;
}e[maxn];
bool cmp(point a,point b){
return a.val > b.val;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> t;
while(t--){
cin >> n >> m >> p;
cnt = 0;
if(p == 1){
for(int i = 1;i <= n;++i){
cin >> a[i];
c[i] = a[i];
}
for(int i = 1;i <= m;++i){
cin >> b[i];
c[i+n] = b[i];
}
}
else{
cin >> k1 >> k2 >> mod;
for (int i = 1; i <= n; ++i)
a[i] = rng() % mod,c[i] = a[i];
cin >> k1 >> k2 >> mod;
for (int i = 1; i <= m; ++i)
b[i] = rng() % mod,c[i+n] = b[i];
}
sort(c+1,c+n+m+1);
int tot = unique(c+1,c+n+m+1) - (c + 1);
for(int i = 1;i <= tot;++i){
com[i] = q[i] = 0;
}
for(int i = 1;i <= n;++i){
a[i] = lower_bound(c+1,c+tot+1,a[i]) - c;
q[a[i]]++;
}
for(int i = 1;i <= m;++i){
b[i] = lower_bound(c+1,c+tot+1,b[i]) - c;
if(q[b[i]]){
com[b[i]]++;
}
}
for(int i = 1;i <= tot;++i){
if(com[i]){
n -= q[i];
m -= com[i];
e[++cnt].val = q[i] + com[i];
e[cnt].id = i;
}
}
sort(e+1,e+cnt+1,cmp);
for(int i = 1;i <= cnt;++i){
if(i % 2 == 1){
n += q[e[i].id];
}
else m += com[e[i].id];
}
if(n > m)cout << "Cuber QQ\n";
else cout << "Quber CC\n";
}
return 0;
}```

0 条评论