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 ...
随机推荐
- SQL Server 2008数据库手动提交的设置
有时候我们需要对SQL Server 2008数据库手动提交的方法进行设置,使用Oracle的朋友会注意到Oracle中的手工提交的,如果修改错了数据还可以Rollback.但在SQL Server ...
- Linux的日志管理
Linux日志的管理 日志:记录了你几乎所有的操作记录,用于系统的审核,故障的排除.日志文件永久存放在日志目录中,系统日志保存在/var/log中 rsyslog 按照日志类型分类,把所有日志记录到/ ...
- 20165324《Java程序设计》第四周
学号 2016-2017-2 <Java程序设计>第四周学习总结 教材学习内容总结 第五章:子类与继承 子类的定义:class 子类名 extends 父类名 { ... } 子类继承性: ...
- Xcode插件开发案例教程
引言 在平时开发过程中我们使用了很多的Xcode插件,虽然官方对于插件制作没有提供任何支持,但是加载三方的插件,默认还是被允许的.第三方的插件,存放在 ~/Library/Application Su ...
- 2016-2017 National Taiwan University World Final Team Selection Contest A - Hacker Cups and Balls
题目: Dreamoon likes algorithm competitions very much. But when he feels crazy because he cannot figur ...
- IDEA 程序直接运行分析
今天用IDEA运行SpringBoot程序,启动时始终报错说读取不到datasource的url配置. 分析代码的resources目录,是有配置文件的,配置也是正常的.如下图: 后来经人指点,是因为 ...
- 你知道C语言为什么会有“_”(下划线)吗?
学过C语言的都知道,变量名只能由字母.数字.下划线组成,且只能以字母或者下划线开头. 学英语时我们都学过连字符(“-”),这个东东主要用来连接单词的.那么C语言为什么不直接 用连字符,而要改用下划线呢 ...
- 多媒体文件格式分析 MP3文件结构及编解码流程
多媒体文件格式分析 http://blog.csdn.net/taniya001/article/details/7962864 多媒体文件格式分析 MP3文件结构及编解码流程 http://www. ...
- Log4Net 日志文件分类保存
1.app.config <configSections> <section name="log4net" type="log4net.Config.L ...
- Android事件处理下(按键、触摸屏和滚动球的一些实现细节)
http://www.cnblogs.com/andtt/articles/2145563.html 对于按键事件,调用mDevices[i]->layoutMap->map进行映射.映射 ...