• 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;
    }
  • 相关阅读:
    installanywhere制作java installation
    长文件名处理
    Hibernate+ehcache二级缓存技术
    如何在JSP里添加删除cookie
    收集java精确截取字符串
    在什么情况下可以定义static 方法?
    Hibernate2 到 Hibernate3 的问题
    出现java.lang.UnsupportedClassVersionError 错误的原因
    DMI指标又叫动向指标或趋向指标
    Tomcat下log4j设置文件路径和temp目录
  • 原文地址:https://www.cnblogs.com/Panoss/p/3821458.html
Copyright © 2020-2023  润新知