結果

問題 No.2933 Range ROT Query
ユーザー amesyuamesyu
提出日時 2024-09-06 05:23:45
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 5,726 bytes
コンパイル時間 236 ms
コンパイル使用メモリ 82,364 KB
実行使用メモリ 356,724 KB
最終ジャッジ日時 2024-10-02 00:24:56
合計ジャッジ時間 9,355 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
65,536 KB
testcase_01 AC 48 ms
60,672 KB
testcase_02 AC 52 ms
62,336 KB
testcase_03 AC 53 ms
61,696 KB
testcase_04 AC 86 ms
76,288 KB
testcase_05 AC 71 ms
71,936 KB
testcase_06 AC 109 ms
76,800 KB
testcase_07 AC 72 ms
71,680 KB
testcase_08 AC 52 ms
60,928 KB
testcase_09 AC 51 ms
61,952 KB
testcase_10 AC 85 ms
75,904 KB
testcase_11 AC 60 ms
64,896 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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


sigma = 26

def op(x, y):
    arr = [0] * sigma
    for i in range(sigma):
        arr[i] += x[i]
        arr[i] += y[i]
    return arr

e = [0] * sigma

def mapping(f, x):
    arr = [0] * sigma
    for i in range(sigma):
        arr[(i+f)%sigma] = x[i]
    return arr

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

def f(x):
    return sum(x) == x[0]

ide = 0


S = input()
T = input()
N = min(len(S), len(T))
init = [e[::] for i in range(N)]

for i in range(N):
    init[i][(ord(S[i])-ord(T[i]))%26] = 1

seg = lazy_segtree(init, op, e, mapping, composition, ide)

checkS = lazy_segtree([0] * N, lambda x, y: 0, 0, lambda f, s : f + s, lambda f, g : f + g, 0)
checkT = lazy_segtree([0] * N, lambda x, y: 0, 0, lambda f, s : f + s, lambda f, g : f + g, 0)

for i in range(N):
    checkS.apply(i, i+1, ord(S[i])-ord('a'))
    checkT.apply(i, i+1, ord(T[i])-ord('a'))

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

    if query[0] == 1:
        l, r, x = query[1:]
        if N < l: continue
        seg.apply(l-1, min(r, N), x)
        checkS.apply(l-1, min(r, N), x)
    elif query[0] == 2:
        l, r, x = query[1:]
        if N < l: continue
        seg.apply(l-1, min(r, N), -x)
        checkT.apply(l-1, min(r, N), x)
    else:
        p = query[1]
        q = seg.max_right(p-1, f)

        if q == N:
            if len(S) == len(T): print("Equals")
            elif len(S) < len(T): print("Lesser")
            else: print("Greater")
        else:
            s, t = checkS.get(q), checkT.get(q)
            if s%26 < t%26: print("Lesser")
            elif s%26 > t%26: print("Greater")
            else: assert True
0