模拟,认真理解题意
#include <stdio.h>
#include <algorithm>
#include <queue>
#define MAXN 150010
#define SCI(i) scanf("%d", &i)
using namespace std;
struct Node
{
char name[210];
int v;
int id;
bool operator <(const Node &a) const
{
if(v!=a.v)
return v < a.v; // big top
return id > a.id; // small top
}
};
Node n[MAXN];
struct Order
{
int come;
int in;
};
Order o[MAXN];
bool cmp1(const Node &a, const Node &b)
{
if(a.v!=b.v)
return a.v>b.v;
return a.id < b.id;
}
bool cmp2(const Order &a, const Order &b)
{
return a.come<b.come;
}
int res[MAXN];
int main()
{
int T;
SCI(T);
while(T--)
{
int res_name = 0;
priority_queue <Node> pq;
int person_num, order_num, ask_num;
scanf("%d %d %d", &person_num, &order_num, &ask_num);
for(int i = 0; i < person_num; i++)
{
scanf("%s %d", n[i].name, &n[i].v);
n[i].id = i;
}
for(int i = 0; i < order_num; i++)
scanf("%d %d", &o[i].come, &o[i].in);
sort(o, o+order_num, cmp2);
if(o[order_num-1].come == person_num)
o[order_num-1].in = person_num;
else
{
o[order_num].come = person_num;
o[order_num++].in = person_num;
}
int now = 0;
for(int i = 0; i < order_num; i++)
{
while(now<person_num&&now<o[i].come)
pq.push(n[now++]);
for(int j = 0;j < o[i].in; j++)
{
if(pq.empty())
break;
res[res_name++] = pq.top().id;
pq.pop();
}
}
for(int i = 0; i < ask_num; i++)
{
int temp;
scanf("%d", &temp);
temp--;
if(i)
printf(" ");
printf("%s", n[res[temp]].name);
}
printf("\n");
}
}