分析:不需要线段树,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. cocos2dx游戏资源加密之XXTEA

    在手机游戏当中,游戏的资源加密保护是一件很重要的事情. 我花了两天的时间整理了自己在游戏当中的资源加密问题,实现了跨平台的资源流加密,这个都是巨人的肩膀之上的. 大概的思路是这样的,游戏资源通过XXT ...

  2. Android中9patch图片格式(xx.9.png)介绍与制作详解

    一:9patch图片介绍: android的.9.png是android系统中一种特殊的图片格式,专门用来用来处理图片大小变化后(如拉伸)的失真,不正常,如我们看到的qq聊天中的文字气泡,不管你输入的 ...

  3. Qt库的静态编译

    一.准备软件1. MinGW     (C:\Qt\MinGW)http://pan.baidu.com/share/link?shareid=174269&uk=673227135这个文件解 ...

  4. 1187: [HNOI2007]神奇游乐园 - BZOJ

    Description 经历了一段艰辛的旅程后,主人公小P乘坐飞艇返回.在返回的途中,小P发现在漫无边际的沙漠中,有一块狭长的绿地特别显眼.往下仔细一看,才发现这是一个游乐场,专为旅途中疲惫的人设计. ...

  5. mysql 获取季度的第一天 本月的第一天,本周的第一天sql语句(转)

    感谢:http://www.111cn.net/database/110/d45124323da8d2d87b80f78319987eda.htm 查看同主题的另一篇博客:http://blog.cs ...

  6. [转载]C#中播放背景音乐几种的方法

    最经在写winform程序,其中有用到播放背景音乐 特此收集了一些网上的教程: 1.调用非托管的dll using System.Runtime.InteropServices; //DllImpor ...

  7. KafkaSpout: PartitionManager的行为分析

    KafkaSpout的核心逻辑都是由PartitionManager来实现的. 但是这个类实现时候需要考虑的东西有些多,0.92至0.93,至当前(2015.3.14)的master一直在变化.在这里 ...

  8. minicom 配置

    问题: 1:不相应按键,只有打印 Hardware Flow Control 选择NO minicom显示中文的设置:              env LANG=en_US minicom   可以 ...

  9. Servlet课程0424(三) 通过继承HttpServlet来开发Servlet

    //这是第三种开发servlet的方法,通过继承httpservlet package com.tsinghua; import javax.servlet.http.*; import java.i ...

  10. Cygwin安装时,选择163的源后出错:Unable to get setup.ini from <http://mirrors.163.com/cygwin/>

    [问题] 折腾: [记录]Cygwin下把make从v3.82换成v3.81 期间,选择了163的源,结果出错: Cygwin Setup Unable to get setup.ini from & ...