結果

問題 No.1921 Range LthKth Query
ユーザー souta-1326souta-1326
提出日時 2022-05-07 17:09:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 231 ms / 4,000 ms
コード長 939 bytes
コンパイル時間 739 ms
コンパイル使用メモリ 72,920 KB
実行使用メモリ 81,912 KB
最終ジャッジ日時 2023-09-21 03:50:22
合計ジャッジ時間 7,378 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,404 KB
testcase_01 AC 2 ms
5,388 KB
testcase_02 AC 2 ms
5,432 KB
testcase_03 AC 2 ms
5,596 KB
testcase_04 AC 2 ms
5,512 KB
testcase_05 AC 2 ms
5,444 KB
testcase_06 AC 2 ms
5,452 KB
testcase_07 AC 2 ms
5,672 KB
testcase_08 AC 2 ms
7,632 KB
testcase_09 AC 3 ms
5,972 KB
testcase_10 AC 4 ms
10,132 KB
testcase_11 AC 14 ms
14,132 KB
testcase_12 AC 13 ms
23,356 KB
testcase_13 AC 148 ms
57,616 KB
testcase_14 AC 129 ms
54,792 KB
testcase_15 AC 231 ms
79,484 KB
testcase_16 AC 181 ms
59,168 KB
testcase_17 AC 201 ms
49,844 KB
testcase_18 AC 136 ms
81,912 KB
testcase_19 AC 147 ms
81,288 KB
testcase_20 AC 122 ms
81,108 KB
testcase_21 AC 98 ms
46,020 KB
testcase_22 AC 135 ms
74,192 KB
evil_01.txt AC 545 ms
154,412 KB
evil_02.txt AC 483 ms
158,648 KB
evil_03.txt AC 308 ms
198,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
using namespace std;
constexpr int MAX_N = 5000;
int N,K,L,Q,l,r,mid,ans_lef,ans_rig,cnt_itr,i,j,k;
int A[MAX_N];
int compute_cnt_itr[MAX_N][MAX_N+1];
int cnt_rp[MAX_N][MAX_N+1];
int rp[MAX_N+1];
int main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cin >> N >> K >> L;
  for(i=0;i<N;i++){cin >> A[i];A[i]--;}
  for(i=0;i<N;i++){
    k = 0;
    for(j=0;j<N;j++){
      rp[j+1] = rp[j]+(A[j]<=i);
      while(rp[j+1]-rp[k] >= K) compute_cnt_itr[i][++k] = j+1;
      cnt_rp[i][j+1] = cnt_rp[i][j]+k;
    }
  }
  cin >> Q;
  while(Q--){
    cin >> l >> r;
    ans_lef = -1,ans_rig = N-1;
    while(ans_rig - ans_lef > 1){
      mid = (ans_lef+ans_rig)>>1;
      cnt_itr = clamp(compute_cnt_itr[mid][l],l,r+1)-1;
      (cnt_rp[mid][r]-cnt_rp[mid][cnt_itr]-(r-cnt_itr)*(l-1) >= L ? ans_rig:ans_lef) = mid;
    }
    cout << ans_rig+1 << "\n";
  }
}
0