結果

問題 No.2933 Range ROT Query
ユーザー loop0919loop0919
提出日時 2024-09-06 09:46:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,508 ms / 3,000 ms
コード長 9,138 bytes
コンパイル時間 860 ms
コンパイル使用メモリ 82,292 KB
実行使用メモリ 104,116 KB
最終ジャッジ日時 2024-10-02 00:26:50
合計ジャッジ時間 54,100 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
55,720 KB
testcase_01 AC 49 ms
54,836 KB
testcase_02 AC 46 ms
55,572 KB
testcase_03 AC 46 ms
55,196 KB
testcase_04 AC 50 ms
57,136 KB
testcase_05 AC 47 ms
56,256 KB
testcase_06 AC 55 ms
64,256 KB
testcase_07 AC 50 ms
57,752 KB
testcase_08 AC 46 ms
56,336 KB
testcase_09 AC 46 ms
55,880 KB
testcase_10 AC 56 ms
65,208 KB
testcase_11 AC 46 ms
56,208 KB
testcase_12 AC 1,194 ms
103,856 KB
testcase_13 AC 1,212 ms
103,788 KB
testcase_14 AC 1,187 ms
104,084 KB
testcase_15 AC 1,149 ms
103,460 KB
testcase_16 AC 1,163 ms
103,756 KB
testcase_17 AC 1,375 ms
103,852 KB
testcase_18 AC 1,368 ms
104,080 KB
testcase_19 AC 1,321 ms
104,068 KB
testcase_20 AC 1,246 ms
103,464 KB
testcase_21 AC 798 ms
103,660 KB
testcase_22 AC 819 ms
103,788 KB
testcase_23 AC 812 ms
103,724 KB
testcase_24 AC 800 ms
103,876 KB
testcase_25 AC 832 ms
103,940 KB
testcase_26 AC 1,347 ms
103,652 KB
testcase_27 AC 1,322 ms
103,412 KB
testcase_28 AC 1,317 ms
103,708 KB
testcase_29 AC 1,351 ms
104,116 KB
testcase_30 AC 1,322 ms
103,984 KB
testcase_31 AC 1,304 ms
103,636 KB
testcase_32 AC 1,296 ms
100,772 KB
testcase_33 AC 1,377 ms
93,936 KB
testcase_34 AC 1,461 ms
93,352 KB
testcase_35 AC 1,108 ms
93,024 KB
testcase_36 AC 1,508 ms
93,612 KB
testcase_37 AC 1,110 ms
92,632 KB
testcase_38 AC 1,115 ms
99,208 KB
testcase_39 AC 1,350 ms
93,188 KB
testcase_40 AC 1,321 ms
94,292 KB
testcase_41 AC 1,335 ms
100,532 KB
testcase_42 AC 1,146 ms
90,428 KB
testcase_43 AC 1,174 ms
90,004 KB
testcase_44 AC 1,404 ms
92,640 KB
testcase_45 AC 1,335 ms
100,628 KB
testcase_46 AC 1,446 ms
92,916 KB
testcase_47 AC 1,285 ms
91,892 KB
testcase_48 AC 1,080 ms
100,608 KB
testcase_49 AC 1,256 ms
100,476 KB
testcase_50 AC 1,103 ms
93,048 KB
testcase_51 AC 1,412 ms
98,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

sigma = 26


