当前位置: 代码迷 >> 综合 >> HDU - 1540 Tunnel Warfare(set)
  详细解决方案

HDU - 1540 Tunnel Warfare(set)

热度:14   发布时间:2023-11-25 07:19:07.0

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;
}