#include using namespace std; typedef signed long long ll; #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define FORR2(x,y,arr) for(auto& [x,y]:arr) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) template bool chmax(T &a, const T &b) { if(a bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;} //------------------------------------------------------- int T; int N,H[202020]; const int def=-1<<20; template class SegTree_ma { public: vector val; V comp(V l,V r){ return max(l,r);}; SegTree_ma(){val=vector(NV*2,def);}; V getval(int x,int y,int l=0,int r=NV,int k=1) { // x<=i1) entry>>=1, val[entry]=comp(val[entry*2],val[entry*2+1]); } }; SegTree_ma st[4]; void solve() { int i,j,k,l,r,x,y; string s; cin>>T; while(T--) { vector Hs={0,1<<30}; cin>>N; FOR(i,N) { cin>>H[i]; Hs.push_back(H[i]); } sort(ALL(Hs)); FOR(i,N) H[i]=lower_bound(ALL(Hs),H[i])-Hs.begin(); FOR(i,4) FOR(j,N+2) st[i].update(j,-1<<20,1); st[0].update(N+1,0); st[0].update(H[0],1); for(i=1;i3 x=st[3].getval(0,H[i]+1); y=st[3].getval(0,N+2); st[3].update(H[i],x+1); st[3].update(N+1,y); // 2->2 // 2->3 x=st[2].getval(H[i],N+2); y=st[2].getval(0,N+2); st[2].update(H[i],x+1); st[3].update(H[i],x+1); st[2].update(0,y); st[3].update(0,y); // 1->1 // 1->2 x=st[1].getval(0,H[i]+1); y=st[1].getval(0,N+2); st[1].update(H[i],x+1); st[2].update(H[i],x+1); st[1].update(N+1,y); st[2].update(N+1,y); // 0->0 // 0->1 x=st[0].getval(H[i],N+2); y=st[0].getval(0,N+2); st[0].update(H[i],x+1); st[1].update(H[i],x+1); st[0].update(0,y); st[1].update(0,y); } int ret=0; FOR(i,N+2) { x=st[3].getval(i,i+1); if(i<=H[N-1]) ret=max(ret,x+1); else ret=max(ret,x); } cout<