結果

問題 No.1921 Range LthKth Query
ユーザー souta-1326souta-1326
提出日時 2022-05-06 22:37:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 616 ms / 4,000 ms
コード長 1,064 bytes
コンパイル時間 2,102 ms
コンパイル使用メモリ 200,356 KB
実行使用メモリ 103,404 KB
最終ジャッジ日時 2023-09-20 03:40:32
合計ジャッジ時間 10,489 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,484 KB
testcase_01 AC 2 ms
5,408 KB
testcase_02 AC 2 ms
5,608 KB
testcase_03 AC 2 ms
5,496 KB
testcase_04 AC 2 ms
5,452 KB
testcase_05 AC 2 ms
5,456 KB
testcase_06 AC 2 ms
5,440 KB
testcase_07 AC 2 ms
5,564 KB
testcase_08 AC 2 ms
7,672 KB
testcase_09 AC 3 ms
9,960 KB
testcase_10 AC 4 ms
12,028 KB
testcase_11 AC 26 ms
22,680 KB
testcase_12 AC 14 ms
38,940 KB
testcase_13 AC 358 ms
101,840 KB
testcase_14 AC 174 ms
101,348 KB
testcase_15 AC 616 ms
101,084 KB
testcase_16 AC 410 ms
103,180 KB
testcase_17 AC 571 ms
103,156 KB
testcase_18 AC 297 ms
103,100 KB
testcase_19 AC 337 ms
103,188 KB
testcase_20 AC 146 ms
103,404 KB
testcase_21 AC 152 ms
103,192 KB
testcase_22 AC 280 ms
103,100 KB
evil_01.txt AC 1,117 ms
198,756 KB
evil_02.txt AC 1,089 ms
198,704 KB
evil_03.txt AC 466 ms
198,860 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 cnt[MAX_N][MAX_N];
int cnt_rp[MAX_N][MAX_N];
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 = -1;
    for(int j=0;j<N;j++){
      rp[j+1] = rp[j]+(A[j]<=i);
      while(k < N && rp[j+1]-rp[k+1] >= K) k++;
      cnt[i][j] = k+1;
    }
    cnt_rp[i][0] = cnt[i][0];
    for(int j=1;j<N;j++) cnt_rp[i][j] = cnt_rp[i][j-1]+cnt[i][j];
  }
  int Q;cin >> Q;
  while(Q--){
    int l,r;cin >> l >> r;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 = upper_bound(cnt[mid]+l,cnt[mid]+r+1,l)-cnt[mid];
      if(cnt_rp[mid][r]-(cnt_itr == 0 ? 0:cnt_rp[mid][cnt_itr-1])-(r-cnt_itr+1)*l >= L) ans_rig = mid;
      else ans_lef = mid;
    }
    cout << ans_rig+1 << "\n";
  }
}
0