标签:into 大于 script tle ESS cst algo ini preview
#include <cstdio> #include <algorithm> using namespace std; int n,k; long long m; int a[100005]; int b[100005]; long long judge(int x) { int ll=1,num=0; long long ans=0; for(int i = 1;i <= n;++i) { if(a[i]>=x) num++; if(num==k) { ans+=n-i+1; while(a[ll]<x)//双指针移动 { ans+=n-i+1; ll++; } num--; ll++; } } return ans; } int main() { int t; scanf("%d",&t); while(t--) { scanf("%d%d%lld",&n,&k,&m);//m会超过int for(int i = 1;i <= n;++i){ scanf("%d",&a[i]); b[i]=a[i]; } sort(b+1,b+1+n); int num=unique(b+1,b+1+n)-b-1; int l=1,r=num; while(l<=r) { int mid=l+r>>1; long long temp=judge(b[mid]); if(temp<m) r=mid-1; else if(temp>=m) l=mid+1; } printf("%d\n",b[r]); } return 0; }
标签:into 大于 script tle ESS cst algo ini preview
原文地址:https://www.cnblogs.com/aaddvvaanntteezz/p/11097612.html