class lazy_segtree:
    def update(self, k):
        self.d[k] = self.op(self.d[2 * k], self.d[2 * k + 1])

    def all_apply(self, k, f):
        self.d[k] = self.mapping(f, self.d[k])
        if k < self.size:
            self.lz[k] = self.composition(f, self.lz[k])

    def push(self, k):
        self.all_apply(2 * k, self.lz[k])
        self.all_apply(2 * k + 1, self.lz[k])
        self.lz[k] = self.identity

    def __init__(self, V, OP, E, MAPPING, COMPOSITION, ID):
        self.n = len(V)
        self.log = (self.n - 1).bit_length()
        self.size = 1 << self.log
        self.d = [E for i in range(2 * self.size)]
        self.lz = [ID for i in range(self.size)]
        self.e = E
        self.op = OP
        self.mapping = MAPPING
        self.composition = COMPOSITION
        self.identity = ID
        for i in range(self.n):
            self.d[self.size + i] = V[i]
        for i in range(self.size - 1, 0, -1):
            self.update(i)

    def set(self, p, x):
        assert 0 <= p and p < self.n
        p += self.size
        for i in range(self.log, 0, -1):
            self.push(p >> i)
        self.d[p] = x
        for i in range(1, self.log + 1):
            self.update(p >> i)

    def get(self, p):
        assert 0 <= p and p < self.n
        p += self.size
        for i in range(self.log, 0, -1):
            self.push(p >> i)
        return self.d[p]

    def prod(self, l, r):
        assert 0 <= l and l <= r and r <= self.n
        if l == r:
            return self.e
        l += self.size
        r += self.size
        for i in range(self.log, 0, -1):
            if ((l >> i) << i) != l:
                self.push(l >> i)
            if ((r >> i) << i) != r:
                self.push(r >> i)
        sml, smr = self.e, self.e
        while l < r:
            if l & 1:
                sml = self.op(sml, self.d[l])
                l += 1
            if r & 1:
                r -= 1
                smr = self.op(self.d[r], smr)
            l >>= 1
            r >>= 1
        return self.op(sml, smr)

    def all_prod(self):
        return self.d[1]

    def apply_point(self, p, f):
        assert 0 <= p and p < self.n
        p += self.size
        for i in range(self.log, 0, -1):
            self.push(p >> i)
        self.d[p] = self.mapping(f, self.d[p])
        for i in range(1, self.log + 1):
            self.update(p >> i)

    def apply(self, l, r, f):
        assert 0 <= l and l <= r and r <= self.n
        if l == r:
            return
        l += self.size
        r += self.size
        for i in range(self.log, 0, -1):
            if ((l >> i) << i) != l:
                self.push(l >> i)
            if ((r >> i) << i) != r:
                self.push((r - 1) >> i)
        l2, r2 = l, r
        while l < r:
            if l & 1:
                self.all_apply(l, f)
                l += 1
            if r & 1:
                r -= 1
                self.all_apply(r, f)
            l >>= 1
            r >>= 1
        l, r = l2, r2
        for i in range(1, self.log + 1):
            if ((l >> i) << i) != l:
                self.update(l >> i)
            if ((r >> i) << i) != r:
                self.update((r - 1) >> i)

    def max_right(self, l, g):
        assert 0 <= l and l <= self.n
        assert g(self.e)
        if l == self.n:
            return self.n
        l += self.size
        for i in range(self.log, 0, -1):
            self.push(l >> i)
        sm = self.e
        while 1:
            while l % 2 == 0:
                l >>= 1
            if not (g(self.op(sm, self.d[l]))):
                while l < self.size:
                    self.push(l)
                    l = 2 * l
                    if g(self.op(sm, self.d[l])):
                        sm = self.op(sm, self.d[l])
                        l += 1
                return l - self.size
            sm = self.op(sm, self.d[l])
            l += 1
            if (l & -l) == l:
                break
        return self.n

    def min_left(self, r, g):
        assert 0 <= r and r <= self.n
        assert g(self.e)
        if r == 0:
            return 0
        r += self.size
        for i in range(self.log, 0, -1):
            self.push((r - 1) >> i)
        sm = self.e
        while 1:
            r -= 1
            while r > 1 and (r % 2):
                r >>= 1
            if not (g(self.op(self.d[r], sm))):
                while r < self.size:
                    self.push(r)
                    r = 2 * r + 1
                    if g(self.op(self.d[r], sm)):
                        sm = self.op(self.d[r], sm)
                        r -= 1
                return r + 1 - self.size
            sm = self.op(self.d[r], sm)
            if (r & -r) == r:
                break
        return 0


