結果

問題 No.2308 [Cherry 5th Tune B] もしかして、真?
ユーザー navel_tosnavel_tos
提出日時 2023-05-20 01:57:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 426 ms / 2,000 ms
コード長 2,421 bytes
コンパイル時間 270 ms
コンパイル使用メモリ 87,124 KB
実行使用メモリ 145,980 KB
最終ジャッジ日時 2023-08-23 04:35:09
合計ジャッジ時間 17,196 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,596 KB
testcase_01 AC 379 ms
108,660 KB
testcase_02 AC 392 ms
121,552 KB
testcase_03 AC 364 ms
119,584 KB
testcase_04 AC 368 ms
125,140 KB
testcase_05 AC 400 ms
114,464 KB
testcase_06 AC 381 ms
128,228 KB
testcase_07 AC 426 ms
145,980 KB
testcase_08 AC 418 ms
129,524 KB
testcase_09 AC 398 ms
129,204 KB
testcase_10 AC 389 ms
105,420 KB
testcase_11 AC 414 ms
129,488 KB
testcase_12 AC 411 ms
130,228 KB
testcase_13 AC 418 ms
129,540 KB
testcase_14 AC 423 ms
128,236 KB
testcase_15 AC 417 ms
129,828 KB
testcase_16 AC 410 ms
130,316 KB
testcase_17 AC 409 ms
130,380 KB
testcase_18 AC 408 ms
130,004 KB
testcase_19 AC 415 ms
129,256 KB
testcase_20 AC 414 ms
129,084 KB
testcase_21 AC 413 ms
137,736 KB
testcase_22 AC 408 ms
137,620 KB
testcase_23 AC 419 ms
137,776 KB
testcase_24 AC 414 ms
138,136 KB
testcase_25 AC 398 ms
137,720 KB
testcase_26 AC 407 ms
137,984 KB
testcase_27 AC 412 ms
137,896 KB
testcase_28 AC 405 ms
137,888 KB
testcase_29 AC 410 ms
137,840 KB
testcase_30 AC 416 ms
137,684 KB
testcase_31 AC 270 ms
135,956 KB
testcase_32 AC 274 ms
135,928 KB
testcase_33 AC 273 ms
135,976 KB
testcase_34 AC 296 ms
136,964 KB
testcase_35 AC 292 ms
137,080 KB
testcase_36 AC 294 ms
136,900 KB
testcase_37 AC 307 ms
83,124 KB
testcase_38 AC 415 ms
130,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#yukicoder389D もしかして、真?_AfterContest

'''
並行二分探索木が必要だよなと思っていましたが実際に必要ですね。
しかたないので実装しましょう。

でもnodeを直接覗けばいいのか。うん・・・
'''
#Segment Tree: O(logN)
class SegmentTree:
    def __init__(self,n,identity_e,combine_f):
        self._n=n;self._size=1
        while self._size<self._n:self._size<<=1
        self._identity_e=identity_e;self._combine_f=combine_f;self._node=[self._identity_e]*2*self._size
    def build(self,array):
        assert len(array)==self._n,'array too large'
        for i,v in enumerate(array,start=self._size):self._node[i]=v
        for i in range(self._size-1,0,-1):self._node[i]=self._combine_f(self._node[i<<1|0],self._node[i<<1|1])
    def update(self,index,value):  #一点更新
        i=self._size+index;self._node[i]=value
        while i-1:i>>=1;self._node[i]=self._combine_f(self._node[i<<1|0],self._node[i<<1|1])
    def fold(self,L,R):  #区間取得: [L,R)の区間値を得る
        L+=self._size;R+=self._size;vL,vR=[self._identity_e]*2
        while L<R:
            if L&1:vL=self._combine_f(vL,self._node[L]);L+=1
            if R&1:R-=1;vR=self._combine_f(self._node[R],vR)
            L>>=1;R>>=1
        return self._combine_f(vL,vR)

add =lambda x,y:x+y
oand=lambda x,y:x&y
oor =lambda x,y:x|y
oxor=lambda x,y:x^y
oimp=lambda x,y:y if x else True

for _ in range(int(input())):
    N=int(input()); X=list(map(lambda x:x=='True', input().split()))
    Y=input().split(); S=list(map(int,input().split()))
    ST=SegmentTree(N,0,add); ST.build([1]*N)

    #手動で平衡二分探索木 区間[0,x)がちょうどiとなる最大のiを求めよ
    for i in S:
        cntL,cntR=0,0; Lt,Rt=1,1; size=ST._size  #cnt: 現在の区間より左側にある値の数
        while Lt<size:
            if cntL+ST._node[Lt<<1|0]>=i:   Lt=Lt<<1|0
            else: cntL+=ST._node[Lt<<1|0];  Lt=Lt<<1|1
            if cntR+ST._node[Rt<<1|0]>=i+1: Rt=Rt<<1|0
            else: cntR+=ST._node[Rt<<1|0];  Rt=Rt<<1|1
        Lt-=size; Rt-=size; ST.update(Rt,0)  #演算子を使用したRt側を削除するよう変更
        if   Y[Rt-1]=='and': X[Lt]=oand(X[Lt],X[Rt])
        elif Y[Rt-1]=='or' : X[Lt]=oor (X[Lt],X[Rt])
        elif Y[Rt-1]=='xor': X[Lt]=oxor(X[Lt],X[Rt])
        elif Y[Rt-1]=='imp': X[Lt]=oimp(X[Lt],X[Rt])
    print(X[Lt])
0