結果

問題 No.3579 区間積逆像
コンテスト
ユーザー kidodesu
提出日時 2026-07-03 21:37:21
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 856 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 163 ms
コンパイル使用メモリ 85,504 KB
実行使用メモリ 99,072 KB
最終ジャッジ日時 2026-07-03 21:37:26
合計ジャッジ時間 3,307 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

def main():
    n, mod, c = list(map(int, input().split()))
    A = list(map(int, input().split()))
    if c == 0:
        p = 0
        ans = 0
        for a in A:
            if a == 0:
                ans += p * (p+1) // 2
                p = 0
            else:
                p += 1
        ans += p * (p+1) // 2
        ans = n * (n+1) // 2 - ans
        return ans
    else:
        c_ = pow(c, -1, mod)
        D = {1: 1}
        now = 1
        ans = 0
        for a in A:
            now = now * a % mod
            if now == 0:
                now = 1
                D = {1: 1}
            else:
                nxt = now * c_ % mod
                if nxt in D:
                    ans += D[nxt]
                if now in D:
                    D[now] += 1
                else:
                    D[now] = 1
        return ans

print(main())
0