zoukankan      html  css  js  c++  java
  • UVA 11991

    Time limit: 1.000 seconds

    Easy Problem from Rujia Liu?

    Though Rujia Liu usually sets hard problems for contests (for example, regional contests like Xi'an 2006, Beijing 2007 and Wuhan 2009, or UVa OJ contests like Rujia Liu's Presents 1 and 2), he occasionally sets easy problem (for example, 'the Coco-Cola Store' in UVa OJ), to encourage more people to solve his problems :D

    Given an array, your task is to find the k-th occurrence (from left to right) of an integer v. To make the problem more difficult (and interesting!), you'll have to answer m such queries.

    Input

    There are several test cases. The first line of each test case contains two integers n, m(1<=n,m<=100,000), the number of elements in the array, and the number of queries. The next line contains n positive integers not larger than 1,000,000. Each of the following m lines contains two integer k and v (1<=k<=n, 1<=v<=1,000,000). The input is terminated by end-of-file (EOF). The size of input file does not exceed 5MB.

    Output

    For each query, print the 1-based location of the occurrence. If there is no such element, output 0 instead.

    Sample Input

    8 4
    1 3 2 2 4 3 2 1
    1 3
    2 4
    3 2
    4 2
    

    Output for the Sample Input

    2
    0
    7
    0

    /*
    * @author  Panoss
    */
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<algorithm>
    #include<vector>
    #include<ctime>
    #include<stack>
    #include<map>
    #include<cmath>
    #include<queue>
    #include<list>
    using namespace std;
    #define DBG 1
    #define fori(i,a,b) for(int i = (a); i < (b); i++)
    #define forie(i,a,b) for(int i = (a); i <= (b); i++)
    #define ford(i,a,b) for(int i = (a); i > (b); i--)
    #define forde(i,a,b) for(int i = (a); i >= (b); i--)
    #define forls(i,a,b,n) for(int i = (a); i != (b); i = n[i])
    #define mset(a,v) memset(a, v, sizeof(a))
    #define mcpy(a,b) memcpy(a, b, sizeof(a))
    #define dout  DBG && cerr << __LINE__ << " >>| "
    #define checkv(x) dout << #x"=" << (x) << " | "<<endl
    #define checka(array,a,b) if(DBG) { 
        dout << #array"[] | " << endl; 
        forie(i, a, b) cerr << "[" << i << "]=" << array[i] << " |" << ((i - (a)+1) % 5 ? " " : "
    "); 
    if (((b)-(a)+1) % 5) cerr << endl; 
    }
    #define redata(T, x) T x; cin >> x
    #define MIN_LD -2147483648
    #define MAX_LD  2147483647
    #define MIN_LLD -9223372036854775808
    #define MAX_LLD  9223372036854775807
    #define MAX_INF 18446744073709551615
    inline int  reint() { int d; scanf("%d", &d); return d; }
    inline long relong() { long l; scanf("%ld", &l); return l; }
    inline char rechar() { scanf(" "); return getchar(); }
    inline double redouble() { double d; scanf("%lf", &d); return d; }
    inline string restring() { string s; cin >> s; return s; }
    
    map<int, vector<int> > A;
    
    int main()
    {
        int n, m, k, v;
        while(scanf("%d%d",&n,&m)==2)
        {
            A.clear();
            forie(i,1,n)
            {
                scanf("%d",&v);
                if(!A.count(v)) A[v] = vector<int>();
                A[v].push_back(i);
            }
            forie(i,1,m)
            {
                scanf("%d%d",&k,&v);
                if(!A.count(v)||A[v].size()<k) printf("0
    ");
                else printf("%d
    ",A[v][k-1]);
            }
        }
        return 0;
    }
  • 相关阅读:
    java.net.ConnectException: localhost/127.0.0.1:8088 Connection refused java程序员
    网络模式:GSM,WCDMA,CDMA2000什么意思 java程序员
    Spring contextConfigLocation java程序员
    src总结 java程序员
    广州天河软件园面试Java实习生时的一些面试题 java程序员
    纠结了好久的Android SDK无法更新问题 java程序员
    Android SDK 2.3/3.0/4.0/4.1 下载与安装教程 java程序员
    域名解析文件hosts文件是什么?如何修改hosts文件? java程序员
    安卓模拟器Android SDK 4.0.3 R2安装完整图文教程 java程序员
    SpringBoot+mongoDB实现id自增
  • 原文地址:https://www.cnblogs.com/Panoss/p/3821458.html
Copyright © 2011-2022 走看看