class segtree:
    n = 1
    size = 1
    log = 2
    d = [0]
    op = None
    e = 10**15

    def __init__(self, V, OP, E):
        self.n = len(V)
        self.op = OP
        self.e = E
        self.log = (self.n - 1).bit_length()
        self.size = 1 << self.log
        self.d = [E for i in range(2 * self.size)]
        for i in range(self.n):
            self.d[self.size + i] = V[i]
        for i in range(self.size - 1, 0, -1):
            self.update(i)

    def set(self, p, x):
        assert 0 <= p and p < self.n
        p += self.size
        self.d[p] = x
        for i in range(1, self.log + 1):
            self.update(p >> i)

    def get(self, p):
        assert 0 <= p and p < self.n
        return self.d[p + self.size]

    def prod(self, l, r):
        assert 0 <= l and l <= r and r <= self.n
        sml = self.e
        smr = self.e
        l += self.size
        r += self.size
        while l < r:
            if l & 1:
                sml = self.op(sml, self.d[l])
                l += 1
            if r & 1:
                smr = self.op(self.d[r - 1], smr)
                r -= 1
            l >>= 1
            r >>= 1
        return self.op(sml, smr)

    def all_prod(self):
        return self.d[1]

    def max_right(self, l, f):
        assert 0 <= l and l <= self.n
        assert f(self.e)
        if l == self.n:
            return self.n
        l += self.size
        sm = self.e
        while 1:
            while l % 2 == 0:
                l >>= 1
            if not (f(self.op(sm, self.d[l]))):
                while l < self.size:
                    l = 2 * l
                    if f(self.op(sm, self.d[l])):
                        sm = self.op(sm, self.d[l])
                        l += 1
                return l - self.size
            sm = self.op(sm, self.d[l])
            l += 1
            if (l & -l) == l:
                break
        return self.n

    def min_left(self, r, f):
        assert 0 <= r and r <= self.n
        assert f(self.e)
        if r == 0:
            return 0
        r += self.size
        sm = self.e
        while 1:
            r -= 1
            while r > 1 and (r % 2):
                r >>= 1
            if not (f(self.op(self.d[r], sm))):
                while r < self.size:
                    r = 2 * r + 1
                    if f(self.op(self.d[r], sm)):
                        sm = self.op(self.d[r], sm)
                        r -= 1
                return r + 1 - self.size
            sm = self.op(self.d[r], sm)
            if (r & -r) == r:
                break
        return 0

    def update(self, k):
        self.d[k] = self.op(self.d[2 * k], self.d[2 * k + 1])

    def __str__(self):
        return str([self.get(i) for i in range(self.n)])


def op(x, y):
    return x & y


e = (1 << sigma) - 1


def mapping(f, x):
    return ((x << f) & e) | (x >> (sigma - f))


def composition(f, g):
    return (f + g) % sigma


id_ = 0


S = input()
T = input()

diff = []

for s, t in zip(S, T):
    diff.append(1 << ((ord(s) - ord(t)) % sigma))

seg = lazy_segtree(diff, op, e, mapping, composition, id_)

s_imos = segtree([0] * (len(S) + 1), lambda x, y: (x + y) % sigma, 0)
t_imos = segtree([0] * (len(T) + 1), lambda x, y: (x + y) % sigma, 0)

Q = int(input())

for _ in range(Q):
    cmd, *query = list(map(int, input().split()))

    if cmd == 1:
        l, r, x = query
        seg.apply(min(l - 1, len(S), len(T)), min(r, len(S), len(T)), x)
        s_imos.set(l - 1, s_imos.get(l - 1) + x)
        s_imos.set(r, s_imos.get(r) - x)

    elif cmd == 2:
        l, r, x = query
        seg.apply(min(l - 1, len(S), len(T)), min(r, len(S), len(T)), -x % sigma)
        t_imos.set(l - 1, t_imos.get(l - 1) + x)
        t_imos.set(r, t_imos.get(r) - x)

    else:
        p = query[0]

        idx = seg.max_right(p - 1, lambda x: x & 1 == 1)

        if idx < min(len(S), len(T)):
            s = (s_imos.prod(0, idx + 1) + ord(S[idx]) - ord("a")) % sigma
            t = (t_imos.prod(0, idx + 1) + ord(T[idx]) - ord("a")) % sigma
            if s > t:
                print("Greater")
            elif s < t:
                print("Lesser")
        else:
            if len(S) > len(T):
                print("Greater")
            elif len(S) < len(T):
                print("Lesser")
            else:
                print("Equals")
0