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 ...
随机推荐
- CodeForces 214B Hometask
本题求n个数组成的大数,要求是2,3,5的倍数. 因为是2 和5 的倍数,所以个位为 0:所以若n个数中没有0,直接输出-1: 难点就是要求为3 的倍数. 因为若某个数为3的倍数,则其各位数的和必然是 ...
- JQuery 的基本命令
调用jquery的格式 <script> $(document).ready(function() { }); </script> 笔记 1.现在让我们开始写第 ...
- Apriori algorithm
本文是个人对spmf中example1. mining frequent itemsets by using the apriori algorithm的学习. What is Apriori? A ...
- 我所不知道的 Chrome 开发者工具
http://www.oschina.net/translate/things-i-didnt-know-about-chrome-devtools 自打我开始进行Web开发后,我就一直将Firebu ...
- inno setup 跳过(Welcome)欢迎界面
原文 http://zwkufo.blog.163.com/blog/static/25882512010816049549/ 在InnoSetup中,我们很容易用 function ShouldSk ...
- Android Studio中获取sha1证书指纹数据的方法
高德地图开发申请KEY的时候需要开发者提供SHA1证书指纹数据,在eclipse很容易就找到了,但是Android Studio很久也没找到,只能使用在网上看到的方法了,在Android Studio ...
- cf459E Pashmak and Graph
E. Pashmak and Graph time limit per test 1 second memory limit per test 256 megabytes input standard ...
- [Leetcode][Python]42: Trapping Rain Water
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 42: Trapping Rain Waterhttps://oj.leetc ...
- C#版QQTea加密
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Wind ...
- Knime 使用 初探
使用数据挖掘工具 Knime,分析某公司用户使用情况. 首先,打开csv文件数据,看到有以下门类: 时间.track id 歌曲名.用户行为.用户id.日期.snap_id 即歌曲门类 然后,打开Kn ...