結果

問題 No.3553 Good Quartet
コンテスト
ユーザー detteiuu
提出日時 2026-05-31 01:56:43
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 375 ms / 2,000 ms
コード長 1,659 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 121 ms
コンパイル使用メモリ 85,888 KB
実行使用メモリ 125,440 KB
最終ジャッジ日時 2026-05-31 01:56:50
合計ジャッジ時間 6,461 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
純コード判定待ち
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

MOD = 998244353

N, Q = map(int, input().split())
S = set(map(int, input().split()))
query = [list(map(int, input().split())) for _ in range(Q)]

ans = 0

A = [1, 5, 7, 11]
B = [1, 11, 19, 29]
for s in S:
    for a in A:
        if a*s not in S:
            break
    else:
        ans += 1
        ans %= MOD
    for b in B:
        if b*s not in S:
            break
    else:
        ans += 1
        ans %= MOD

for t, x in query:
    if t == 1:
        S.add(x)
        for a in A:
            if x%a == 0:
                n = x//a
                for c in A:
                    if a == c: continue
                    if n*c not in S:
                        break
                else:
                    ans += 1
                    ans %= MOD
        for b in B:
            if x%b == 0:
                n = x//b
                for c in B:
                    if b == c: continue
                    if n*c not in S:
                        break
                else:
                    ans += 1
                    ans %= MOD
    else:
        S.remove(x)
        for a in A:
            if x%a == 0:
                n = x//a
                for c in A:
                    if a == c: continue
                    if n*c not in S:
                        break
                else:
                    ans -= 1
                    ans %= MOD
        for b in B:
            if x%b == 0:
                n = x//b
                for c in B:
                    if b == c: continue
                    if n*c not in S:
                        break
                else:
                    ans -= 1
                    ans %= MOD
    print(ans)
0