I'm trying to solve this question:
As we all know that Varchas is going on. So FOC wants to organise an event called Finding Occurrence.
The task is simple :
Given an array A[1...N] of positive integers. There will be Q queries. In the queries you will be given an integer. You need to find out the frequency of that integer in the given array.
INPUT:
First line of input comprises of integer N, the number of integers in given array. The next line will comprise of N space separated integers. The next line will be Q, number of Queries. The next Q lines will comprise of a single integer whose Occurrence you are supposed to find out.
OUTPUT:
Output single integer for each Query which is the frequency of the given integer.
Constraints:
1<=N<=100000
1<=Q<=100000
0<=A[i]<=1000000
And this is my code:
#include <iostream>
using namespace std;
int main()
{
    long long n=0;
    cin >> n;
    long long a[1000000];
    for (int i=1;i<=n;i++)
    {
        cin >> a[i];
    }
    long long q=0;
    cin >> q;
    while (q--)
    {
        long long temp=0,counter=0;
        cin >> temp;
        for (int k=1;k<=n;k++)
        {
            if (a[k]==temp)
                counter++;
        }
        cout << "\n" << counter;
        temp=0;
        counter=0;
    }
    return 0;
}
However, I encountered the 'Time Limit Exceeded' error. I suspect this is due to the failure to handle large values in arrays. Could someone tell me how to handle such large size arrays?
 
     
     
    