[Algo Beat Contest 001 D] Dreamed Sequence 官方题解
显然最终的序列中
虽然序列元素的数据范围很大,但是一个序列中的不同元素显然最多只有
时间复杂度:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod = 1e9 + 7;
ll n, x, y, ans, a[114514], b[114514];
unordered_map<ll, ll> cnt, mp;
set<ll> s;
pair<ll, ll> c[114514], d[114514];
ll op(ll t[], pair<ll, ll> p[], ll tot = 0) {
s.clear();
cnt.clear();
for (ll i = 1; i <= n; i++) {
cin >> t[i];
cnt[t[i]]++;
}
for (ll i = 1; i <= n; i++) {
s.insert(t[i]);
}
for (ll kk : s) {
tot++;
p[tot] = {kk, cnt[kk]};
}
return tot;
}
void solve() {
cin >> n;
x = op(a, c);
y = op(b, d);
for (ll i = 1; i <= x; i++) {
for (ll j = 1; j <= y; j++) {
mp[c[i].first * d[j].first % mod] += min(c[i].second, d[j].second);
}
}
for (pair<ll, ll> kk : mp) {
ans = max(ans, kk.second);
}
cout << ans;
}
int main() {
solve();
return 0;
}