結果

問題 No.3579 区間積逆像
コンテスト
ユーザー LyricalMaestro
提出日時 2026-07-05 16:14:23
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 1,081 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 569 ms
コンパイル使用メモリ 96,488 KB
実行使用メモリ 120,032 KB
最終ジャッジ日時 2026-07-05 16:14:33
合計ジャッジ時間 4,794 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 12 WA * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

# https://yukicoder.me/problems/no/3579


def main():
    N, P, C = map(int, input().split())
    A = list(map(int, input().split()))

    array = []
    prev = False
    for a in A:
        if a % P != 0:
            if not prev:
                array.append([a])
            else:
                array[-1].append(a)
            prev = True
        else:
            prev = False
    if C == 0:
        ans = 0
        for x in array:
            ans += (len(x) * (len(x) + 1)) // 2
        
        total = (N * (N + 1)) // 2
        print(total - ans)
    else:
        answer = 0
        inv_c = pow(C, P - 2, P)
        for x_array in array:
            p_map = {1: 1}
            cum_p = 1

            for a in x_array:
                cum_p *= a
                cum_p %= P

                x = (a * inv_c) % P
                if x in p_map:
                    answer += p_map[x]
                
                if cum_p not in p_map:
                    p_map[cum_p] = 0
                p_map[cum_p] += 1
        print(answer)






if __name__ == "__main__":
    main()
0