One of my colleagues was asked this question in an interview.
Given a huge array which stores unsigned int. Length of array is 100000000. Find the effective
Look at its variation that might help you to find no. of distinct elements.
#include
using namespace std;
#define ll long long int
#define ump unordered_map
void file_i_o()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int main() {
file_i_o();
ll t;
cin>>t;
while(t--)
{
int n,q;
cin>>n>>q;
ump num;
int x;
int arr[n+1];
int a,b;
for(int i=1;i<=n;i++)
{
cin>>x;
arr[i]=x;
num[x]++;
}
for(int i=0;i>a>>b;
num[arr[a]]--;
if((num[arr[a]])==0)
{ num.erase(arr[a]); }
arr[a]=b;
num[b]++;
cout<