結果

問題 No.803 Very Limited Xor Subset
ユーザー tpynerivertpyneriver
提出日時 2019-05-30 14:16:24
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 3,678 bytes
コンパイル時間 105 ms
コンパイル使用メモリ 12,420 KB
実行使用メモリ 10,648 KB
最終ジャッジ日時 2023-10-17 18:52:20
合計ジャッジ時間 3,899 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
10,604 KB
testcase_01 AC 33 ms
10,604 KB
testcase_02 AC 33 ms
10,604 KB
testcase_03 AC 30 ms
10,616 KB
testcase_04 AC 29 ms
10,620 KB
testcase_05 AC 31 ms
10,620 KB
testcase_06 AC 31 ms
10,620 KB
testcase_07 AC 31 ms
10,620 KB
testcase_08 AC 30 ms
10,620 KB
testcase_09 AC 31 ms
10,620 KB
testcase_10 AC 32 ms
10,624 KB
testcase_11 AC 31 ms
10,624 KB
testcase_12 AC 31 ms
10,624 KB
testcase_13 AC 32 ms
10,620 KB
testcase_14 AC 63 ms
10,628 KB
testcase_15 AC 66 ms
10,628 KB
testcase_16 AC 64 ms
10,628 KB
testcase_17 AC 65 ms
10,628 KB
testcase_18 AC 65 ms
10,628 KB
testcase_19 AC 65 ms
10,628 KB
testcase_20 AC 64 ms
10,628 KB
testcase_21 AC 66 ms
10,628 KB
testcase_22 AC 66 ms
10,628 KB
testcase_23 AC 78 ms
10,648 KB
testcase_24 AC 77 ms
10,644 KB
testcase_25 AC 78 ms
10,644 KB
testcase_26 AC 76 ms
10,640 KB
testcase_27 AC 76 ms
10,640 KB
testcase_28 AC 74 ms
10,628 KB
testcase_29 AC 74 ms
10,640 KB
testcase_30 AC 75 ms
10,640 KB
testcase_31 AC 78 ms
10,644 KB
testcase_32 AC 77 ms
10,628 KB
testcase_33 AC 78 ms
10,644 KB
testcase_34 AC 36 ms
10,628 KB
testcase_35 AC 77 ms
10,636 KB
testcase_36 AC 45 ms
10,628 KB
testcase_37 AC 54 ms
10,628 KB
testcase_38 AC 32 ms
10,628 KB
testcase_39 AC 32 ms
10,628 KB
testcase_40 AC 77 ms
10,632 KB
testcase_41 AC 73 ms
10,628 KB
testcase_42 AC 76 ms
10,636 KB
testcase_43 AC 73 ms
10,620 KB
testcase_44 AC 31 ms
10,620 KB
testcase_45 AC 30 ms
10,620 KB
testcase_46 AC 36 ms
10,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class GE():
    #mod2 なら Aは1重リストで渡して, max(bit_length) をMに渡してあげた方が速い
    def __init__(self, A, mod, M = 0):
        self.N = len(A)
        if M:
            self.M = M
        else:
            self.M = len(A[0])
        self.mod = mod
        self.A = A[:]
        self.uptri = None
        self.A2 = None
        self.pivot = []
        self.R = None
    def ut(self):
        if self.mod != 2:
            if self.uptri is not None:
                return self.uptri
            self.uptri = self.A[:]
            c = 0
            for i in range(self.N):
                if i + c >= self.M:
                    break
                while self.uptri[i][i+c] == 0:
                    for j in range(i+1, self.N):
                        if self.uptri[j][i+c]:
                            self.uptri[i], self.uptri[j] = self.uptri[j], self.uptri[i]
                            break
                    else:
                        c += 1
                        if i + c == self.M:
                            break
                else:
                    self.pivot.append((i, i+c))
                    t = pow(self.uptri[i][i+c], self.mod - 2, self.mod)
                    for j in range(i+1, self.N):
                        tj = t * self.uptri[j][i+c]
                        self.uptri[j][i+c:] = [(aj - tj*ai) % self.mod for ai, aj in zip(self.uptri[i][i+c:], self.uptri[j][i+c:])]
                    continue
                break
            for pi, pj in self.pivot[::-1]:
                t = pow(self.uptri[pi][pj], self.mod-2, self.mod)
                self.uptri[pi][pj:] = [(ai * t) % self.mod for ai in self.uptri[pi][pj:]]
                for i in range(pi-1, -1, -1):
                    ti = self.uptri[i][pj]
                    self.uptri[i][pj:] = [(ai - api*ti) % self.mod for ai, api in zip(self.uptri[i][pj:], self.uptri[pi][pj:])]
            
            return self.uptri
        else:
            if self.A2 is not None:
                return self.A2
            self.A2 = self.A[:]
            c = 0
            for i in range(self.N):
                if i + c >= self.M:
                    break
                while not self.A2[i] & 2**(i+c):
                    for j in range(i+1, self.N):
                        if self.A2[j] & 2**(i+c):
                            self.A2[i], self.A2[j] = self.A2[j], self.A2[i]
                            break
                    else:
                        c += 1
                        if i + c == self.M:
                            break
                else:
                    self.pivot.append((i, i+c))
                    for j in range(i+1, self.N):
                        if self.A2[j] & 2**(i+c):
                            self.A2[j] ^= self.A2[i]
                    continue
                break
            for pi, pj in self.pivot[::-1]:
                for i in range(pi-1, -1, -1):
                    if 2**pj & self.A2[i]:
                        self.A2[i] ^= self.A2[pi]
            
            return self.A2
            
                
    def rank(self):
        if self.R is not None:
            return self.R
        self.ut()
        self.R = len(self.pivot)
        return self.R

import sys
N, M, X = map(int, input().split())
mod = 10**9+7
A = list(map(int,input().split())) + [X]

AM = [sum(2**j if 2**i & a else 0 for j, a in enumerate(A)) for i in range(30)]
for _ in range(M):
    t, l, r = map(int, sys.stdin.readline().split())
    AM.append(2**r - 2**(l-1) + 2**N*t)

T = GE(AM, 2, N+1)
ans = 0
for u in T.ut():
    if u == 2**N:
        break
else:
    ans = pow(2, N-T.rank(), mod)
print(ans)
0