传送门
文章目录
- 题意:
- 思路:
题意:
思路:
日常水一篇题解。
带修改的求区间连续的递增序列,我们考虑用线段树维护。
直接维护mlenmlenmlen是区间最长的递增序列,lslsls是从左端点开始的最长递增序列,rsrsrs是从右端点开始的最长递增序列,pushuppushuppushup的时候当且仅当左区间最右端的值小于右区间最左端的值的时候,两端可以接起来,根据这个条件直接转移就好啦。
我维护的信息有点多,其实本不需要维护最左和最右的值的。
// Problem: LCIS
// Contest: HDOJ
// URL: http://acm.hdu.edu.cn/showproblem.php?pid=3308
// Memory Limit: 65 MB
// Time Limit: 6000 ms
//
// Powered by CP Editor (https://cpeditor.org)//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid ((tr[u].l+tr[u].r)>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;const int N=100010,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6;int n,m;
struct Node {int l,r;int val;int mlen,ls,rs,lval,rval;
}tr[N<<2];void pushup(int u) {tr[u].lval=tr[L].lval;tr[u].rval=tr[R].rval;tr[u].mlen=max(tr[L].mlen,tr[R].mlen);if(tr[L].ls==Len(L)) {if(tr[L].rval<tr[R].lval) tr[u].ls=Len(L)+tr[R].ls;else tr[u].ls=Len(L);} else tr[u].ls=tr[L].ls;if(tr[R].rs==Len(R)) {if(tr[R].lval>tr[L].rval) tr[u].rs=Len(R)+tr[L].rs;else tr[u].rs=Len(R);} else tr[u].rs=tr[R].rs;//tr[u].mlen=max(tr[u].mlen,max(tr[u].ls,tr[u].rs));if(tr[L].rval<tr[R].lval) tr[u].mlen=max(tr[u].mlen,tr[L].rs+tr[R].ls);
}void build(int u,int l,int r) {tr[u]={l,r};if(l==r) {scanf("%d",&tr[u].val);tr[u].lval=tr[u].rval=tr[u].val;tr[u].mlen=tr[u].ls=tr[u].rs=1;return;}build(L,l,Mid); build(R,Mid+1,r);pushup(u);
}void change(int u,int pos,int val) {if(tr[u].l==pos&&tr[u].r==pos) {tr[u].val=val;tr[u].lval=tr[u].rval=tr[u].val;return;}if(pos<=Mid) change(L,pos,val);else change(R,pos,val);pushup(u);
}Node query(int u,int l,int r) {if(tr[u].l>=l&&tr[u].r<=r) return tr[u];if(r<=Mid) return query(L,l,r);else if(l>Mid) return query(R,l,r);else {Node a=query(L,l,r),b=query(R,l,r);Node ans;ans.lval=a.lval;ans.rval=b.rval;ans.mlen=max(a.mlen,b.mlen);if(a.ls==a.r-a.l+1) {if(a.rval<b.lval) ans.ls=a.r-a.l+1+b.ls;else ans.ls=a.r-a.l+1;} else ans.ls=a.ls;if(b.rs==b.r-b.l+1) {if(b.lval>a.rval) ans.rs=b.r-b.l+1+a.rs;else ans.rs=b.r-b.l+1;} else ans.rs=b.rs;//ans.mlen=max(ans.mlen,max(ans.ls,ans.rs));if(a.rval<b.lval) ans.mlen=max(ans.mlen,a.rs+b.ls);return ans;}
}int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0); int _; scanf("%d",&_);while(_--) {scanf("%d%d",&n,&m);build(1,1,n);while(m--) {char op[2]; int l,r; scanf("%s%d%d",op,&l,&r);if(op[0]=='U') l++,change(1,l,r);else l++,r++,printf("%d\n",query(1,l,r).mlen);}}return 0;
}
/**/