Search Here

Saturday, June 20, 2015

UVa - 10991 ( Easy Problem From Rujia Liu Solution )

Try Yourself First. For help Scroll Down .

Clearance :  This is really an easy problem. All you have to do is to search a Distinct Position of a Distinct Number. If it is there with that respective position then Print the Position or Print ' 0 ' . A Normal Searching Solution must get a TLE verdict as the Data Set may be Very Big . So to solve you have to Pre-Calculate all the numbers position in a Two Dimensional Array . And then for each input set print  the respective array value. That work is up to you . Hopefully Cleared .

Tip : Try to use Dynamic Arrays. As the array length is very big .

Code :


#include<bits/stdc++.h>
#define clear(a) memset(a,0,sizeof(a))
using namespace std;

vector<int>number[1000001];

int main()
{

    int m, n;
    while(scanf("%d %d",&m,&n)==2)
    {
        clear(number);
        int x;
        for(int i=1; i<=m; i++)
        {
           cin>>x;
           number[x].push_back(i);
        }
        int k, v;
        for(int i=0; i<n; i++)
        {
            cin>>k>>v;
            if(k>number[v].size())
                printf("0\n");
            else
                printf("%d\n",number[v][k-1]);
        }
    }
    return 0;
}

=> Need Help? Leave a Comment .

No comments:

Post a Comment