国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

uva 11991 Easy Problem from Rujia Liu?

2019-11-14 11:29:16
字體:
來源:轉載
供稿:網友

原題: 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). 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 Sample Output 2 0 7 0

中文: 給你n個數,然后給你m個查詢,每個查詢包含兩個數k和v問你第k個v的小標是多少?

#include <bits/stdc++.h>using namespace std;unordered_map<int,vector<int>> miv;int n,m;int main(){ ios::sync_with_stdio(false); while(cin>>n>>m) { miv.clear(); for(int i=1;i<=n;i++) { int res; cin>>res; miv[res].push_back(i); } for(int i=1;i<=m;i++) { int k,v; cin>>k>>v; if(miv.find(v)==miv.end()||miv[v].size()<k) cout<<0<<endl; else { cout<<miv[v][k-1]<<endl; } } } return 0;}

思路: 這題的名起的,不秒殺都不好意思~~ 思路見下面的圖 這里寫圖片描述 長方格里面的數是輸入的所有數,每個方格里面的數下面的鏈是按順序存儲的下標值。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 洪泽县| 苏尼特右旗| 达日县| 南汇区| 奇台县| 雷州市| 乳源| 南通市| 万源市| 北川| 桑日县| 宜川县| 黄龙县| 长葛市| 阜城县| 卓尼县| 龙州县| 苏州市| 英德市| 周宁县| 正定县| 蕲春县| 台东县| 永安市| 巫山县| 阳曲县| 安泽县| 新余市| 柘城县| 桂平市| 平舆县| 本溪市| 甘德县| 武夷山市| 凉山| 稷山县| 克东县| 洞头县| 满洲里市| 曲阳县| 兰州市|