cdoj 秋实大哥与战争
首先,显然每个区间的最长连续子区间要么在左孩子里,要么在右孩子里,要么跨越两个孩子。于是我们可以对每个区间维护如下信息ll(left long),rl(rigth long),ml(mid long)分别表示前缀最长长度,后缀最长长度,中间的最长区间长度,并维护即可。
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<string> using namespace std; struct Tree{
int l,r;
int ll,rl,ml;
}; int n,m;
Tree T[]; void buildtree(int now,int l,int r){
T[now].ll=T[now].rl=T[now].ml=r-l+;
T[now].l=l;
T[now].r=r;
if (l==r) return;
buildtree(now<<,l,(l+r)>>);
buildtree((now<<)|,((l+r)>>)+,r);
} void update(int now,int aim,int val){
if (T[now].l==T[now].r){
T[now].ll=T[now].rl=T[now].ml=val;
return;
}
int mid=(T[now].l+T[now].r)>>;
if (aim<=mid) update(now<<,aim,val);
else update((now<<)|,aim,val);
T[now].ll=T[now<<].ll;
T[now].rl=T[(now<<)|].rl;
if (T[now<<].ll==(T[now<<].r-T[now<<].l+)) T[now].ll=T[now].ll+T[(now<<)|].ll;
if (T[(now<<)|].rl==T[(now<<)|].r-T[(now<<)|].l+) T[now].rl+=T[now<<].rl;
T[now].ml=max(T[now<<].ml,T[(now<<)|].ml);
T[now].ml=max(T[now].ml,T[now<<].rl+T[(now<<)|].ll);
} int query(int now,int aim){
if (T[now].l==T[now].r || T[now].ml== || T[now].ml==T[now].r-T[now].l+){
return T[now].ml;
}
int mid=(T[now].l+T[now].r)>>;
if (aim<=mid){
if (aim>=T[now<<].r-T[now<<].rl+)
return query(now<<,aim)+query((now<<)|,mid+);
else
return query(now<<,aim);
}
else{
if (aim<=T[(now<<)|].l+T[(now<<)|].ll-)
return query((now<<)|,aim)+query(now<<,mid);
else
return query((now<<)|,aim);
}
} int main(){
scanf("%d%d",&n,&m);
buildtree(,,n);
for (int cas=;cas<=m;cas++){
int f,x;
scanf("%d%d",&f,&x);
if (f==){
update(,x,);
}
if (f==){
update(,x,);
}
if (f==){
printf("%d\n",query(,x));
}
checktree(,,n);
}
return ;
}
/*
5 3
2 2
0 3
2 2 5 5
2 2
0 3
2 2
1 3
2 2
*/
cdoj 秋实大哥与战争的更多相关文章
- CDOJ 1061 C - 秋实大哥与战争 STL set 迭代器
题目链接: C - 秋实大哥与战争 Time Limit:1000MS Memory Limit:65535KB 64bit IO Format:%lld & %llu Sub ...
- UESTC_秋实大哥与战争 2015 UESTC Training for Data Structures<Problem D>
D - 秋实大哥与战争 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Subm ...
- 2015 UESTC 数据结构专题D题 秋实大哥与战争 SET的妙用
D - 秋实大哥与战争 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 D ...
- 2015 UESTC 数据结构专题D题 秋实大哥与战争 变化版本的线段树,合并区间,单点查询
D - 秋实大哥与战争 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 D ...
- UESTC 1061 秋实大哥与战争 线段树区间合并
秋实大哥与战争 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) 男儿何不带吴钩, ...
- E - 秋实大哥与战争
秋实大哥与战争 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit S ...
- cdoj 秋实大哥搞算数
地址:http://acm.uestc.edu.cn/#/contest/show/95 题目: N - 秋实大哥搞算数 Time Limit: 3000/1000MS (Java/Others) ...
- cdoj 秋实大哥带我飞 最短路走法 含0权边
//做完这题以后终于理解白书上的边为什么要那样定义了 可以很方便的在o(1) 时间内找到反向边 解法:先跑一边最短路,然后检查最短路上有没有0权边(dfs就好,但是每条边只能走一次,这里就需要用异或找 ...
- CDOJ 1146 A - 秋实大哥与连锁快餐店 最小生成树 Prim算法 稠密图
题目链接 A - 秋实大哥与连锁快餐店 Time Limit:3000MS Memory Limit:65535KB 64bit IO Format:%lld & %llu S ...
随机推荐
- SQL Server 无法启动的 4 种原因
SQL Server 无法启动的原因定位.首先要知道SQL Server 启动的过程. 第一步: 读取注册表,创建log文件.检测硬件.初始化系统配置. 第二步: 启动系统数据库. 第三步: 准备好网 ...
- Android 控件属性
TextView 文字属性//文字左右居中android:layout_centerHorizontal="true"//文字垂直居中android:layout_centerVe ...
- 观察者模式模拟YUI事件机制
首先介绍下YUI的事件机制,很好理解,因为和浏览器事件机制差不多.看懂下面几个方法就可以了: publish: 创建自定义事件.第一个参数是事件类型,第二个参数是一个对象,里面可以设置默认动作 on: ...
- QReadWriteLock读写锁的一点测试(它是逻辑锁,并没有与实物相联系),只有锁住了读,才允许再次读,否则一概不允许
QReadWriteLock m_lock; void MyWidget::Button1(){ m_lock.lockForRead(); ShowMessage(tr("111" ...
- 隐私模式启动IE 谷歌浏览器
C:\Program Files (x86)\Internet Explorer\iexplore.exe -privateC:\Program Files (x86)\Google\Chrome\A ...
- Lipschitz连续【zz】
转载地址:http://moosewoler.blog.163.com/blog/static/6986605201242643122296/ 李普希兹连续是以德国数学家Rudolf Lipschit ...
- hdu 1715 大菲波数_java
用java的大数解决 import java.math.BigInteger; import java.util.Scanner; public class Main { public static ...
- 何谓Dandy?它是一种着装风格
何谓Dandy?它是一种着装风格_女性_腾讯网 何谓Dandy?它是一种着装风格 2012年02月17日09:47腾讯专稿我要评论(0) 字号:T|T 何谓Dandyism?它是一种风格,词根Da ...
- animate CSS动画程序接口(仅Chrome可用)
jQuery中很早就提供了animate方法,使用它可以很方便地实现一些简单动画效果.后来CSS3中也提供了animation用于动画效果制作,但CSS本身的可操作性太差,所以用起来并不方便.现在最新 ...
- 【二分+最大团】【HDU3585】【maximum shortest distance】
题目大意 在N个点钟 选出K个点 使得这K个点间的最小距离最大 二分距离,然后如果两点间距离小于它的边当做不存在,求出最大团,如果最大团>=K,向上缩小区间 < K , 向下缩小区间 ...