結果

問題 No.1471 Sort Queries
ユーザー 萩3萩3
提出日時 2021-05-02 18:09:24
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,330 bytes
コンパイル時間 1,123 ms
コンパイル使用メモリ 87,132 KB
実行使用メモリ 139,668 KB
最終ジャッジ日時 2023-09-28 08:45:31
合計ジャッジ時間 17,333 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,328 KB
testcase_01 AC 69 ms
71,216 KB
testcase_02 AC 69 ms
71,252 KB
testcase_03 AC 73 ms
71,612 KB
testcase_04 AC 72 ms
71,580 KB
testcase_05 AC 70 ms
71,532 KB
testcase_06 AC 71 ms
71,528 KB
testcase_07 AC 71 ms
71,320 KB
testcase_08 AC 72 ms
71,256 KB
testcase_09 AC 72 ms
71,340 KB
testcase_10 AC 70 ms
71,296 KB
testcase_11 AC 71 ms
71,424 KB
testcase_12 AC 71 ms
71,404 KB
testcase_13 AC 282 ms
80,180 KB
testcase_14 AC 258 ms
80,252 KB
testcase_15 AC 373 ms
81,024 KB
testcase_16 AC 213 ms
78,636 KB
testcase_17 AC 226 ms
79,260 KB
testcase_18 AC 183 ms
79,084 KB
testcase_19 AC 222 ms
78,720 KB
testcase_20 AC 371 ms
81,388 KB
testcase_21 AC 238 ms
79,436 KB
testcase_22 AC 214 ms
79,508 KB
testcase_23 AC 571 ms
84,188 KB
testcase_24 AC 590 ms
84,472 KB
testcase_25 AC 802 ms
85,812 KB
testcase_26 AC 530 ms
83,272 KB
testcase_27 AC 720 ms
87,244 KB
testcase_28 AC 734 ms
86,644 KB
testcase_29 AC 553 ms
83,240 KB
testcase_30 AC 551 ms
83,260 KB
testcase_31 AC 776 ms
84,744 KB
testcase_32 AC 716 ms
83,504 KB
testcase_33 TLE -
testcase_34 AC 1,047 ms
89,352 KB
testcase_35 AC 1,066 ms
89,372 KB
testcase_36 TLE -
testcase_37 TLE -
testcase_38 AC 1,783 ms
123,804 KB
testcase_39 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

def resolve():
    readline = sys.stdin.readline
    n,q = map(int,readline().split())
    cs = [[c] for c in readline().strip()]
    seg = SegTree(cs)
    for _ in range(q):
        l,r,x = map(int,readline().split())
        print(seg.fold(l-1,r)[x-1])

class SegTree:
    """
    reffered to 'maspy', noncommutative operation is available
    X_f = min, X_unit = INF
    X_f = max, X_unit = -INF
    X_f = sum, X_unit = 0
    X_f = lambda _,a,b: a+b, X_unit = ''
    """
    X_f = lambda _,a,b:sorted(a+b)

    def __init__(self, seq):
        l = list(seq)
        self.N = len(l)
        self.X = [[] for _ in range(self.N)] + l
        for i in range(self.N - 1, 0, -1):
            self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])

    def set_val(self, i, x):
        i += self.N
        self.X[i] = x
        while i > 1:
            i >>= 1
            self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])

    def fold(self, L, R):#[L,R)
        L += self.N
        R += self.N
        vL = []
        vR = []
        while L < R:
            if L & 1:
                vL = self.X_f(vL, self.X[L])
                L += 1
            if R & 1:
                R -= 1
                vR = self.X_f(self.X[R], vR)
            L >>= 1
            R >>= 1
        return self.X_f(vL, vR)


resolve()
0