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

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

uva 11991 Easy Problem from Rujia Liu?

2019-11-14 10:58:05
字體:
來源:轉載
供稿:網友

原題: 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;}

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


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 盐源县| 韶关市| 宝兴县| 陇川县| 平凉市| 岫岩| 萨嘎县| 镇巴县| 靖远县| 新乡市| 宜君县| 屯留县| 德州市| 夏河县| 曲沃县| 镇沅| 龙门县| 万安县| 阜新市| 双桥区| 图片| 阜南县| 礼泉县| 新平| 萍乡市| 淅川县| 阜宁县| 涟水县| 长宁区| 瑞昌市| 肇州县| 楚雄市| 邯郸市| 清原| 新昌县| 岗巴县| 西和县| 买车| 东丰县| 保亭| 房山区|