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;
    }
  • 相关阅读:
    连接服务器时通时不通的问题
    二进制包搭建k8s集群
    2、带着问题学习JVM_对象存活_垃圾回收的内容_理论_收集算法
    四、redis事务_真正实现分布式Lua_分布式锁
    四、Spring 框架中接入单机Redis的两种方式
    3、通过zkCli⼯具命令和zk 的java API两种方式创建⼀个主从模式示列
    1、带着问题学习JVM_Java为什么属于编译型+解释型的高级语言_Class类文件结构理解
    2、zookeeper安装、常用命令、API说明及简单示列(创建ZK会话及对节点进行操作、创建分布式锁、创建全局唯一ID)
    1、zk的产生、优劣、基础知识
    十三、Spring容器的原理及源码分析
  • 原文地址:https://www.cnblogs.com/Panoss/p/3821458.html
Copyright © 2011-2022 走看看