国产探花免费观看_亚洲丰满少妇自慰呻吟_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;}

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


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 固阳县| 合作市| 宝坻区| 井研县| 武邑县| 鹤山市| 游戏| 包头市| 沙湾县| 库尔勒市| 雷山县| 安阳县| 安徽省| 巴林左旗| 横山县| 洪湖市| 贵南县| 长汀县| 大关县| 资溪县| 南宫市| 安溪县| 仁化县| 留坝县| 新疆| 浦江县| 古丈县| 同心县| 个旧市| 涟源市| 民权县| 松溪县| 行唐县| 合川市| 贡嘎县| 上饶县| 贵港市| 潜山县| 新宁县| 突泉县| 肇州县|