集合字典序(优先队列)

题目链接 :传送门
 
解题思路:我们可以维护两个小顶堆的优先队列,然后每次入队的时候,对队列前面的元素进行比较,如果相等就一直pop,否则,就跳出循环,然后比较一下两个队列的前端,如果第一个队列大则输出>,反之输出<,如果队列为空,则输出=
 
Code:

#include<bits/stdc++.h>
using namespace std;

int n,a,b;
priority_queue<int,vector<int>,greater<int> > que1,que2;

int main()
{
	while(~scanf("%d",&n)) {
		for(int i = 0;i < n; ++i) {
			scanf("%d%d",&a,&b);
			que1.push(a);
			que2.push(b);
			int op = 0;
			while(que1.size()) {
				if(que1.top() == que2.top()) {
					que1.pop();
					que2.pop();
				}
				else {
					if(que1.top() > que2.top()) {
						op = 1;
					}
					else {
						op = -1;
					}
					break;
				}
			}
			if(op == 0) {
				puts("=");
			}
			else if(op == 1) {
				puts(">");
			}
			else if(op == -1) {
				puts("<");
			}
		}
		while(que1.size()) {
			que1.pop();
			que2.pop();
		}
	}
	
	return 0;
}
posted @ 2021-01-18 19:44  MangataTS  阅读(110)  评论(0编辑  收藏  举报