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

#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. POJ3281:Dining(dinic+拆点)

    题目链接:http://poj.org/problem?id=3281 PS:刷够网络流了,先这样吧,之后再刷,慢慢补. 题意:有F种食物,D种饮料,N头奶牛,只能吃某种食物和饮料(而且只能吃特定的一 ...

  2. 2-AMD

    诞生背景1.随着前端逻辑越来越多,项目越来越大,开发大型项目就必须分模块开发2.一切都那么完美,在NodeJs实现后,当人们开始热情的打算把这种实现也用于浏览器时,却发现并不适合.NodeJS应用加载 ...

  3. MySQL 温故知心(二) 事务的隔离级别

    事务的隔离级别 A事务做了操作 没有提交 对B事务来说 就等于没做 获取的都是之前的数据但是 在A事务中查询的话 查到的都是操作之后的数据没有提交的数据只有自己看得到,并没有update到数据库 查看 ...

  4. Kattis - virus【字符串】

    Kattis - virus[字符串] 题意 有一个正常的DNA序列,然后被病毒破坏.病毒可以植入一段DNA序列,这段插入DNA序列是可以删除正常DNA序列中的一个连续片段的. 简单来说就是,给你一段 ...

  5. hihocoder1478 水陆距离

    地址:http://hihocoder.com/problemset/problem/1478 题目: 水陆距离 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 给定一个 ...

  6. C#数组的Map、Filter、Reduce操作

    在Javascript.Python等语言里,Map.Filter和Reduce是数组的常用方法,可以让你在实现一些数组操作时告别循环,具有很高的实用价值.它们三个的意义大家应该都清楚,有一个十分形象 ...

  7. 谷歌技术"三宝"之BigTable(转)

    原文地址:   http://blog.csdn.net/opennaive/article/details/7532589 2006年的OSDI有两篇google的论文,分别是BigTable和Ch ...

  8. USBasp制作资料及全过程(菜鸟版)

    源:USBasp制作资料及全过程(菜鸟版) 一.usbasp 的一般性介绍: 1.下载线,是“ISP”(In System Programmability:“在系统编程”)或“IAP”(In Appl ...

  9. 【Python】高阶函数

    filter def is_palindrome(n): L = str(n) i = 0 j = len(L) - 1 while i != j: if L[i] != L[j]: return F ...

  10. Jquery编历数组

    <html> <head> <title>编历</title> <script type="text/javascript"& ...