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;
    }
  • 相关阅读:
    MySQL常用函数大全讲解
    mysql 获取最近一个月每一天
    Mysql查询某个月的每一天的数据
    Mysql 查询一天中,每个小时数据的数量
    oracle 和 mysql 遍历当前月份每一天
    sql查询总结
    Qt样式表——选择器详解(父子关系,插图详细解释)
    Qt样式表之盒子模型(以QSS来讲解,而不是CSS)
    程序员晋升必备技能——单元测试框架(小豆君的干货铺)
    为什么川普反对中国补贴农业(渐进式发展是非常正确的,如果贸然改动农村土地制度,在城市还不能提供足够的就业岗位下将大量的农民推向城市……请欣赏一下巴西、印度城市的贫民窟)
  • 原文地址:https://www.cnblogs.com/Panoss/p/3821458.html
Copyright © 2011-2022 走看看