結果
問題 | No.1921 Range LthKth Query |
ユーザー | tatyam |
提出日時 | 2022-05-01 20:43:24 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,705 ms / 4,000 ms |
コード長 | 1,792 bytes |
コンパイル時間 | 165 ms |
コンパイル使用メモリ | 82,136 KB |
実行使用メモリ | 370,952 KB |
最終ジャッジ日時 | 2024-07-01 01:19:52 |
合計ジャッジ時間 | 22,112 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
53,824 KB |
testcase_01 | AC | 40 ms
52,880 KB |
testcase_02 | AC | 42 ms
53,688 KB |
testcase_03 | AC | 39 ms
52,952 KB |
testcase_04 | AC | 40 ms
52,704 KB |
testcase_05 | AC | 41 ms
52,952 KB |
testcase_06 | AC | 41 ms
53,556 KB |
testcase_07 | AC | 42 ms
54,488 KB |
testcase_08 | AC | 50 ms
60,904 KB |
testcase_09 | AC | 73 ms
72,184 KB |
testcase_10 | AC | 111 ms
77,820 KB |
testcase_11 | AC | 185 ms
84,140 KB |
testcase_12 | AC | 199 ms
101,948 KB |
testcase_13 | AC | 717 ms
251,288 KB |
testcase_14 | AC | 861 ms
301,904 KB |
testcase_15 | AC | 1,705 ms
335,976 KB |
testcase_16 | AC | 1,046 ms
258,108 KB |
testcase_17 | AC | 1,112 ms
275,184 KB |
testcase_18 | AC | 1,325 ms
369,168 KB |
testcase_19 | AC | 1,227 ms
346,716 KB |
testcase_20 | AC | 855 ms
362,608 KB |
testcase_21 | AC | 450 ms
224,468 KB |
testcase_22 | AC | 1,367 ms
370,952 KB |
evil_01.txt | MLE | - |
evil_02.txt | MLE | - |
evil_03.txt | MLE | - |
ソースコード
import sys import bisect input = sys.stdin.readline N, K, L = map(int, input().split()) A = list(map(int, input().split())) # Kth[i][j] = Kth(A[i:j+1]) Kth = [[0] * N for i in range(N)] idx = [-1, N] for id in sorted(range(N), key=lambda id: A[id]): x = A[id] i = bisect.bisect(idx, id) idx.insert(i, id) r = max(K + 1, i + 1) l = r - (K + 1) while r < len(idx) and l < i: for j in range(idx[l + 1], idx[l], -1): for k in range(idx[r - 1], idx[r]): Kth[j][k] = x l += 1 r += 1 # B[i][j] = Kth[i][j] <= t B = [[0] * N for i in range(N)] # Kth[i][j] = t forall i, j in seg_K[t] seg_K = [[] for i in range(N + 1)] for i in range(N): for j in range(i + K - 1, N): seg_K[Kth[i][j]].append((i, j)) row_sum = [0] * N row_r = [N] * N col_sum = [0] * N col_l = [0] * N Lth = [[1] * N for i in range(N)] for t in range(1, N + 1): for i, j in seg_K[t]: B[i][j] = 1 if j < row_r[i]: row_sum[i] += 1 if i >= col_l[j]: col_sum[j] += 1 i = 0 cnt = 0 for j in range(N): if col_l[j] < i: col_sum[j] -= sum(B[i2][j] for i2 in range(col_l[j], i)) col_l[j] = i cnt += col_sum[j] while cnt >= L: row_sum[i] -= sum(B[i][j + 1 : row_r[i]]) row_r[i] = j + 1 cnt -= row_sum[i] i += 1 if i < N: Lth[i][j] = t + 1 for i in range(N): for j in range(N - 1, -1, -1): if i + 1 < N and Lth[i + 1][j] < Lth[i][j]: Lth[i + 1][j] = Lth[i][j] if j and Lth[i][j - 1] < Lth[i][j]: Lth[i][j - 1] = Lth[i][j] Q = int(input()) for i in range(Q): l, r = map(int, input().split()) print(Lth[l - 1][r - 1])