Alisha’s Party

Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 7514    Accepted Submission(s): 1748

Problem Description
Princess Alisha invites her friends to come to her birthday party. Each of her friends will bring a gift of some value v, and all of them will come at a different time. Because the lobby is not large enough, Alisha can only let a few people in at a time. She decides to let the person whose gift has the highest value enter first.

Each time when Alisha opens the door, she can decide to let p people enter her castle. If there are less than p people in the lobby, then all of them would enter. And after all of her friends has arrived, Alisha will open the door again and this time every friend who has not entered yet would enter.

If there are two friends who bring gifts of the same value, then the one who comes first should enter first. Given a query n Please tell Alisha who the n−th person to enter her castle is.

 
Input
The first line of the input gives the number of test cases, T , where 1≤T≤15.

In each test case, the first line contains three numbers k,m and q separated by blanks. k is the number of her friends invited where 1≤k≤150,000. The door would open m times before all Alisha’s friends arrive where 0≤m≤k. Alisha will have q queries where 1≤q≤100.

The i−th of the following k lines gives a string Bi, which consists of no more than 200 English characters, and an integer vi, 1≤vi≤108, separated by a blank. Biis the name of the i−th person coming to Alisha’s party and Bi brings a gift of value vi.

Each of the following m lines contains two integers t(1≤t≤k) and p(0≤p≤k) separated by a blank. The door will open right after the t−th person arrives, and Alisha will let p friends enter her castle.

The last line of each test case will contain q numbers n1,...,nq separated by a space, which means Alisha wants to know who are the n1−th,...,nq−th friends to enter her castle.

Note: there will be at most two test cases containing n>10000.

 
Output
For each test case, output the corresponding name of Alisha’s query, separated by a space.
 
Sample Input
1
5 2 3
Sorey 3
Rose 3
Maltran 3
Lailah 5
Mikleo 6
1 1
4 2
1 2 3
 
Sample Output
Sorey Lailah Rose
 
Source
 
Recommend
 
 
 
 #include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
#define P pair<int,int>
#define ph push_back
#define ll long long
#define N 150009
#define fi first
#define se second
int t,n,m,q;
struct Ma{
string s;
int val,id;
bool operator <(const Ma&a)const{
if(val!=a.val)
return val<a.val;
return id>a.id;
}
}ma[N];
struct Node{
int time,p;
}nod[N];
bool cmp(Node a,Node b)
{
return a.time<b.time;
}
string ret[N];
char ss[];
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&n,&m,&q);
for(int i=;i<=n;i++)
{
scanf("%s%d",ss,&ma[i].val);
ma[i].s=ss;
ma[i].id=i;
}
for(int i=;i<m;i++)
{
scanf("%d%d",&nod[i].time,&nod[i].p);
}
sort(nod,nod+m,cmp);
priority_queue<Ma>que;
int pos=,cnt=;
for(int i=;i<m;i++)
{
while(pos<=nod[i].time){
que.push(ma[pos]);//pos容易写错
pos++;
}
for(int j=;j<nod[i].p;j++)
{
if(que.empty()) break;//小于p个人,都进去
Ma x=que.top();que.pop();
ret[cnt++]=x.s;
}
}
while(pos<=n)
{
que.push(ma[pos]);
pos++;
}
while(!que.empty()){
Ma x=que.top();que.pop();
ret[cnt++]=x.s;
}
int y;
for(int l=;l<q;l++)
{
scanf("%d",&y);
printf("%s%c",ret[y].c_str(),l==q-?'\n':' ');
}
}
return ;
}

