11991 - Easy Problem from Rujia Liu?

  Though Rujia Liu usually sets hard problems for contests (for example, regional contests like
Xi’an 2006, Beijing 2007 and Wuhan 2009, or UVa OJ contests like Rujia Liu’s Presents 1
and 2), he occasionally sets easy problem (for example, ‘the Coco-Cola Store’ in UVa OJ),
to encourage more people to solve his problems :D
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
题解:就是给你一个数组,问多次,每次找第k个v的坐标;我用了sort还用了二分,这竟然都没超时。。。数据太弱了吧。。。数据量是100000。。本来就是想试试 ,竟然过了,总结,以后别怕超时,别怂就是干。。。大神是map+vector,我用的vector  re了;;;

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
using namespace std;
const int INF=0x3f3f3f3f;
#define mem(x,y) memset(x,y,sizeof(x))
#define SI(x) scanf("%d",&x)
#define SL(x) scanf("%lld",&x)
#define PI(x) printf("%d",x)
#define PL(x) printf("%lld",x)
#define P_ printf(" ")
#define T_T while(T--)
#define F(i,s,x) for(i=s;i<x;i++)
const double PI=acos(-1.0);
typedef long long LL;
int n,m;
struct Node{
int v,pos;
friend bool operator < (Node a,Node b){
if(a.v!=b.v)return a.v<b.v;
else return a.pos<b.pos;
}
}dt[100010];
int erfen(int x){
int l=1,r=n,mid;
while(l<=r){
mid=(l+r)>>1;
if(dt[mid].v>=x)r=mid-1;
else l=mid+1;
}
return l;
}
int main(){
while(~scanf("%d%d",&n,&m)){
int i;
F(i,1,n+1)SI(dt[i].v),dt[i].pos=i;
sort(dt+1,dt+1+n);
int k,v,pos;
// F(i,1,n+1)PI(dt[i].v),P_;puts("");
// F(i,1,n+1)PI(dt[i].pos),P_;puts("");
while(m--){
SI(k);SI(v);
pos=erfen(v);
//printf("%d\n",pos);
if(dt[k+pos-1].v!=v)puts("0");
else printf("%d\n",dt[k+pos-1].pos);
}
}
return 0;
}

  map+vetor;

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<map>
using namespace std;
const int INF=0x3f3f3f3f;
#define mem(x,y) memset(x,y,sizeof(x))
#define SI(x) scanf("%d",&x)
#define SL(x) scanf("%lld",&x)
#define PI(x) printf("%d",x)
#define PL(x) printf("%lld",x)
#define P_ printf(" ")
#define T_T while(T--)
#define F(i,s,x) for(i=s;i<x;i++)
const double PI=acos(-1.0);
typedef long long LL;
const int MAXN=100010;
map<int,vector<int> >mp;
int main(){
int m,n;
while(~scanf("%d%d",&n,&m)){
int i,x;
F(i,1,n+1){
SI(x);
// if(!mp.count(x))mp[x]=vector<int>();
mp[x].push_back(i);
}int k,v;
while(m--){
SI(k);SI(v);
if(mp[v].size()<k)puts("0");
else printf("%d\n",mp[v][k-1]);
}
}
return 0;
}

  vector  re...

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
using namespace std;
const int INF=0x3f3f3f3f;
#define mem(x,y) memset(x,y,sizeof(x))
#define SI(x) scanf("%d",&x)
#define SL(x) scanf("%lld",&x)
#define PI(x) printf("%d",x)
#define PL(x) printf("%lld",x)
#define P_ printf(" ")
#define T_T while(T--)
#define F(i,s,x) for(i=s;i<x;i++)
const double PI=acos(-1.0);
typedef long long LL;
const int MAXN=100010;
vector<int>vec[MAXN];
int main(){
int m,n;
while(~scanf("%d%d",&n,&m)){
int i,x;
for(int i=0;i<MAXN;i++)vec[i].clear();
F(i,1,n+1){
SI(x);
vec[x].push_back(i);
}int k,v;
while(m--){
SI(k);SI(v);
if(vec[v].size()<k)puts("0");
else printf("%d\n",vec[v][k-1]);
}
}
return 0;
}

  

uva--11991 - Easy Problem from Rujia Liu?(sort+二分 map+vector vector)的更多相关文章

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

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

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

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

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

  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. 11991 - Easy Problem from Rujia Liu?(的基础数据结构)

    UVA 11991 - Easy Problem from Rujia Liu? 题目链接 题意:给一个长度n的序列,有m询问,每一个询问会问第k个出现的数字的下标是多少 思路:用map和vector ...

随机推荐

  1. Android四大组件之Activity详解

    一.Activity的概要说明 我看过Activity的源码,Activity类注释大概是这样解释的:几乎所有的Activity都是与用户交互用的,我想用了一个几乎的意思应该是排除一些纯展示界面吧,因 ...

  2. xcode6编译cocos2dx项目出现Undefined symbols _fwrite$UNIX2003

    当xcode6编译cocos2dx的时候会出现Undefined symbols _fwrite$UNIX2003 这个问题.google了一篇文章:http://stackoverflow.com/ ...

  3. 这家伙,搞了好多C#excel的操作,学习了

    http://www.cnblogs.com/peterzb/archive/2009/07/06/1517395.html

  4. Linux 系统之Systemd

    子贡问为仁.子曰:“工欲善其事,必先利其器.居是邦也,事其大夫之贤者,友其士之仁者.”——孔子(春秋)<论语·卫灵公> [工欲善其事,必先利其器] 掌握一门技术,知道其发展历程是非常重要的 ...

  5. mybatis foreach where test用法

    <select id="selectAny" resultType="user" parameterType="user"> s ...

  6. C#中WebClient使用DownloadString中文乱码的解决办法

    原文:C#中WebClient中文乱码的解决办法 第一次尝试: string question = textBox1.Text.ToString(); WebClient client= new We ...

  7. Java并发编程总结4——ConcurrentHashMap在jdk1.8中的改进(转)

    一.简单回顾ConcurrentHashMap在jdk1.7中的设计 先简单看下ConcurrentHashMap类在jdk1.7中的设计,其基本结构如图所示: 每一个segment都是一个HashE ...

  8. MapList 自己封装的

    //// Source code recreated from a .class file by IntelliJ IDEA// (powered by Fernflower decompiler)/ ...

  9. HDU 2104 hide handkerchief

    题解:由题目可以知道,如果n和m的最大公约数不为1,那么总有箱子是无法遍历的,所以求一遍GCD就可以判断了. 注意点:一定要记住判断是==,在做题时又忘了. #include <cstdio&g ...

  10. 记NOIP分数出来前

    咩~成绩还没有出来呢!但是拿到了每个人的程序,还有一堆民间的数据.我测了好多不同的数据,基本上D1T1,D2T1,D2T2的都是暴力解决掉的,没有什么问题,唯一就是D1T2的link那一题,写的时候2 ...