/***************************************************************** Author:lbn187, a konjac TwT Date:2015-7-17 Contest:Bestcoder Algorithm:QAQ ^_^ Orz hzh, NOI gold members, IOI 2016 world champion ^=^ Orz hhw, you are our blue moon, with you will live ^~^ Orz mxh, you are our red sun, without you we'll die ^-^ Orz yizhou, I wish you a successful marriage ^w^ Orz xianyangyu, you can sleep all the time in the game *****************************************************************/ #pragma comment(linker, "/STACK:1024000000,1024000000") #include #include #include #include #include #include #include #include #include #define fon(i,n) for(int i=0;i=0;i--) #define rep(i,a,n) for(int i=a;i<=n;i++) #define per(i,a,n) for(int i=n;i>=a;i--) #define mjj(i,x) for(int i=fir[x];i;i=ne[i]) #define X first #define Y second #define MAX(a,b) a=max(a,b) #define MIN(a,b) a=min(a,b) #define mp make_pair #define rlr son[son[root][1]][0] #define gi(a) scanf("%d",&a); #define gi2(a,b) scanf("%d%d",&a,&b); #define gi3(a,b,c) scanf("%d%d%d",&a,&b,&c); #define gl(a) scanf("%I64d",&a); #define gs(s) scanf("%s",s); #define pi(a) printf("%d\n",a); #define pi2(a,b) printf("%d %d\n",a,b); #define pl(a) printf("%I64d\n",a); #define spr(x) (x*x) #define pie acos(-1) #define CP(a,b) memcpy(a,b,sizeof(a)) #define CL(a) memset(a,0,sizeof(a)) #define N 222222 #define M 222222 #define inf 1e9 #define eps 1e-8 using namespace std; char ch;void read(int &x){for(ch=getchar();ch<'0';ch=getchar());for(x=0;ch>='0';ch=getchar())x=x*10+ch-'0';} const int xx[]={1,-1,0,0},yy[]={0,0,1,-1}; long long an; int T,n,m,k,x,y,i,j,t,L,tot,cnt,a[N],b[N],v[N],E[N*3],co[N*3];vectorV[N]; struct P{int l,r,x,z;}p[N*10];bool cmp(P a,P b){return a.x>1; if(x<=md)ins(k<<1,l,md,x,y,z);if(y>md)ins(k<<1|1,md+1,r,x,y,z); ps(k,l,r); } int main(){ for(scanf("%d",&T);T--;){ scanf("%d%d",&n,&k);an=0;t=0;CL(E);CL(co); for(i=1;i<=n;i++)V[i].clear(); for(i=1;i<=n;i++)scanf("%d",&a[i]),v[i]=a[i]; sort(v+1,v+n+1);cnt=unique(v+1,v+n+1)-v-1; for(i=1;i<=n;i++)a[i]=lower_bound(v+1,v+cnt+1,a[i])-v,V[a[i]].push_back(i); for(x=1;x<=cnt;x++){ for(L=V[x].size(),i=0;i