Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 5471 Accepted Submission(s): 1370
node
#include <cstdio> #include <cstring> #include <algorithm> #include <queue> #include <string> using namespace std; const int MAXN=150005; struct Node{ char name[205]; int val,id; Node(){} bool operator<(const Node &nod) const { if(val!=nod.val) return val < nod.val; else return id > nod.id; } }node[MAXN]; struct Query{ int t,q; }que[MAXN]; int n,m,q; int query[MAXN]; bool comp(Query q1,Query q2) { return q1.t < q2.t; } int res[MAXN],tot; int main() { int T; scanf("%d",&T); while(T--) { tot=0; scanf("%d%d%d",&n,&m,&q); for(int i=1;i<=n;i++) { scanf("%s %d",node[i].name,&node[i].val); node[i].id=i; } for(int i=0;i<m;i++) { scanf("%d%d",&que[i].t,&que[i].q); } int mx=0; for(int i=0;i<q;i++) { scanf("%d",&query[i]); mx=max(mx,query[i]); } sort(que,que+m,comp); priority_queue<Node> pque; for(int i=1,j=0;i<=n;i++) { pque.push(node[i]); if(j<m&&i==que[j].t) { for(int l=0;l<que[j].q&&!pque.empty();l++) { Node nod=pque.top();pque.pop(); res[++tot]=nod.id; } j++; } if(tot>=mx) break; } while(!pque.empty()) { Node nod=pque.top();pque.pop(); res[++tot]=nod.id; if(tot>=mx) break; } for(int i=0;i<q-1;i++) { printf("%s ",node[res[query[i]]].name); } printf("%s\n",node[res[query[q-1]]].name); } return 0; }