hdu 5437的更多相关文章

  1. hdu 5437 Alisha’s Party 优先队列

    Alisha’s Party Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/contests/contest_sh ...

  2. hdu 5437 优先队列+模拟 **

    比赛的时候虽然考虑到没门的情况,但是写了几组都能过,就没想了,23333,差一行代码就能A,遗憾~~ #include<cstdio> #include<iostream> # ...

  3. hdu 5437 Alisha’s Party 模拟 优先队列

    Problem Description Princess Alisha invites her friends to come to her birthday party. Each of her f ...

  4. HDU 5437 Alisha’s Party (优先队列模拟)

    题意:邀请k个朋友,每个朋友带有礼物价值不一,m次开门,每次开门让一定人数p(如果门外人数少于p,全都进去)进来,当最后所有人都到了还会再开一次门,让还没进来的人进来,每次都是礼物价值高的人先进.最后 ...

  5. HDU 5437 Alisha’s Party (优先队列)——2015 ACM/ICPC Asia Regional Changchun Online

    Problem Description Princess Alisha invites her friends to come to her birthday party. Each of her f ...

  6. HDU 5437 Alisha’s Party

    题意:有k个人带着价值vi的礼物来,开m次门,每次在有t个人来的时候开门放进来p个人,所有人都来了之后再开一次门把剩下的人都放进来,每次带礼物价值高的人先进,价值相同先来先进,q次询问,询问第n个进来 ...

  7. hdu 5437(优先队列模拟)

    Alisha’s Party Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  8. 优先队列 + 模拟 - HDU 5437 Alisha’s Party

    Alisha’s Party Problem's Link Mean: Alisha过生日,有k个朋友来参加聚会,由于空间有限,Alisha每次开门只能让p个人进来,而且带的礼物价值越高就越先进入. ...

  9. HDU 5437 & ICPC 2015 Changchun Alisha's Party(优先队列)

    Alisha’s Party Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

随机推荐

  1. 【bzoj1718】Redundant Paths 分离的路径

    1718: [Usaco2006 Jan] Redundant Paths 分离的路径 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 964  Solve ...

  2. 【aspnetcore】在asp.net core中配置使用AutoMapper

    网上使用AutoMapper的文章很多,就不多说了.这里主要记录一下怎么在项目中配置和使用. 首先是从NuGet获取AutoMapper. 在Startup.cs文件中注册AutoMapper服务 p ...

  3. 牛客网Java刷题知识点之什么是死锁、死锁产生的4个必要条件、死锁的解除与预防

    不多说,直接上干货! https://www.nowcoder.com/ta/review-java/review?query=&asc=true&order=&page=16 ...

  4. 系统讲解一下,Dao,Entity,Servlet,Action各自有什么东西-Java/Web开发

    dao 主要是一些接口,里面定义了一些用于增删改查的方法名 daoImpl 就是对dao的具体实现 Service 同上,也是一些接口,主要是用来调用dao层的一些方法,所以这里定义的方法一般都定义好 ...

  5. link标签的media属性的用法

    <link rel=stylesheet" type="text/css" href="print.css" media="scree ...

  6. 提升 Web开发性能的 10 个技巧

    随着网络的高速发展,网络性能的持续提高成为能否在芸芸App中脱颖而出的关键.高度联结的世界意味着用户对网络体验提出了更严苛的要求.假如你的网站不能做到快速响应,又或你的App存在延迟,用户很快就会移情 ...

  7. 基于 Azure IaaS 搭建企业官网的规划和实践

    本课程主要介绍了基于 Azure IaaS 搭建企业官网的案例分析和实践,实践讲解如何使用 Azure 门户创建虚拟机, 创建虚拟网络, 创建存储账户等. 具体包括项目背景介绍, 项目架构, 准备和实 ...

  8. 生鲜o2o配送应用系统,包括Android源码+SSH带后台管理系统

    前台功能划分    我的 登录            账户+密码 注册            订单管理 查看/删除(显示订单详情)                支付(提交订单)           ...

  9. -[UPAInitViewController startAPPay] in libUPAPayPlugin.a(UPAInitViewController.o)

    问题 Undefined symbols for architecture arm64: "_PKPaymentNetworkChinaUnionPay", referenced ...

  10. C01 C语言基础

    目录 C语言简史及特点 C语言开发环境 C语言程序结构 C语言基本输入输出函数 编译 软件类型 C语言简要及特点 什么是计算机语言 计算机语言是用于人与计算机之间通讯的语言. 计算机遵照接收到的计算机 ...