結果
| 問題 |
No.3188 K-th Lexmin
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-06-20 22:06:47 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 549 ms / 3,500 ms |
| コード長 | 1,120 bytes |
| コンパイル時間 | 2,250 ms |
| コンパイル使用メモリ | 103,396 KB |
| 実行使用メモリ | 20,272 KB |
| 最終ジャッジ日時 | 2025-06-20 22:07:13 |
| 合計ジャッジ時間 | 22,121 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 47 |
ソースコード
#include<iostream>
#include<vector>
#include<cassert>
#include<atcoder/string>
#include<atcoder/lazysegtree>
using namespace std;
using dat=pair<long,int>;
dat op(dat a,dat b){return make_pair(a.first+b.first,a.second+b.second);}
dat e(){return make_pair(0L,0);}
dat mp(int f,dat x)
{
if(f)x.first=x.second*(long)f;
return x;
}
int cmp(int f,int g){return f?f:g;}
int id(){return 0;}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;cin>>T;
for(;T--;)
{
int N;long long K;
cin>>N>>K;
vector<int>A(N);
for(int i=0;i<N;i++)cin>>A[i];
vector<int>sa=atcoder::suffix_array(A);
vector<int>lcp=atcoder::lcp_array(A,sa);
atcoder::lazy_segtree<dat,op,e,int,mp,cmp,id>seg(vector<dat>(N,make_pair(N,1)));
K=(long long)N*(N+1)/2-K;
for(int i=N;i--;)
{
int r=N-sa[i];
int l=seg.min_left(r,[&](dat x){
return x.first-(long long)i*x.second<=K;
});
int mn=i==0?0:lcp[i-1];
if(l<=mn)
{
dat x=seg.prod(mn,r);
K-=x.first-(long long)i*x.second;
seg.apply(mn,N,i);
continue;
}
for(int j=0;j<l;j++)cout<<A[sa[i]+j]<<(j+1==l?"\n":" ");
break;
}
}
}