0
点赞
收藏
分享

微信扫一扫

HDU - 1540 Tunnel Warfare(set)

幸甚至哉歌以咏志 2022-04-05 阅读 29
c++算法

HDU - 1540 Tunnel Warfare

set做法

#include<iostream>
#include<cstdio>
#include<set>
#include<stack>
using namespace std;
int main()
{
	int n,m;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		set<int> se={0,n+1};
		stack<int> stk;
		while(m--)
		{
			char op[2];scanf("%s",op);
			if(*op=='D')
			{
				int x;scanf("%d",&x);
				se.insert(x);stk.push(x);
			}
			if(*op=='Q')
			{
				int x;scanf("%d",&x);
				int res = *se.upper_bound(x) - *(--se.upper_bound(x)) - 1;
				if(se.count(x)) res=0;
				printf("%d\n",res);
			}
			if(*op=='R'&&!stk.empty()) se.erase(stk.top()),stk.pop();
		}
	}
	return 0;
}
举报

相关推荐

0 条评论