模板题>.<当初学了一波又忘了

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<iomanip>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define MIN(a,b) a<b ? a:b using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f; int ml[N<<],mr[N<<],lr[N<<],ans;
void btree(int l,int r,int rt)
{
ml[rt]=mr[rt]=lr[rt]=r-l+;
if(l==r)return ;
int m=(l+r)>>;
btree(ls);
btree(rs);
}
void update(int l,int r,int rt,int x,int c)
{
if(l==r)
{
ml[rt]=mr[rt]=lr[rt]=c;
return ;
}
int m=(l+r)>>;
if(x<=m)update(ls,x,c);
else update(rs,x,c);
if((ml[rt]=ml[rt<<])==m-l+)ml[rt]+=ml[rt<<|];
if((mr[rt]=mr[rt<<|])==r-m)mr[rt]+=mr[rt<<];
lr[rt]=max(max(lr[rt<<],lr[rt<<|]),mr[rt<<]+ml[rt<<|]);
}
void query(int l,int r,int rt,int x)
{
if(l==r||lr[rt]==||lr[rt]==r-l+)
{
ans+=lr[rt];
return ;
}
int m=(l+r)>>;
if(x<=m)
{
if(x>m-mr[rt<<])query(ls,x),query(rs,m+);
else query(ls,x);
}
else
{
if(x<m++ml[rt<<|])query(ls,m),query(rs,x);
else query(rs,x);
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
int n,m;
while(cin>>n>>m){
btree(,n,);
stack<int>st;
while(m--){
string s;
cin>>s;
if(s[]=='D')
{
int x;
cin>>x;
st.push(x);
update(,n,,x,);
}
else if(s[]=='R')
{
update(,n,,st.top(),);
st.pop();
}
else
{
ans=;
int x;
cin>>x;
query(,n,,x);
cout<<ans<<endl;
}
}
}
return ;
}

hdu1540线段树连续区间的更多相关文章

  1. hdu-1540线段树刷题

    title: hdu-1540线段树刷题 date: 2018-10-18 19:55:21 tags: acm 刷题 categories: ACM-线段树 概述 哇,,,这道线段树的题可以说是到目 ...

  2. Tunnel Warfare(HDU1540+线段树+区间合并)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1540 题目: 题意:总共有n个村庄,有q次操作,每次操作分为摧毁一座村庄,修复一座村庄,和查询与询问的 ...

  3. Tunnel Warfare(hdu1540 线段树)

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

  4. hdu1540线段树

    https://vjudge.net/contest/66989#problem/I #include<iostream> #include<cstdio> #include& ...

  5. HDU1540(线段树统计连续长度)

    ---恢复内容开始--- Tunnel Warfare Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d &am ...

  6. Codeforces343D(SummerTrainingDay06-F dfs序+线段树)

    D. Water Tree time limit per test:4 seconds memory limit per test:256 megabytes input:standard input ...

  7. Tunnel Warfare(线段树取连续区间)

    emmmmmmmm我菜爆了 思路来自:https://blog.csdn.net/chudongfang2015/article/details/52133243 线段树最难的应该就是要维护什么东西 ...

  8. CodeForces - 150C :Smart Cheater (线段树,求最大连续区间)

    I guess there's not much point in reminding you that Nvodsk winters aren't exactly hot. That increas ...

  9. Tunnel Warfare HDU - 1540 (线段树处理连续区间问题)

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

随机推荐

  1. 读写INI配置文件。

    核心函数: 写入.ini文件:bool WritePrivateProfileString(LPCTSTR lpAppName,//INI文件中的一个字段名 LPCTSTR lpKeyName,//l ...

  2. Linux系统——sed命令

    sed命令精讲 cat工作原理 cat命令只想文件,把文件打开后,将文件中所有内容一次性读到内存中,从内存里一次性输出到屏幕上,此时可能存在内存装不下的情况,因此cat命令只能查看小文件内容,不能读取 ...

  3. 转:js获取json中key所对应的value值

    <script type="text/javascript"> getJson('age'); function getJson(key){ var jsonObj={ ...

  4. Windows 配置安卓环境变量

    变量名:JAVA_HOME 变量值:JDK 路径 变量名:CLASSPATH 变量值:.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\toos.jar      // ...

  5. 使用Spring Session和Redis解决分布式Session跨域共享问题

    http://blog.csdn.net/xlgen157387/article/details/57406162 使用Spring Session和Redis解决分布式Session跨域共享问题

  6. javascript 设置元素滚动大小

    3. 滚动大小 最后要介绍的是滚动大小(scroll dimension),指的是包含滚动内容的元素的大小. 有些元素(例如 元素),即使没有执行任何代码也能自动地添加滚动条:但另外一些元素,则需要通 ...

  7. Spring Boot+BootStrap fileInput 多图片上传

    一.依赖文件 <link rel="stylesheet" type="text/css" th:href="@{/js/bootstrap/c ...

  8. 对于JVM中方法区,永久代,元空间以及字符串常量池的迁移和string.intern方法

    在Java虚拟机(以下简称JVM)中,类包含其对应的元数据,比如类的层级信息,方法数据和方法信息(如字节码,栈和变量大小),运行时常量池,已确定的符号引用和虚方法表. 在过去(当自定义类加载器使用不普 ...

  9. context.Request方法总结

    Request.Params为获取的包含上述两种集合外,还包括当前运行环境变量,COOKIES等的集合.Request.QueryString["param"] getReques ...

  10. addEventListener、onclick和jquery的bind()、click()

    addEventListener("click",function(event){},false); removeEventListener("click",f ...