Untitled
unknown
plain_text
2 years ago
1.5 kB
4
Indexable
#include <bits/stdc++.h>
using namespace std;
int f(int n, vector<int> a, vector<int> b)
{
unordered_map<int, int> mp1;
unordered_map<int, int> mp2;
for (int i = 0; i < n; i++)
{
mp1[a[i]]++;
/* code */
}
for (int i = 0; i < n; i++)
{
/* code */ mp2[b[i]]++;
}
int count = 1;
for (auto i = mp1.begin(); i != mp1.end(); i++)
{
count = max(count, (*i).second);
/* code */
}
for (auto i = mp2.begin(); i != mp2.end(); i++)
{
count = max(count, (*i).second);
/* code */
}
int y = -1;
for (auto i = mp1.begin(); i != mp1.end(); i++)
{
auto it = mp2.find((*i).first);
if (it != mp2.end())
{
y = max(y, (*i).second + (*it).second);
}
/* code */
}
if (count == 1)
{
if (y == -1)
return 1;
else
return y;
}
else
{
if (y == -1)
return count;
else
return max(count,y);
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
vector<int> a(n);
vector<int> b(n);
for (int i = 0; i < n; i++)
{
/* code */ cin >> a[i];
}
for (int i = 0; i < n; i++)
{
/* code */
cin >> b[i];
}
cout << f(n, a, b) << '\n';
}
return 0;
}Editor is loading...