日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

【HDU】3308 LCIS

發布時間:2023/11/27 生活经验 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【HDU】3308 LCIS 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
 1 #include<cstdio>
 2 #define MAXN 100010
 3 struct node
 4 {
 5     int left,right,val;
 6 };
 7 int a[MAXN];
 8 node tree[MAXN<<2];
 9 inline int MAX(int x,int y)
10 {
11     return x>y?x:y;
12 }
13 inline int MIN(int x,int y)
14 {
15     return x>y?y:x;
16 }
17 inline void PushUp(int mid,int L,int R,int rt)
18 {
19     tree[rt].left=tree[rt<<1].left;
20     tree[rt].right=tree[rt<<1|1].right;
21     tree[rt].val=MAX(tree[rt<<1].val,tree[rt<<1|1].val);
22     if(a[mid]<a[mid+1])
23     {
24         if(tree[rt].left==mid-L+1)
25             tree[rt].left+=tree[rt<<1|1].left;
26         if(tree[rt].right==R-mid)
27             tree[rt].right+=tree[rt<<1].right;
28         tree[rt].val=MAX(tree[rt].val,tree[rt<<1].right+tree[rt<<1|1].left);
29     }
30 }
31 void Build(int L,int R,int rt)
32 {
33     if(L==R)
34     {
35         scanf("%d",&a[L]);
36         tree[rt].left=tree[rt].val=tree[rt].right=1;
37     }
38     else
39     {
40         int mid=(L+R)>>1;
41         Build(L,mid,rt<<1);
42         Build(mid+1,R,rt<<1|1);
43         PushUp(mid,L,R,rt);
44     }
45 }
46 void Update(int x,int val,int L,int R,int rt)
47 {
48     if(L==R)
49         a[L]=val;
50     else
51     {
52         int mid=(L+R)>>1;
53         if(mid>=x)
54             Update(x,val,L,mid,rt<<1);
55         else
56             Update(x,val,mid+1,R,rt<<1|1);
57         PushUp(mid,L,R,rt);
58     }
59 }
60 int Query(int x,int y,int L,int R,int rt)
61 {
62     if(x<=L&&R<=y)
63         return tree[rt].val;
64     int mid=(L+R)>>1,ans=0;
65     if(mid>=x)
66         ans=MAX(ans,Query(x,y,L,mid,rt<<1));
67     if(y>mid)
68         ans=MAX(ans,Query(x,y,mid+1,R,rt<<1|1));
69     if(a[mid]<a[mid+1])
70         ans=MAX(ans,MIN(mid-x+1,tree[rt<<1].right)+MIN(y-mid,tree[rt<<1|1].left));
71     return ans;
72 }
73 int main()
74 {
75     char ch;
76     int c,n,m,x,y;
77     scanf("%d",&c);
78     while(c--)
79     {
80         scanf("%d%d",&n,&m);
81         Build(1,n,1);
82         while(m--)
83         {
84             scanf(" %c%d%d",&ch,&x,&y);
85             if(ch=='U')
86                 Update(x+1,y,1,n,1);
87             else
88                 printf("%d\n",Query(x+1,y+1,1,n,1));
89         }
90     }
91     return 0;
92 }

轉載于:https://www.cnblogs.com/DrunBee/archive/2012/05/24/2516633.html

總結

以上是生活随笔為你收集整理的【HDU】3308 LCIS的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。