UVA 11991 - Easy Problem from Rujia Liu?

题目链接

题意:给一个长度n的序列,有m询问,每一个询问会问第k个出现的数字的下标是多少

思路:用map和vector搞,map[i][j]直接保存的就是数字i第j个出现,每次直接输出就可以

代码:

#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
using namespace std; int n, m; map<int, vector<int> > ans; int main() {
while (~scanf("%d%d", &n, &m)) {
int a, b;
ans.clear();
for (int i = 1; i <= n; i++) {
scanf("%d", &a);
if (!ans.count(a)) ans[a] = vector<int> ();
ans[a].push_back(i);
}
while (m--) {
scanf("%d%d", &a, &b);
if (ans[b].size() < a) printf("0\n");
else printf("%d\n", ans[b][a - 1]);
}
}
return 0;
}

版权声明:本文博主原创文章,博客,未经同意不得转载。

11991 - Easy Problem from Rujia Liu?(的基础数据结构)的更多相关文章

  1. [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 ...

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

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

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

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

  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. STL UVA 11991 Easy Problem from Rujia Liu?

    题目传送门 题意:训练指南P187 分析:用vector存id下标,可以用map,也可以离散化用数组存(发现不用离散化也可以) map #include <bits/stdc++.h> u ...

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

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

  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. POJ 3169 Layout (HDU 3592) 差分约束

    http://poj.org/problem?id=3169 http://acm.hdu.edu.cn/showproblem.php?pid=3592 题目大意: 一些母牛按序号排成一条直线.有两 ...

  2. [Angular] Learn How To Use ng-template Inputs

    For example, we have a modal component, it can config that using ng-template as a configurable templ ...

  3. 深度学习 Deep Learning UFLDL 最新Tutorial 学习笔记 4:Debugging: Gradient Checking

    1 Gradient Checking 说明 前面我们已经实现了Linear Regression和Logistic Regression.关键在于代价函数Cost Function和其梯度Gradi ...

  4. 关于fatfs生成的wav文件是空,大小是0的问题

    绝大多数是因为打开错误 调试的时候,编写程序的时候 要记得res=f_open() 要有返回值res的设置

  5. UI组件之TextView及其子类(三)ToggleButton和Switch

    ToggleButton.Switch.CheckBox和RadioButton都是继承自android.widget.CompoundButton,意思是可选择的,因此它们的使用方法都非常类似. C ...

  6. dll = MinGW gcc 生成动态链接库 dll 的一些问题汇总

    MinGW gcc 生成动态链接库 dll 的一些问题汇总 https://blog.csdn.net/liyuanbhu/article/details/42612365 网络上关于用 MinGW  ...

  7. 使用DatagramSocket与DatagramPacket传输数据 分类: B1_JAVA 2013-10-12 13:00 1936人阅读 评论(0) 收藏

    参考传智播客毕向东JAVA视频. 注: DatagramSocket发送的每个包都需要指定地址,而Socket则是在首次创建时指定地址,以后所有数据的发送都通过此socket. A socket is ...

  8. dmalloc用法快速入门

    原文链接 常用内存泄露检测手段有 1 mtrace 2 memwatch 3 mpatrol 4 dmalloc 5 dbgmem 6 valgrind 7 Electric Fence dmallo ...

  9. Android多线程研究(3)——线程同步和互斥及死锁

    为什么会有线程同步的概念呢?为什么要同步?什么是线程同步?先看一段代码: package com.maso.test; public class ThreadTest2 implements Runn ...

  10. sysbench压测Oracle

    安装: yum -y install make m4  autoconf automake libtool pkgconfig libaio-devel rpm -Uvh http://dl.fedo ...