分析:不需要线段树,set可过,STL大法好

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <stack>
using namespace std;
const int N=5e4+;
set<int>s;
bool d[N];
stack<int>p;
char o[];
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
memset(d,,sizeof(d));
while(!p.empty())p.pop();
s.clear();
while(m--)
{
int u;
scanf("%s",o);
if(o[]=='R')
{
u=p.top();
p.pop();
d[u]=;
if(s.find(u)!=s.end())s.erase(u);
}
else if(o[]=='D')
{
scanf("%d",&u);
d[u]=;
if(s.find(u)==s.end())s.insert(u);
p.push(u);
}
else
{
scanf("%d",&u);
if(d[u])printf("0\n");
else
{
set<int>::iterator it=s.lower_bound(u);
int ans=n;
if(it!=s.end())ans=(*it)-;
ans=ans-u;
int x;
if(it==s.begin())x=;
else
{
it--;
x=(*it);
}
ans+=u-x;
printf("%d\n",ans);
}
}
}
}
}

HDU1540 Tunnel Warfare 水题的更多相关文章

  1. HDU--1540 Tunnel Warfare(线段树区间更新)

    题目链接:1540 Tunnel Warfare 以为单组输入 这个题多组输入 结构体记录每个区间左边和右边的连续区间 ms记录最大 在查询操作时: 1.这个点即将查询到右区间 看这个点 x 是否存在 ...

  2. HDU1540 Tunnel Warfare —— 线段树 区间合并

    题目链接:https://vjudge.net/problem/HDU-1540 uring the War of Resistance Against Japan, tunnel warfare w ...

  3. HDU-1540 Tunnel Warfare(区间连续点长度)

    http://acm.hdu.edu.cn/showproblem.php?pid=1540 Time Limit: 4000/2000 MS (Java/Others)    Memory Limi ...

  4. hdu1540 Tunnel Warfare

    Tunnel Warfare Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  5. hdu1540 Tunnel Warfare 线段树/树状数组

    During the War of Resistance Against Japan, tunnel warfare was carried out extensively in the vast a ...

  6. hdu1540 Tunnel Warfare【线段树】

    During the War of Resistance Against Japan, tunnel warfare was carried out extensively in the vast a ...

  7. HDU1540 Tunnel Warfare(线段树区间维护&求最长连续区间)题解

    Tunnel Warfare Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  8. kuangbin专题七 HDU1540 Tunnel Warfare (前缀后缀线段树)

    During the War of Resistance Against Japan, tunnel warfare was carried out extensively in the vast a ...

  9. Tunnel Warfare(hdu1540 线段树)

    Tunnel Warfare Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

随机推荐

  1. 【BZOJ 1877】 [SDOI2009]晨跑

    Description Elaxia最近迷恋上了空手道,他为自己设定了一套健身计划,比如俯卧撑.仰卧起坐等 等,不过到目前为止,他坚持下来的只有晨跑. 现在给出一张学校附近的地图,这张地图中包含N个十 ...

  2. 企业应用的Web程序的安全性

    提起安全性这个话题,大家恐怕依稀还记得Sony的PSP账户信息泄露的事故造成的重大损失.但是又隐隐觉得这事儿离我很远,无需过多考虑.也有的人会想,我们做的是企业内部系统所以不必太在意.但是,Web程序 ...

  3. js解决checkbox全选和反选的问题

    function SelectAll() { var checkboxs=document.getElementsByName("chk_list"); for (var i=0; ...

  4. python time模块详解

    python time模块详解 转自:http://blog.csdn.net/kiki113/article/details/4033017 python 的内嵌time模板翻译及说明  一.简介 ...

  5. POJ3697+BFS+hash存边

    /* 疾速优化+hash存边 题意:给定一个包含N(1 ≤ N ≤ 10,000)个顶点的无向完全图,图中的顶点从1到N依次标号.从这个图中去掉M(0 ≤ M ≤ 1,000,000)条边,求最后与顶 ...

  6. POJ1151+线段树+扫描线

    /* 线段树+扫描线+离散化 求多个矩形的面积 */ #include<stdio.h> #include<string.h> #include<stdlib.h> ...

  7. 【无聊放个模板系列】BZOJ 1597 斜率优化

    STL 双向队列DEQUE版本 #include<cstdio> #include<cstdlib> #include<cstring> #include<i ...

  8. UIALertView的基本用法与UIAlertViewDelegate对对话框的事件处理方法

    首先,视图控制器必须得实现协议UIAlertViewDelegate中的方法,并指定delegate为self,才能使弹出的Alert窗口响应点击事件. 具体代码如下: ViewController. ...

  9. 【转】VMware设置共享文件夹之后Ubuntu中看不到怎么办?

    一.共享文件夹设置好了,但是在虚拟机中的Ubuntu系统下却看不到,怎么办? 一种可能的原因是系统没有自动挂载,解决办法: 1.安装:               sudo apt-get insta ...

  10. JixiPix 各种图像软件,很不错的说,还有affinity designer

    http://jixipix.com/purchase.html https://www.board4allcz.eu/showthread.php?t=639107 https://affinity ...