#include #include #include #include using namespace std; const int MAXN = 1e5; struct SegmentTree { int maxVal; int l, r; SegmentTree *L, *R; SegmentTree() : maxVal(0), L(nullptr), R(nullptr) {} SegmentTree(int l, int r) : SegmentTree() { this->l = l; this->r = r; } void recalc() { maxVal = max(L->maxVal, R->maxVal); } void build() { if(l==r) return; L = new SegmentTree(l, (l+r)/2); R = new SegmentTree((l+r)/2+1, r); L->build(); R->build(); recalc(); } void update(int q, int newVal) { if(l==r && l==q) { maxVal = max(maxVal, newVal); return; } if(rq) return; L->update(q, newVal); R->update(q, newVal); recalc(); } int query(int ql, int qr) { if(ql>qr) return 0; if(l>=ql && r<=qr) return maxVal; if(rqr) return -1; return max(L->query(ql, qr), R->query(ql, qr)); } }; int n; int a[MAXN+5]; void compress() { set s; for(int i = 0;i mp; int x = 0; for(int item: s) { mp[item] = x; x++; } for(int i = 0;i> n; for(int i = 0;i> a[i]; compress(); SegmentTree *T0 = new SegmentTree(0, n-1);T0->build(); SegmentTree *T1 = new SegmentTree(0, n-1);T1->build(); T0->update(a[0], +1); for(int i = 1;iquery(0, a[i]-1) + 1; int val1 = T0->query(a[i], a[i]); if(val1!=0) val1++; T0->update(a[i], val0); T1->update(a[i], val1); } fout << T1->query(0, n-1) << '\n'; } int main() { ios::sync_with_stdio(false); fin.tie(nullptr); int T; fin >> T; while(T--) solveTestcase(); }