hdu3308 LCIS(简单线段树)
来源:互联网 发布:linux搜狗输入法激活 编辑:程序博客网 时间:2024/06/05 03:45
LCIS
Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2988 Accepted Submission(s): 1307
Problem Description
Given n integers.
You have two operations:
U A B: replace the Ath number by B. (index counting from 0)
Q A B: output the length of the longest consecutive increasing subsequence (LCIS) in [a, b].
You have two operations:
U A B: replace the Ath number by B. (index counting from 0)
Q A B: output the length of the longest consecutive increasing subsequence (LCIS) in [a, b].
Input
T in the first line, indicating the case number.
Each case starts with two integers n , m(0<n,m<=105).
The next line has n integers(0<=val<=105).
The next m lines each has an operation:
U A B(0<=A,n , 0<=B=105)
OR
Q A B(0<=A<=B< n).
Each case starts with two integers n , m(0<n,m<=105).
The next line has n integers(0<=val<=105).
The next m lines each has an operation:
U A B(0<=A,n , 0<=B=105)
OR
Q A B(0<=A<=B< n).
Output
For each Q, output the answer.
Sample Input
110 107 7 3 3 5 9 9 8 1 8 Q 6 6U 3 4Q 0 1Q 0 5Q 4 7Q 3 5Q 0 2Q 4 6U 6 10Q 0 9
Sample Output
11423125
Author
shǎ崽
题目大意:给一串数字,1种操作,将第a个数改成b;一种查询,查询区间[a,b]的LICS。
题目分析:跟这种题一个类型,同时维护端点左右连续值就可以了。详情请见代码:
#include <iostream>#include<cstdio>#include<cstring>using namespace std;const int N = 100005;struct node{ int lc,rc;//区间左右LCIS int lv,rv;//区间左右端点值 int ans;//区间LCIS}tree[N<<2];int m,n;int Max(int a,int b){ return a > b?a:b;}int Min(int a,int b){ return a > b?b:a;}void pushup(int num,int s,int e){ int ls = num<<1; int rs = num<<1|1; int mid = (s + e)>>1; tree[num].lv = tree[ls].lv; tree[num].rv = tree[rs].rv; tree[num].lc = tree[ls].lc; if(tree[ls].ans == mid - s + 1 && tree[ls].rv < tree[rs].lv) tree[num].lc += tree[rs].lc; tree[num].rc = tree[rs].rc; if(tree[rs].ans == e - mid && tree[rs].lv > tree[ls].rv) tree[num].rc += tree[ls].rc; int cmp = Max(tree[ls].rc,tree[rs].lc); if(tree[ls].rv < tree[rs].lv) cmp = tree[ls].rc + tree[rs].lc; tree[num].ans = Max(tree[ls].ans,Max(tree[rs].ans,cmp));}void build(int num,int s,int e){ if(s == e) { scanf("%d",&tree[num].lv); tree[num].rv = tree[num].lv; tree[num].lc = tree[num].rc = 1; tree[num].ans = 1; return; } int mid = (s + e)>>1; build(num<<1,s,mid); build(num<<1|1,mid + 1,e); pushup(num,s,e);}void update(int num,int s,int e,int pos,int val){ if(s == e) { tree[num].lv = tree[num].rv = val; return; } int mid = (s + e)>>1; if(pos <= mid) update(num<<1,s,mid,pos,val); else update(num<<1|1,mid + 1,e,pos,val); pushup(num,s,e);}int query(int num,int s,int e,int l,int r){ if(s == l && r == e) { return tree[num].ans; } int mid = (s + e)>>1; if(r <= mid) return query(num<<1,s,mid,l,r); else { if(l > mid) return query(num<<1|1,mid + 1,e,l,r); else { int ta = Min(tree[num<<1].rc,mid - l + 1); int tb = Min(tree[num<<1|1].lc,r - mid); int middle = Max(ta,tb); if(tree[num<<1].rv < tree[num<<1|1].lv) middle = ta + tb; return Max(query(num<<1,s,mid,l,mid),Max(query(num<<1|1,mid + 1,e,mid + 1,r),middle)); } }}int main(){ int t; char op[3]; int a,b; scanf("%d",&t); while(t --) { scanf("%d%d",&n,&m); build(1,1,n); while(m --) { scanf("%s",op); scanf("%d%d",&a,&b); if(op[0] == 'Q') printf("%d\n",query(1,1,n,a + 1,b + 1)); else update(1,1,n,a + 1,b); } } return 0;}//343MS5376K
- hdu3308 LCIS(简单线段树)
- hdu3308 LCIS 线段树 难题
- HDU3308:LCIS(线段树区间合并)
- hdu3308 LCIS(线段树区间合并)
- hdu3308 LCIS 线段树 区间合并
- 线段树区间合并 hdu3308 LCIS
- HDU3308-LCIS-线段树区间合并
- HDU3308 LCIS(线段树区间合并)
- HDU3308 LCIS
- HDU3308--LCIS
- hdu3308 LCIS
- HDU3308 LCIS
- hdu3308----LCIS
- hdu3308 LCIS
- hdu3308 LCIS
- HDU3308-LCIS
- HDU3308 LCIS
- 线段树区间合并(POJ 3667 Hotel ,HDU HDU3308 LCIS)
- PreSubclassWindow详细分析
- 使用Rspec进行rails测试详解1-Transactions
- 输出页面加载时间或者方法执行耗费时间
- iOS中登录功能的体验探究
- openstack quantum获取metadata的测试
- hdu3308 LCIS(简单线段树)
- Sprite Kit编程指南(4)-构建场景
- 黑马程序员-高新技术(JavaBean)
- Android之ActivityManager简介(一)
- Linux 信号signal处理机制
- 怎么样很好的理解typedef
- ArcEngine filegeodatabase锁定文件 .Lock
- Android Application的作用
- Decorators and Functional Python