結果

問題 No.1921 Range LthKth Query
ユーザー souta-1326souta-1326
提出日時 2022-05-06 23:00:43
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 386 ms / 4,000 ms
コード長 989 bytes
コンパイル時間 3,068 ms
コンパイル使用メモリ 245,884 KB
実行使用メモリ 89,564 KB
最終ジャッジ日時 2023-09-20 05:06:11
合計ジャッジ時間 9,470 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,324 KB
testcase_01 AC 2 ms
5,400 KB
testcase_02 AC 2 ms
5,652 KB
testcase_03 AC 2 ms
5,316 KB
testcase_04 AC 2 ms
5,416 KB
testcase_05 AC 2 ms
5,356 KB
testcase_06 AC 2 ms
5,448 KB
testcase_07 AC 2 ms
5,444 KB
testcase_08 AC 2 ms
7,652 KB
testcase_09 AC 3 ms
5,832 KB
testcase_10 AC 4 ms
10,164 KB
testcase_11 AC 15 ms
15,772 KB
testcase_12 AC 15 ms
23,328 KB
testcase_13 AC 194 ms
69,740 KB
testcase_14 AC 161 ms
80,144 KB
testcase_15 AC 386 ms
88,204 KB
testcase_16 AC 296 ms
71,648 KB
testcase_17 AC 332 ms
76,392 KB
testcase_18 AC 191 ms
89,564 KB
testcase_19 AC 205 ms
89,516 KB
testcase_20 AC 159 ms
89,548 KB
testcase_21 AC 129 ms
47,184 KB
testcase_22 AC 184 ms
89,564 KB
evil_01.txt AC 715 ms
162,688 KB
evil_02.txt AC 746 ms
166,216 KB
evil_03.txt AC 403 ms
198,720 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 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);
  int N,K,L;cin >> N >> K >> L;
  for(int i=0;i<N;i++){cin >> A[i];A[i]--;}
  for(int i=0;i<N;i++){
    int k = 0;
    for(int j=0;j<N;j++){
      rp[j+1] = rp[j]+(A[j]<=i);
      while(k < N && rp[j+1]-rp[k] >= K){
        compute_cnt_itr[i][++k] = j+1;
      }
      cnt_rp[i][j+1] = cnt_rp[i][j]+k;
    }
  }
  int Q;cin >> Q;
  while(Q--){
    int l,r;cin >> l >> r;
    int ans_lef = -1,ans_rig = N-1;
    while(ans_rig - ans_lef > 1){
      int mid = (ans_lef+ans_rig)/2;
      int cnt_itr = clamp(compute_cnt_itr[mid][l],l,r+1);
      (cnt_rp[mid][r]-cnt_rp[mid][cnt_itr-1]-(r-cnt_itr+1)*(l-1) >= L ? ans_rig:ans_lef) = mid;
    }
    cout << ans_rig+1 << "\n";
  }
}
0