結果

問題 No.1921 Range LthKth Query
ユーザー souta-1326souta-1326
提出日時 2022-05-06 23:22:28
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 252 ms / 4,000 ms
コード長 960 bytes
コンパイル時間 2,204 ms
コンパイル使用メモリ 199,376 KB
実行使用メモリ 95,260 KB
最終ジャッジ日時 2023-09-20 06:12:46
合計ジャッジ時間 9,513 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,444 KB
testcase_01 AC 2 ms
5,340 KB
testcase_02 AC 2 ms
5,504 KB
testcase_03 AC 2 ms
5,440 KB
testcase_04 AC 2 ms
5,448 KB
testcase_05 AC 2 ms
5,540 KB
testcase_06 AC 2 ms
5,440 KB
testcase_07 AC 2 ms
5,420 KB
testcase_08 AC 3 ms
7,564 KB
testcase_09 AC 3 ms
5,968 KB
testcase_10 AC 4 ms
10,152 KB
testcase_11 AC 14 ms
15,604 KB
testcase_12 AC 14 ms
23,408 KB
testcase_13 AC 153 ms
69,708 KB
testcase_14 AC 132 ms
83,880 KB
testcase_15 AC 252 ms
94,228 KB
testcase_16 AC 208 ms
71,616 KB
testcase_17 AC 228 ms
77,988 KB
testcase_18 AC 138 ms
95,260 KB
testcase_19 AC 149 ms
95,104 KB
testcase_20 AC 122 ms
94,928 KB
testcase_21 AC 102 ms
47,184 KB
testcase_22 AC 134 ms
95,148 KB
evil_01.txt AC 525 ms
165,856 KB
evil_02.txt AC 528 ms
170,676 KB
evil_03.txt AC 311 ms
198,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
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)/2;
      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