您的位置:首页 > 其它

fzu1894 自愿者选拔

2016-05-18 12:47 302 查看
题意:

中文题目就不多说了。


思路:

单调队列的使用,因为问的是当前排队中的最高rp,所以用个维护最大值的单调队列就好了,出队和询问的时候判断下就好了。


const int maxn = 1e6 + 10;
struct node {
char *name;
int rp;
int pos;
node() {}
node(char c[], int rp,int pos) {
this->name = c;
this->rp = rp;
this->pos = pos;
}
}p[maxn];
int main(int argc, const char * argv[])
{
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
int t;
cin >> t;
char name[10];
int rp;
while(t--) {
char op[10];
int head = 0, tail = 0;
int out = 0;
int pos = 0;
while(scanf("%s", op) != EOF) {
if (strcmp(op, "START") == 0) continue;
if (op[0] == 'C') {
scanf("%s %d", name, &rp);
while(head < tail && p[tail-1].rp < rp) tail--;
p[tail++] = node(name, rp, ++pos);
}else if (op[0] == 'G') {
out++;
if (p[head].pos == out) head++;
}else if (op[0] == 'Q'){
if (head == tail) printf("-1\n");
else printf("%d\n", p[head].rp);
}else if (op[0] == 'E') break;
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: