您的位置:首页 > 其它

uva 11991 Easy Problem from Rujia Liu?

2013-09-10 19:40 337 查看
解题思路:STL —— vector, map

///////////////////////////////////////////////////////////////////////////
//problem_id: uva 11991
//user_id: SCNU20102200088
///////////////////////////////////////////////////////////////////////////

#include <algorithm>
#include <iostream>
#include <iterator>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
using namespace std;

///////////////////////////////////////////////////////////////////////////
#pragma comment(linker,"/STACK:1024000000,1024000000")

#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
///////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////
const double EPS=1e-8;
const double PI=acos(-1.0);

const int x4[]={-1,0,1,0};
const int y4[]={0,1,0,-1};
const int x8[]={-1,-1,0,1,1,1,0,-1};
const int y8[]={0,1,1,1,0,-1,-1,-1};
///////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////
typedef long long LL;

typedef int T;
T max(T a,T b){ return a>b? a:b; }
T min(T a,T b){ return a<b? a:b; }
T gcd(T a,T b){ return b==0? a:gcd(b,a%b); }
T lcm(T a,T b){ return a/gcd(a,b)*b; }
///////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////
//Add Code:
vector<int> a[1000005];
///////////////////////////////////////////////////////////////////////////

int main(){
///////////////////////////////////////////////////////////////////////
//Add Code:
int n,m,x,k,v,i;
while(scanf("%d%d",&n,&m)!=EOF){
for(i=0;i<=1000000;i++) a[i].clear();
for(i=1;i<=n;i++){
scanf("%d",&x);
a[x].push_back(i);
}
while(m--){
scanf("%d%d",&k,&v);
if(a[v].size()<k) printf("0\n");
else printf("%d\n",a[v][k-1]);
}
}
///////////////////////////////////////////////////////////////////////
return 0;
}

///////////////////////////////////////////////////////////////////////////
/*
Testcase:
Input:
8 4
1 3 2 2 4 3 2 1
1 3
2 4
3 2
4 2
Output:
2
0
7
0
*/
///////////////////////////////////////////////////////////////////////////


///////////////////////////////////////////////////////////////////////////
//problem_id: uva 11991
//user_id: SCNU20102200088
///////////////////////////////////////////////////////////////////////////

#include <algorithm>
#include <iostream>
#include <iterator>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
using namespace std;

///////////////////////////////////////////////////////////////////////////
#pragma comment(linker,"/STACK:1024000000,1024000000")

#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
///////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////
const double EPS=1e-8;
const double PI=acos(-1.0);

const int x4[]={-1,0,1,0};
const int y4[]={0,1,0,-1};
const int x8[]={-1,-1,0,1,1,1,0,-1};
const int y8[]={0,1,1,1,0,-1,-1,-1};
///////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////
typedef long long LL;

typedef int T;
T max(T a,T b){ return a>b? a:b; }
T min(T a,T b){ return a<b? a:b; }
T gcd(T a,T b){ return b==0? a:gcd(b,a%b); }
T lcm(T a,T b){ return a/gcd(a,b)*b; }
///////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////
//Add Code:
///////////////////////////////////////////////////////////////////////////

int main(){
///////////////////////////////////////////////////////////////////////
//Add Code:
int n,m,x,k,v,i;
while(scanf("%d%d",&n,&m)!=EOF){
map<int,vector<int> > a;
for(i=1;i<=n;i++){
scanf("%d",&x);
if(a.count(x)==0) a[x]=vector<int>();
a[x].push_back(i);
}
while(m--){
scanf("%d%d",&k,&v);
if(a.count(v)==0 || a[v].size()<k) printf("0\n");
else printf("%d\n",a[v][k-1]);
}
}
///////////////////////////////////////////////////////////////////////
return 0;
}

///////////////////////////////////////////////////////////////////////////
/*
Testcase:
Input:
8 4
1 3 2 2 4 3 2 1
1 3
2 4
3 2
4 2
Output:
2
0
7
0
*/
///////////////////////////////////////////////////////////////////////////
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: