結果

問題 No.3579 区間積逆像
コンテスト
ユーザー kidodesu
提出日時 2026-07-03 21:37:21
言語 PyPy3
(8.0.0 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 72 ms / 2,000 ms
+ 521µs
コード長 856 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 92 ms
コンパイル使用メモリ 64,656 KB
実行使用メモリ 82,980 KB
最終ジャッジ日時 2026-10-23 13:34:12
合計ジャッジ時間 4,472 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

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