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

#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. C# 将 HTML 转换为图片或 PDF

    首先是把 HTML 转换为图片. public partial class Form1 : Form { public Form1() { InitializeComponent(); } WebBr ...

  2. smarty模板(转载)

    一.smarty的程序设计部分: 在smarty的模板设计部分我简单的把smarty在模板中的一些常用设置做了简单的介绍,这一节主要来介绍一下如何在smarty中开始我们程序设计.下载Smarty文件 ...

  3. mycat 指定mycat节点

    mycat 指定节点: /*!mycat:dataNode=order1*/select seq_nextval('APPOINTMENT_NO'); 指定节点创建存储过程或建表: /*!mycat: ...

  4. 带宽、流量、CDN

    1.啥叫带宽? 1.1 带宽的概念: 在网络中的带宽往往是指一个固定的时间内,能通过的最大位数据,即数据传输率.带宽是一个计量单位,用来计量单位时间内传输的数据量的多少. 1.2 计量单位: 这个数据 ...

  5. ISAP模板

    #include<bits/stdc++.h> using namespace std; using namespace std; typedef long long ll; const ...

  6. 关于js中的取值问题

    像这样是获取不到值的,弹出的消息是 underfined:<html><style type="text/css">input { border: 1px ...

  7. Ubuntu16.04安装和卸载MySQL 5.7

    介绍: MySQL 是一种开源数据库管理系统,通常作为流行的LAMP(Linux,Apache,MySQL,PHP / Python / Perl)堆栈的一部分安装.它使用关系数据库和SQL(结构化查 ...

  8. [原创]CSS 去掉点li 的点 使得LI前面的点不在显示

    我对博客的认识是:记录问题,解决问题,分享知识.如果有轮子,我不需要造轮子. 1.问题解决方式: 设置属性:li {list-style-type:none;} 2.更多属性参数参考 list-sty ...

  9. 基于Node.js的爬虫工具 – Node Crawler

    Node Crawler的目标是成为最好的node.js爬虫工具,目前已经停止维护. 我们来抓取光合新知博客tech栏目中的文章信息.访问http://dev.guanghe.tv/category/ ...

  10. 20145329 《Java程序设计》实验二总结

    实验指导教师:娄嘉鹏老师 实验日期:2016.4.12 实验时间:15:30~17:30 实验序号:实验二 实验名称:Java面向对象程序设计 实验目的与要求: 1.初步掌握单元测试和TDD 2.理解 ...