Qiuqiqiu  
不管道路多么崎岖坎坷,我永远不停下追逐梦想的脚步!

http://acm.hdu.edu.cn/showproblem.php?pid=3308

View Code
 1 //HDU 3308
2 #include <cstdio>
3 using namespace std;
4 const int N=100100;
5 struct segtree
6 {
7 int l,r,s,ls,rs;
8 int m() {return (l+r)/2;}
9 int len() {return r-l+1;}
10 }st[N*4];
11 int a[N];
12 void pushup(int rt)
13 {
14 int lrt=rt*2,rrt=rt*2+1;
15 st[rt].s=st[lrt].s>st[rrt].s?st[lrt].s:st[rrt].s;
16 st[rt].ls=st[lrt].ls;
17 st[rt].rs=st[rrt].rs;
18 int m=st[rt].m();
19 if (a[m]<a[m+1])
20 {
21 if (st[lrt].rs+st[rrt].ls>st[rt].s)
22 st[rt].s=st[lrt].rs+st[rrt].ls;
23 if (st[lrt].ls==st[lrt].len())
24 st[rt].ls+=st[rrt].ls;
25 if (st[rrt].rs==st[rrt].len())
26 st[rt].rs+=st[lrt].rs;
27 }
28 }
29 void build(int l,int r,int rt)
30 {
31 st[rt].l=l; st[rt].r=r;
32 if (l==r)
33 {
34 st[rt].s=st[rt].ls=st[rt].rs=1;
35 return;
36 }
37 int m=st[rt].m();
38 build(l,m,rt*2);
39 build(m+1,r,rt*2+1);
40 pushup(rt);
41 }
42 void update(int p,int rt)
43 {
44 int l=st[rt].l,r=st[rt].r;
45 if (l==r) return;
46 int m=st[rt].m();
47 if (p<=m) update(p,rt*2);
48 else update(p,rt*2+1);
49 pushup(rt);
50 }
51 int query(int L,int R,int rt)
52 {
53 int l=st[rt].l,r=st[rt].r;
54 if (L<=l && r<=R) return st[rt].s;
55 int m=st[rt].m();
56 int s1=0,s2=0;
57 int lrt=rt*2,rrt=rt*2+1;
58 if (L<=m) s1=query(L,R,lrt);
59 if (R>m) s2=query(L,R,rrt);
60 int s=s1>s2?s1:s2;
61 if (a[m]<a[m+1])
62 {
63 s1=m-L+1<st[lrt].rs?m-L+1:st[lrt].rs;
64 s2=R-m<st[rrt].ls?R-m:st[rrt].ls;
65 if (s1+s2>s) s=s1+s2;
66 }
67 return s;
68 }
69 int main()
70 {
71 int T;
72 scanf("%d",&T);
73 int n,m,i;
74 while (T--)
75 {
76 scanf("%d%d",&n,&m);
77 for (i=0;i<n;i++) scanf("%d",&a[i]);
78 build(0,n-1,1);
79 char op[2];
80 int x,y;
81 while (m--)
82 {
83 scanf("%s%d%d",op,&x,&y);
84 if (op[0]=='U')
85 {
86 a[x]=y;
87 update(x,1);
88 }
89 else
90 {
91 int s=query(x,y,1);
92 printf("%d\n",s);
93 }
94 }
95 }
96 return 0;
97 }

 

posted on 2012-02-28 22:21  Qiuqiqiu  阅读(206)  评论(0编辑  收藏  举报