首页 > 其他分享 >HDU 3308 LCIS

HDU 3308 LCIS

时间:2022-11-09 20:00:15浏览次数:56  
标签:lf HDU LCIS int rx rf lr 3308 lx


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].


 


Input


T in the first line, indicating the case number.
Each case starts with two integers n , m(0<n,m<=10 5).
The next line has n integers(0<=val<=10 5).
The next m lines each has an operation:
U A B(0<=A,n , 0<=B=10 5)
OR
Q A B(0<=A<=B< n).


 



Output


For each Q, output the answer.


 



Sample Input

1
10 10
7 7 3 3 5 9 9 8 1 8
Q 6 6
U 3 4
Q 0 1
Q 0 5
Q 4 7
Q 3 5
Q 0 2
Q 4 6
U 6 10
Q 0 9


 



Sample Output


1
1
4
2
3
1
2
5


线段树单点修改区间合并

#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn = 400005;
int n, m, T, l, r;
char s[2];

struct node
{
int l, lr, lf, r, rl, rf, m;
};

struct ST
{
int y;
node f[maxn], ans;
void merge(node &x, node &lx, node &rx)
{
x.lf = lx.lf; x.rf = rx.rf;
if (lx.lr == lx.r&&lx.rf < rx.lf) x.lr = rx.lr; else x.lr = lx.lr;
if (rx.rl == rx.l&&rx.lf > lx.rf) x.rl = lx.rl; else x.rl = rx.rl;
x.m = max(lx.m, rx.m);
if (lx.rf < rx.lf) x.m = max(x.m, rx.lr - lx.rl + 1);
}
void build(int x, int l, int r)
{
f[x].l = l; f[x].r = r;
if (l == r)
{
scanf("%d", &y);
f[x].lr = f[x].r;
f[x].rl = f[x].l;
f[x].lf = f[x].rf = y;
f[x].m = 1;
}
else
{
int mid = (l + r) >> 1;
build(x + x, l, mid);
build(x + x + 1, mid + 1, r);
merge(f[x], f[x + x], f[x + x + 1]);
}
}
void insert(int x, int l, int r, int u, int v)
{
if (l == r) f[x].lf = f[x].rf = v;
else
{
int mid = (l + r) >> 1;
if (u <= mid) insert(x + x, l, mid, u, v);
else insert(x + x + 1, mid + 1, r, u, v);
merge(f[x], f[x + x], f[x + x + 1]);
}
}
void find(int x, int l, int r, int ll, int rr)
{
if (ll <= l&&r <= rr)
{
if (ans.l == 0) ans = f[x];
else
{
node t = ans;
merge(ans, t, f[x]);
}
}
else
{
int mid = (l + r) >> 1;
if (ll <= mid) find(x + x, l, mid, ll, rr);
if (rr > mid) find(x + x + 1, mid + 1, r, ll, rr);
}
}
int solve(int l, int r)
{
ans.l = 0;
find(1, 1, n, l, r);
return ans.m;
}
}st;

int main()
{
scanf("%d", &T);
while (T--)
{
scanf("%d%d", &n, &m);
st.build(1, 1, n);
while (m--)
{
scanf("%s%d%d", s, &l, &r);
if (s[0] == 'Q') printf("%d\n", st.solve(l + 1, r + 1));
else st.insert(1, 1, n, l + 1, r);
}
}
return 0;
}



标签:lf,HDU,LCIS,int,rx,rf,lr,3308,lx
From: https://blog.51cto.com/u_15870896/5838709

相关文章

  • HDU 5874 Friends and Enemies
    ProblemDescriptionOnanisolatedisland,livedsomedwarves.Aking(notadwarf)ruledtheislandandtheseasnearby,thereareabundantcobblestones......
  • HDU 5876 Sparse Graph
    ProblemDescriptioncomplement ofagraph G isagraph H onthesameverticessuchthattwodistinctverticesof H areadjacentifand......
  • HDU 5877 Weak Pair
    ProblemDescriptionrooted treeof N nodes,labeledfrom1to N.Tothe ithnodeanon-negativevalue ai isassigned.An order......
  • HDU 5875 Function
    ProblemDescriptionTheshorter,thesimpler.Withthisproblem,youshouldbeconvincedofthistruth.    Youaregivenanarray A of ......
  • HDU 5320 Fan Li
    DescriptionFanLi(范蠡)wasanancientChineseadvisorinthestateofYueintheSpringandAutumnperiod.Heisasuccessfulmilitaristandasuccessf......
  • HDU 5399 Too Simple
    ProblemDescriptionRhasonCheunghadasimpleproblem,andaskedTeacherMaiforhelp.ButTeacherMaithoughtthisproblemwastoosimple,sometimesna......
  • HDU 5402 Travelling Salesman Problem
    ProblemDescriptionn rowsand m columns.Thereisanon-negativenumberineachcell.TeacherMaiwantstowalkfromthetopleftcorner (1,1......
  • HDU 1272 小希的迷宫
    ProblemDescription上次Gardon的迷宫城堡小希玩了很久(见ProblemB),现在她也想设计一个迷宫让Gardon来走。但是她设计迷宫的思路不一样,首先她认为所有的通道都应该是双向......
  • HDU 2242 考研路茫茫——空调教室
    ProblemDescription众所周知,HDU的考研教室是没有空调的,于是就苦了不少不去图书馆的考研仔们。Lele也是其中一个。而某教室旁边又摆着两个未装上的空调,更是引起人们无......
  • HDU 4041 Eliminate Witches!
    ProblemDescriptionKanameMadokaisaMagicalGirl(MahouShoujo/PuellaMagi).ThedutyofaMagicalGirlistoeliminateWitches(Majo).Thoughsoundshorrif......