hdu1540线段树连续区间
模板题>.<当初学了一波又忘了
#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线段树连续区间的更多相关文章
- hdu-1540线段树刷题
title: hdu-1540线段树刷题 date: 2018-10-18 19:55:21 tags: acm 刷题 categories: ACM-线段树 概述 哇,,,这道线段树的题可以说是到目 ...
- Tunnel Warfare(HDU1540+线段树+区间合并)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1540 题目: 题意:总共有n个村庄,有q次操作,每次操作分为摧毁一座村庄,修复一座村庄,和查询与询问的 ...
- Tunnel Warfare(hdu1540 线段树)
Tunnel Warfare Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- hdu1540线段树
https://vjudge.net/contest/66989#problem/I #include<iostream> #include<cstdio> #include& ...
- HDU1540(线段树统计连续长度)
---恢复内容开始--- Tunnel Warfare Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d &am ...
- Codeforces343D(SummerTrainingDay06-F dfs序+线段树)
D. Water Tree time limit per test:4 seconds memory limit per test:256 megabytes input:standard input ...
- Tunnel Warfare(线段树取连续区间)
emmmmmmmm我菜爆了 思路来自:https://blog.csdn.net/chudongfang2015/article/details/52133243 线段树最难的应该就是要维护什么东西 ...
- CodeForces - 150C :Smart Cheater (线段树,求最大连续区间)
I guess there's not much point in reminding you that Nvodsk winters aren't exactly hot. That increas ...
- Tunnel Warfare HDU - 1540 (线段树处理连续区间问题)
During the War of Resistance Against Japan, tunnel warfare was carried out extensively in the vast a ...
随机推荐
- 给定1-a的随机数生成器,产生1-b的随机数生成器
转自http://www.code123.cc/959.html 先给出一个例子,后面会有扩展 题目 给你一个能生成1到5随机数的函数,用它写一个函数生成1到7的随机数. (即:使用函数rand5() ...
- select 自动选择 检查下拉列表
下面我们来看一下selenium webdriver是如何来处理select下拉框的,以Apple注册页面为例. https://appleid.apple.com/cgi-bin/WebObject ...
- python16_day21【git and celery】
一.Git使用 ## GIT常用执令说明 * 初始化git项目 > git init * 查看当前目录状态 > git status * 把代码提交到stage区 > git add ...
- 【转】Google的2012论文
转自:http://www.sigvc.org/bbs/thread-1152-1-1.html Google的论文一直是业界的风向标,尤其在机器学习.分布式系统.网络等方面很多创新性的成果都是由他们 ...
- Winter-1-B Sum 解题报告及测试数据
Time Limit:500MS Memory Limit:32768KB Description Hey, welcome to HDOJ(Hangzhou Dianzi University O ...
- maven install jdk版本自动降为1.7
开发过程中遇到了一个奇怪的现象. IDEA中所有的设置都改成了1.8,但是在执行maven install时却自动降为1.7,报错提示: [ERROR] Failed to execute goal ...
- 今天刚接触lua 写写环境配置和基本设置
首先是安装开发工具: Quick: http://www.tairan.com/engines-download 引擎 Sublime Text的下载地址为:http://www.sublimetex ...
- Hibernate与autoCommit
JDBC 的autoCommit属性 对于每一个 JDBC connection,都有一个autoCommit属性,只有执行commit后,该connection中的操作(statement操作)才会 ...
- python---自动群发邮件
生活中我们经常发送邮件,那么我们能不能用Python写一个自动发送邮件的功能呢?答案是肯定的!!! 开始实现功能之前我们需要开启我们邮箱的 IMAP/SMTP功能,我们先了解一下什么是IMAP/SMT ...
- 20145309java第三次实验报告
实验三 敏捷开发与XP实践 实验内容 •下载并学会使用git上传代码: •与同学结对,相互下载并更改对方代码,并上传: •实现代码的重载. 实验步骤 下载并用git上传代码: •1.下载并安装好git ...