結果

問題 No.1921 Range LthKth Query
ユーザー 👑 tatyamtatyam
提出日時 2022-05-01 20:43:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,651 ms / 4,000 ms
コード長 1,792 bytes
コンパイル時間 1,393 ms
コンパイル使用メモリ 86,476 KB
実行使用メモリ 371,520 KB
最終ジャッジ日時 2023-09-13 16:44:26
合計ジャッジ時間 23,377 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,220 KB
testcase_01 AC 73 ms
71,216 KB
testcase_02 AC 74 ms
71,232 KB
testcase_03 AC 73 ms
71,156 KB
testcase_04 AC 74 ms
71,032 KB
testcase_05 AC 74 ms
71,148 KB
testcase_06 AC 73 ms
71,112 KB
testcase_07 AC 75 ms
70,924 KB
testcase_08 AC 84 ms
75,760 KB
testcase_09 AC 103 ms
77,096 KB
testcase_10 AC 139 ms
78,404 KB
testcase_11 AC 211 ms
85,728 KB
testcase_12 AC 230 ms
102,876 KB
testcase_13 AC 713 ms
253,312 KB
testcase_14 AC 833 ms
303,136 KB
testcase_15 AC 1,651 ms
335,932 KB
testcase_16 AC 999 ms
259,128 KB
testcase_17 AC 1,086 ms
276,844 KB
testcase_18 AC 1,293 ms
370,264 KB
testcase_19 AC 1,245 ms
347,816 KB
testcase_20 AC 845 ms
362,004 KB
testcase_21 AC 467 ms
225,744 KB
testcase_22 AC 1,334 ms
371,520 KB
evil_01.txt MLE -
evil_02.txt MLE -
evil_03.txt MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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])
0