結果

問題 No.3579 区間積逆像
コンテスト
ユーザー t98slider
提出日時 2026-07-03 22:20:10
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 996 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,357 ms
コンパイル使用メモリ 379,208 KB
実行使用メモリ 13,312 KB
最終ジャッジ日時 2026-07-03 22:20:51
合計ジャッジ時間 6,632 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;
using mint = atcoder::modint;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, p, c;
    cin >> n >> p >> c;
    vector<int> a(n);
    for(auto &&v : a) cin >> v;
    mint::set_mod(p);
    ll ans = 0;
    map<int, int> mp;
    if(c == 0){
        ans += n * (ll)(n + 1) / 2;
        for(int i = 0; i < n; ){
            int p = i;
            while(i < n && a[i] == a[p]) i++;
            if(a[p] == 0) continue;
            ans -= (i - p) * (ll)(i - p + 1) / 2;
        }
    }else{
        mint mul = 1, divc = mint(c).inv();
        mp[1] = 1;
        for(int i = 0; i < n; i++){
            if(a[i] == 0){
                mul = 1;
                mp.clear();
                mp[1] = 1;
                continue;
            }
            mul *= mint::raw(a[i]);
            ans += mp[(mul * divc).val()];
            mp[mul.val()]++;
        }
    }
    cout << ans << '\n';
}
0