题解 CF1470B 【Strange Definition】
do_while_true · · 题解
\mathcal{Translate}
注: "
定义
共有
对于每一种数据,给定长度为
定义
共有
\mathcal{Solution}
\mathcal{Code}
#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
#include<algorithm>
#include<map>
#define pb push_back
#define pp std::pair<unsigned long long, unsigned long long>
#define mp std::make_pair
#define fir first
#define sec second
#define ll long long
#define re register
#define ull unsigned long long
//#define int long long
inline int Max(int x, int y) { return x > y ? x : y; }
inline int Min(int x, int y) { return x < y ? x : y; }
inline int Abs(int x) { return x < 0 ? ~x + 1 : x; }
inline int read() {
int r = 0; bool w = 0; char ch = getchar();
while(ch < '0' || ch > '9') {
if(ch == '-') w = 1;
ch = getchar();
}
while(ch >= '0' && ch <= '9') {
r = (r << 3) + (r << 1) + (ch ^ 48);
ch = getchar();
}
return w ? ~r + 1 : r;
}
//#undef int
const int N = 300010;
const ull base = 21841;
const ull mod = 29050993;
const ull base2 = 1429;
const ull mod2 = 68861641;
int n, a[N], ans1, ans2;
pp hs[N];
std::map<pp, int>vis;
pp hasher(int x) {
std::vector<int>vec; int xx = x;
for(int i = 2; i * i <= xx; ++i)
if(x % i == 0) {
int ct = 0;
while(x % i == 0) x /= i, ++ct;
if(ct&1) vec.pb(i);
}
if(x > 1) vec.pb(x);
ull sum1 = 0, sum2 = 0;
std::sort(vec.begin(), vec.end());
int len = vec.size();
for(int i = 0; i < len; ++i) sum1 = (sum1 * base % mod + (ull)vec[i]) % mod;
for(int i = 0; i < len; ++i) sum2 = (sum2 * base2 % mod2 + (ull)vec[i]) % mod2;
return mp(sum1, sum2);
}
void solve() {
n = read(); vis.clear(); ans1 = ans2 = 0;
for(int i = 1; i <= n; ++i) a[i] = read();
for(int i = 1; i <= n; ++i) hs[i] = hasher(a[i]), vis[hs[i]]++, ans1 = Max(ans1, vis[hs[i]]);
for(int i = 1; i <= n; ++i) if(vis[hs[i]] % 2 == 0 || hs[i].fir + hs[i].sec == 0) ans2 += vis[hs[i]], vis[hs[i]] = 0;
ans2 = Max(ans1, ans2);
int q = read();
ll x;
while(q--) {
scanf("%lld", &x);
if(x == 0) printf("%d\n", ans1);
else printf("%d\n", ans2);
}
}
signed main() {
int T = read();
while(T--) solve();
return 0;
}