HDU1540 Turnal Warfare
线段树保存每个区间的左边最大连续长度和右边最大连续长度~
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
using namespace std;
const int maxn=1e6+;
struct node {
int l,r;
int ll,rl,ml;
//左边开始连续的最大长度和右边开始连续的最大长度
//以及这个区间的最大连续长度
}segTree[maxn*];
void build (int i,int l,int r) {
segTree[i].l=l;
segTree[i].r=r;
segTree[i].ll=segTree[i].rl=segTree[i].ml=r-l+;
if (l==r) return;
int mid=(l+r)>>;
build (i<<,l,mid);
build (i<<|,mid+,r);
}
void update (int i,int t,int val) {
if (segTree[i].l==segTree[i].r) {
if (val==) segTree[i].ll=segTree[i].rl=segTree[i].ml=;
else segTree[i].ll=segTree[i].rl=segTree[i].ml=;
return;
}
int mid=(segTree[i].l+segTree[i].r)>>;
if (t<=mid) update (i<<,t,val);
else update (i<<|,t,val);
segTree[i].ll=segTree[i<<].ll;
segTree[i].rl=segTree[i<<|].rl;
segTree[i].ml=max(segTree[i<<].ml,segTree[i<<|].ml);
segTree[i].ml=max(segTree[i].ml,segTree[i<<].rl+segTree[i<<|].ll);
if (segTree[i<<].ll==segTree[i<<].r-segTree[i<<].l+) segTree[i].ll+=segTree[i<<|].ll;
if (segTree[i<<|].rl==segTree[i<<|].r-segTree[i<<|].l+)
segTree[i].rl+=segTree[i<<].rl;
}
int query (int i,int t) {
if (segTree[i].l==segTree[i].r||segTree[i].ml==||segTree[i].ml==segTree[i].r-segTree[i].l+)
return segTree[i].ml;
int mid=(segTree[i].l+segTree[i].r)>>;
if (t<=mid) {
if (t>=segTree[i<<].r-segTree[i<<].rl+)
return query (i<<,t)+query (i<<|,mid+);
else return query (i<<,t);
}
else {
if (t<=segTree[i<<|].l+segTree[i<<|].ll-)
return query (i<<|,t)+query(i<<,mid);
else return query (i<<|,t);
}
}
int a[maxn],top,n,m,x;
string s;
int main () {
while (~scanf ("%d %d",&n,&m)) {
build (,,n);
top=;
while (m--) {
cin>>s;
if (s=="D") {
scanf ("%d",&x);
a[top++]=x;
update (,x,);
}
else if (s=="Q") {
scanf ("%d",&x);
printf ("%d\n",query(,x));
}
else {
if (x>) {
x=a[--top];
update (,x,);
}
}
}
}
return ;
}
HDU1540 Turnal Warfare的更多相关文章
- HDU1540 Tunnel Warfare —— 线段树 区间合并
题目链接:https://vjudge.net/problem/HDU-1540 uring the War of Resistance Against Japan, tunnel warfare w ...
- hdu1540 Tunnel Warfare
Tunnel Warfare Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- HDU--1540 Tunnel Warfare(线段树区间更新)
题目链接:1540 Tunnel Warfare 以为单组输入 这个题多组输入 结构体记录每个区间左边和右边的连续区间 ms记录最大 在查询操作时: 1.这个点即将查询到右区间 看这个点 x 是否存在 ...
- hdu1540 Tunnel Warfare 线段树/树状数组
During the War of Resistance Against Japan, tunnel warfare was carried out extensively in the vast a ...
- hdu1540 Tunnel Warfare【线段树】
During the War of Resistance Against Japan, tunnel warfare was carried out extensively in the vast a ...
- HDU1540 Tunnel Warfare(线段树区间维护&求最长连续区间)题解
Tunnel Warfare Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- kuangbin专题七 HDU1540 Tunnel Warfare (前缀后缀线段树)
During the War of Resistance Against Japan, tunnel warfare was carried out extensively in the vast a ...
- HDU-1540 Tunnel Warfare(区间连续点长度)
http://acm.hdu.edu.cn/showproblem.php?pid=1540 Time Limit: 4000/2000 MS (Java/Others) Memory Limi ...
- HDU1540 Tunnel Warfare 水题
分析:不需要线段树,set可过,STL大法好 #include <iostream> #include <cstdio> #include <cstring> #i ...
随机推荐
- 【译】写个好的 CLI 程序
写个好的 CLI 程序 Write a Good CLI Program 译文 原文链接:https://qiita.com/tigercosmos/items/678f39b1209e60843cc ...
- EAC3 Transient Pre-Noise Processing
Transient pre-noise processing用于减少pre-noise的长度,pre-noise产生于low bitrate 编码存在transient matiral的场景. 当使用 ...
- sqlldr总结参数介绍
有效的关键字: userid -- ORACLE username/password control - 控制文件 log - 记录的日志文件 * 表示 ...
- C语言随笔3:指针定义、数据在地址中的大小端排列
指针变量:用于存放另一个变量的地址 (指针变量所占空间大小由操作系统决定32/64位 4/8字节 // 声明且定义:int *p=&a: 声明.定义:int *p: p= &a: ...
- kali中网卡、ssh、apache的配置与开启
在Kali-linux中修改网卡文件,启动ssh和apache服务的方法 1.su root //取得root权限 2.shift+字母 //大小写字母切换 3.修改网卡 ...
- drf框架,restful接口规范,源码分析
复习 """ 1.vue如果控制html 在html中设置挂载点.导入vue.js环境.创建Vue对象与挂载点绑定 2.vue是渐进式js框架 3.vue指令 {{ }} ...
- Opencv模块
参考博客:https://blog.csdn.net/u012679707/article/details/79505279
- opencv静态编译
在Windows下opencv静态编译. 使用cmake生成visual Studio 2015 解决方案如下图所示: 重点看红色框线里的内容,先编译ALL_BUILD,这样就把所有子项目编译成功.所 ...
- zookeeper集群搭建记录
本文仅记录zookeeper集群搭建的过程,留待日后查看.使用. 一.硬件机器: 192.168.183.195 master-node 192.168.183.194 data-node1 192. ...
- 隐藏pyqt中调用matplotlib图片中的工具栏
方法: # pyqtgraph使用matplotlib import pyqtgraph.widgets.MatplotlibWidget as mw a_plt = mw.MatplotlibWid ...