// ayy // ' lamo // SUBLIME HAX #include using namespace std; template ostream &operator<<(ostream &os,const pair &x) { return os<<"("< struct is_iterable { template static long check(...); template static char check(int, typename T::const_iterator = C().end()); enum { value = sizeof(check(0)) == sizeof(char), neg_value = sizeof(check(0)) != sizeof(char) }; }; template ostream &_out_str(ostream &os,const T &x) { return os<<'"'< ostream &_dbg2_5(ostream &,const T &); template using eit=typename enable_if::type; template inline ostream &_dbg3(ostream &os,eit::neg_value,const T> &x) { return os< inline ostream &_dbg3(ostream &os,eit::value,const T> &V) { os<<"{"; bool ff=0; for(const auto &E:V) _dbg2_5(ff?os<<",":os,E), ff=1; return os<<"}"; } template<> inline ostream &_dbg3(ostream &os,const string &x) { return _out_str(os,x); } template<> inline ostream &_dbg3(ostream &os,const char *const &x) { return _out_str(os,x); } template inline ostream &_dbg2_5(ostream &os,const T &x) { return _dbg3(os,x); } template ostream &_dbg2(ostream &os,vector::iterator nm,const T &x,Args&&... args); inline ostream &_dbg2(ostream &os,vector::iterator) { return os; } template inline ostream &_dbg2(ostream &os,vector::iterator nm,const char *x,Args&&... args) { return _dbg2(_dbg3(os<<" ",x),nm+1,args...); } template inline ostream &_dbg2(ostream &os,vector::iterator nm,const T &x,Args&&... args) { return _dbg2(_dbg3(os<<" "<<*nm<<"=",x),nm+1,args...); } vector split(string s) { vector Z; string z=""; s+=','; int dep=0; for(char c:s) { if(c==',' && !dep) Z.push_back(z),z=""; else z+=c; if(c=='(') ++dep; if(c==')') --dep; } return Z; } template inline ostream &_dbg1(int ln,const string &nm,Args&&... args) { auto nms=split(nm); return _dbg2(cerr<<"L"< // using namespace __gnu_pbds; typedef unsigned long long ull; typedef long long ll; typedef long double ld; //CARE typedef complex pt; const ld eps=(ld)1e-8; const ld tau=2*(ld)acosl(-1); const int inf=1e9+99; const ll linf=1e18+99; const int P=1e9+7; const int N=64<<10; int m,n; int t[N],s[N],d[N]; vector v[N]; int y[N]; struct dat { int zz,lz; void set(int x) { zz=x; lz=0; } void inc(int dx=1) { zz+=dx, lz+=dx; } void push(dat &L,dat &R) { if(!lz) return; L.inc(lz), R.inc(lz); lz=0; } void pull(dat &L,dat &R) { push(L,R); zz=max(L.zz,R.zz); } void clr() { zz=lz=0; } inline int Q() const { return zz; } } rmq[2][N+N]; #define lc (ii+ii) #define rc (ii+ii+1) void SET(int i,int x,int ii=1,int L=0,int R=m) { // if(ii==1) dbg("SET",i,x); if(L==R) { rmq[0][ii].set(x); rmq[1][ii].set(x); return; } int M=(L+R)>>1; if(i<=M) SET(i,x,lc,L,M); else SET(i,x,rc,M+1,R); rmq[0][ii].pull(rmq[0][lc],rmq[0][rc]); rmq[1][ii].pull(rmq[1][lc],rmq[1][rc]); } void INC(int l,int r,int tt,int ii=1,int L=0,int R=m) { // if(ii==1) dbg("INC",l,r,tt); if(rR) return; if(l<=L && R<=r) { // dbg("incing",tt,ii,L,R,l,r); rmq[tt][ii].inc(); return; } int M=(L+R)>>1; rmq[tt][ii].push(rmq[tt][lc],rmq[tt][rc]); INC(l,r,tt,lc,L,M); INC(l,r,tt,rc,M+1,R); rmq[tt][ii].pull(rmq[tt][lc],rmq[tt][rc]); } int Q(int l,int r,int ii=1,int L=0,int R=m) { // if(ii==1) dbg("Q",l,r); if(rR) return 0; if(l<=L && R<=r) return max(rmq[0][ii].Q(),rmq[1][ii].Q()); rmq[0][ii].push(rmq[0][lc],rmq[0][rc]); rmq[1][ii].push(rmq[1][lc],rmq[1][rc]); int M=(L+R)>>1; return max(Q(l,r,lc,L,M),Q(l,r,rc,M+1,R)); } void _m() { for(int i=0;i(y,y+m+1)); int t=0; for(int i=1;i<=n;i++) { for(;t<=m && y[t]m?-1:t," \n"[i==n]); } } int32_t main() { int T; scanf("%d",&T); for(;T--;) _m(); }