#include #include #include #include using namespace std; #include #include template struct rangefreq{ int n; vector >dat; rangefreq(const vector&v={}) { n=1; while(n=0;i--) { dat[i].resize(dat[i*2+1].size()+dat[i*2+2].size()); merge(dat[i*2+1].begin(),dat[i*2+1].end(), dat[i*2+2].begin(),dat[i*2+2].end(), dat[i].begin() ); } } int query(int a,int b,T x,int k=0,int l=0,int r=-1)const//[a,b) count(*>T; vector >B; setS; for(;T--;) { cin>>N; for(int i=0;i>A[i]; B.resize(N); for(int i=0;i>B[i].first; B[i].second=i; } sort(B.begin(),B.end()); rangefreqP(vector(A,A+N)); S.clear(); S.insert(-1); S.insert(N); bool out=false; for(int i=0;ib)out=true; j++; } if(P.query(L,R,b+1)>P.query(L,R,b)) { for(int k=i;k