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

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

uva 11991 Easy Problem from Rujia Liu?

2019-11-14 11:31:12
字體:
來源:轉載
供稿:網友

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

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


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 商都县| 义马市| SHOW| 芒康县| 盱眙县| 钟山县| 铅山县| 尖扎县| 大渡口区| 乌拉特中旗| 湖北省| 轮台县| 峡江县| 宁晋县| 岳阳市| 简阳市| 洪湖市| 城口县| 鄄城县| 龙江县| 广宁县| 沅陵县| 汝阳县| 冕宁县| 托克托县| 渭南市| 吴江市| 天水市| 和林格尔县| 河源市| 巴南区| 东乌| 长岛县| 宜君县| 简阳市| 婺源县| 肥城市| 奉贤区| 垦利县| 玛多县| 渑池县|