题目传送门

题意:训练指南P187

分析:用vector存id下标,可以用map,也可以离散化用数组存(发现不用离散化也可以)

map

#include <bits/stdc++.h>
using namespace std; map<int, vector<int> >mp; int main(void) {
int n, m;
while (scanf ("%d%d", &n, &m) == 2) {
mp.clear ();
for (int a, i=1; i<=n; ++i) {
scanf ("%d", &a);
if (!mp.count (a)) mp[a] = vector<int> ();
mp[a].push_back (i);
}
while (m--) {
int k, v; scanf ("%d%d", &k, &v);
if (!mp.count (v) || mp[v].size () < k) puts ("0");
else printf ("%d\n", mp[v][k-1]);
}
} return 0;
}

离散化

#include <bits/stdc++.h>
using namespace std; const int N = 1e5 + 5;
vector<int> vec[N];
int a[N], A[N]; int main(void) {
int n, m;
while (scanf ("%d%d", &n, &m) == 2) {
for (int i=1; i<=n; ++i) vec[i].clear ();
for (int i=1; i<=n; ++i) {
scanf ("%d", &a[i]); A[i] = a[i];
}
sort (A+1, A+1+n);
int nn = unique (A+1, A+1+n) - A - 1;
for (int i=1; i<=n; ++i) {
a[i] = lower_bound (A+1, A+1+nn, a[i]) - A;
}
for (int i=1; i<=n; ++i) {
vec[a[i]].push_back (i);
}
for (int k, v, i=1; i<=m; ++i) {
scanf ("%d%d", &k, &v);
v = lower_bound (A+1, A+1+nn, v) - A;
if (vec[v].size () < k) puts ("0");
else printf ("%d\n", vec[v][k-1]);
}
} return 0;
}

  

STL UVA 11991 Easy Problem from Rujia Liu?的更多相关文章

  1. uva 11991 - Easy Problem from Rujia Liu?(STL)

    option=com_onlinejudge&Itemid=8&page=show_problem&problem=3142" target="_blank ...

  2. CJOJ 2485 UVa 11991 生日礼物 / UVa 11991 Easy Problem from Rujia Liu?

    CJOJ 2485 UVa 11991 生日礼物 / UVa 11991 Easy Problem from Rujia Liu? Description (原题来自刘汝佳<训练指南>Pa ...

  3. [UVA] 11991 - Easy Problem from Rujia Liu? [STL应用]

    11991 - Easy Problem from Rujia Liu? Time limit: 1.000 seconds Problem E Easy Problem from Rujia Liu ...

  4. UVa 11991:Easy Problem from Rujia Liu?(STL练习,map+vector)

    Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, ...

  5. UVA 11991 Easy Problem from Rujia Liu?(vector map)

    Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, ...

  6. UVA 11991 Easy Problem from Rujia Liu?【STL】

    题目链接: option=com_onlinejudge&Itemid=8&page=show_problem&problem=3142">https://uv ...

  7. uva 11991 Easy Problem from Rujia Liu? vector+map

    水题 学习一下数据的存储方法. #include<iostream> #include<cstdio> #include<cstdlib> #include< ...

  8. 11991 - Easy Problem from Rujia Liu?(的基础数据结构)

    UVA 11991 - Easy Problem from Rujia Liu? 题目链接 题意:给一个长度n的序列,有m询问,每一个询问会问第k个出现的数字的下标是多少 思路:用map和vector ...

  9. uva--11991 - Easy Problem from Rujia Liu?(sort+二分 map+vector vector)

    11991 - Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for e ...

随机推荐

  1. jQuery与JS的区别,以及jQuery的基础语法

    *在使用jQuery时,要在页面最上端加上 <script src="../jquery-1.11.2.min.js"></script> 看一下js与jQ ...

  2. Android Studio新建了一个项目看不到手机界面的效果

    我今天新建了一个项目,但是在这里却看不到手机的界面效果,如下图:

  3. [Android Pro] Android libdvm.so 与 libart.so

    reference to :http://blog.csdn.net/koffuxu/article/details/44780351 Android libdvm.so 与 libart.so   ...

  4. !struct operator reload

    struct t3DObject //对象信息结构体{ int numOfVerts; // 模型中顶点的数目 int numOfFaces; // 模型中面的数目 int numTexVertex; ...

  5. C --gettimeofday===获取某个程序经历的时间

    #include <stdio.h> #include <sys/time.h> #include <time.h> int gettimeofday(struct ...

  6. Java使用JDBC连接MySQL数据库

    1.引用 JDBC(Java Data Base Connectivity,java数据库连接)是一种用于执行SQL语句的Java API,可以为多种关系数据库提供统一访问,它由一组用Java语言编写 ...

  7. Jpinyin笔记

  8. UVA 10252

    按照字典序输出最长公共子序列 #include<time.h> #include <cstdio> #include <iostream> #include< ...

  9. 同一内网不能网段ping 不通

    [root@NB sysconfig]# route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use ...

  10. C#的LINQ to Object

    using System; using System.Collections; using System.Collections.Generic; using System.IO; using Sys ...