# 长大校赛C(st表+二分)

#include<bits/stdc++.h>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define inf 1e9
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define eps 1e-8
#define succ(x) (1<<(x))
#define sqr(x) ((x)*(x))
#define mid (x+y>>1)
#define lowbit(x) (x&(-x))
#define NM 100005
#define MAXN 100005
using namespace std;
ll x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
return x*f;
}

int n,a[NM],tmp[NM],mn[NM];
ll m;
int dp[MAXN][32];int pos[MAXN][32],b[NM];
void st(){
mem(dp);mem(pos);mem(mn);
inc(i,2,n)mn[i]=mn[i/2]+1;
inc(i,0,n+1) dp[i][0]=a[i],pos[i][0]=i;
for(int j=1;succ(j)<=n;j++)
for(int i=1;i+succ(j)-1<=n;i++){
if(dp[i][j-1]>dp[i+(1<<(j-1))][j-1]) dp[i][j]=dp[i][j-1],pos[i][j]=pos[i][j-1];
else dp[i][j]=dp[i+(1<<(j-1))][j-1],pos[i][j]=pos[i+(1<<(j-1))][j-1];
}
}
int rmq(int l,int r){
int k=mn[r-l];
int t1=dp[l][k];int t2=dp[r-(1<<k)+1][k];
if(t1>=t2) return pos[l][k];
else return pos[r-(1<<k)+1][k];
}
int work(int x,int y,int i){
int s=n+1,k=x;
for(;x<=y;){
int t=x+y>>1;
if(a[rmq(k,t)]>=a[i]){
y=rmq(k,t)-1;s=rmq(k,t);
}else x=t+1;
}
return s;
}

int _work(int x,int y,int i){
int s=0,k=y;
for(;x<=y;){
int t=x+y>>1;
if(a[rmq(t,k)]>a[i]){
x=rmq(t,k)+1;s=rmq(t,k);
}else y=t-1;
}
return s;
}

bool cmp(int x,int y){
return a[x]>a[y];
}

int main(){
//freopen("data.in","r",stdin);
while(_--){
a[n+1]=inf;a[0]=inf;
st();mem(b);
inc(i,1,n){
int x,y,_x,_y;
x=_work(0,i-1,i);
y=work(i+1,1+n,i);
if(x>1)_x=_work(0,x-1,i);else _x=0;
if(y<n)_y=work(y+1,n+1,i);else _y=n+1;
//  printf("%d %d %d %d\n",_x,x,y,_y);
b[i]=(x-_x)+(_y-y)+(x>=1?(y-i-1)*(x-_x):0)+(y<=n?(i-x-1)*(_y-y):0);
}
//  inc(i,1,n)printf("%d ",b[i]);putchar('\n');
inc(i,1,n)tmp[i]=i;
sort(tmp+1,tmp+1+n,cmp);
inc(k,1,n){
int i=tmp[k];
if(m<=b[i]){
printf("%d\n",a[i]);break;
}
m-=b[i];
}
}
return 0;
}

64bit IO Format: %lld

## 题目描述

We deﬁne a value of an interval is the second largest number of it's elements, and of course an interval has at least two elements.
Given an array A with n elements and a number k, can you ﬁnd the value of the kth largest interval?

## 输入描述:

The ﬁrst line contains an integer number T, the number of test cases.
For each test case :
The ﬁrst line contains two integer numbers n,k(2 ≤ n ≤ 105,1 ≤ k ≤ n(n−1)/2), the number of test cases.
The second lines contains n integers Ai(1 ≤ Ai ≤ 109), the elements of array A.

## 输出描述:

For each test case print the value of the kth largest interval.

## 输入

2
3 3
1 2 3
5 1
1 2 2 3 3

## 输出

1
3

## 说明

For the sample input, there are three intervals.
Interval [1 2 3] has value 2.
Interval [2 3] has value 2.
Interval [1 2] has value 1.
So the 3rd largest interval is [1 2] whose value is 1.

64bit IO Format: %lld

## 题目描述

We deﬁne a value of an interval is the second largest number of it's elements, and of course an interval has at least two elements.
Given an array A with n elements and a number k, can you ﬁnd the value of the kth largest interval?

## 输入描述:

The ﬁrst line contains an integer number T, the number of test cases.
For each test case :
The ﬁrst line contains two integer numbers n,k(2 ≤ n ≤ 105,1 ≤ k ≤ n(n−1)/2), the number of test cases.
The second lines contains n integers Ai(1 ≤ Ai ≤ 109), the elements of array A.

## 输出描述:

For each test case print the value of the kth largest interval.

## 输入

2
3 3
1 2 3
5 1
1 2 2 3 3

## 输出

1
3

## 说明

For the sample input, there are three intervals.
Interval [1 2 3] has value 2.
Interval [2 3] has value 2.
Interval [1 2] has value 1.
So the 3rd largest interval is [1 2] whose value is 1.

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120