結果

問題 No.1471 Sort Queries
ユーザー 小野寺健小野寺健
提出日時 2021-04-25 15:46:39
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,096 bytes
コンパイル時間 394 ms
コンパイル使用メモリ 11,044 KB
実行使用メモリ 13,396 KB
最終ジャッジ日時 2023-09-17 14:06:38
合計ジャッジ時間 26,495 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,284 KB
testcase_01 AC 16 ms
8,396 KB
testcase_02 AC 17 ms
8,368 KB
testcase_03 AC 18 ms
8,376 KB
testcase_04 AC 19 ms
8,436 KB
testcase_05 AC 18 ms
8,472 KB
testcase_06 AC 17 ms
8,308 KB
testcase_07 AC 17 ms
8,284 KB
testcase_08 AC 19 ms
8,372 KB
testcase_09 AC 18 ms
8,316 KB
testcase_10 AC 17 ms
8,264 KB
testcase_11 AC 17 ms
8,376 KB
testcase_12 AC 19 ms
8,324 KB
testcase_13 AC 370 ms
10,588 KB
testcase_14 AC 347 ms
9,760 KB
testcase_15 AC 590 ms
10,572 KB
testcase_16 AC 265 ms
9,108 KB
testcase_17 AC 268 ms
10,256 KB
testcase_18 AC 188 ms
9,556 KB
testcase_19 AC 299 ms
9,180 KB
testcase_20 AC 618 ms
10,688 KB
testcase_21 AC 309 ms
9,684 KB
testcase_22 AC 252 ms
9,704 KB
testcase_23 AC 893 ms
11,476 KB
testcase_24 AC 853 ms
11,288 KB
testcase_25 AC 1,348 ms
12,852 KB
testcase_26 AC 973 ms
11,088 KB
testcase_27 AC 1,116 ms
12,876 KB
testcase_28 AC 1,115 ms
12,864 KB
testcase_29 AC 919 ms
11,196 KB
testcase_30 AC 867 ms
11,248 KB
testcase_31 AC 1,411 ms
11,588 KB
testcase_32 AC 1,454 ms
11,452 KB
testcase_33 TLE -
testcase_34 AC 1,775 ms
13,284 KB
testcase_35 AC 1,765 ms
13,360 KB
testcase_36 AC 219 ms
13,024 KB
testcase_37 AC 227 ms
13,084 KB
testcase_38 AC 1,840 ms
13,260 KB
testcase_39 AC 1,998 ms
13,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect

N, Q = map(int, input().split())

A = list(input())

I = []
J = []
K = []

for _ in range(Q):
    l, r, x = map(int, input().split())
    I.append(l)
    J.append(r)
    K.append(x)
    
n = 1
while n < N:
    n *= 2
    
dat = [[] for _ in range(n*2)]
    
def init(k, l, r):
    if r - l == 1:
        dat[k].append(A[l])
    else:
        lch = k * 2 + 1
        rch = k * 2 + 2
        init(lch, l, (l+r)//2)
        init(rch, (l+r)//2, r)
        dat[k] = sorted(dat[lch] + dat[rch])

def query(i, j, x, k, l, r):
    if j <= l or r <= i:
        return 0
    elif i <= l and r <= j:
        return bisect.bisect_right(dat[k], x)
    else:
        lc = query(i, j, x, k * 2 + 1, l, (l+r)//2)
        rc = query(i, j, x, k * 2 + 2, (l+r)//2, r)
        return lc + rc
    
nums = sorted(A)

init(0, 0, N)

for i in range(Q):
    l = I[i] - 1
    r = J[i]
    k = K[i]
    lb, ub = -1, N - 1
    while ub - lb > 1:
        md = (ub + lb) // 2
        c = query(l, r, nums[md], 0, 0, N)
        if c >= k:
            ub = md
        else:
            lb = md
    print(nums[ub])
0