結果

問題 No.1084 積の積
ユーザー ooaiu
提出日時 2024-12-10 23:12:38
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 1,269 bytes
コンパイル時間 3,119 ms
コンパイル使用メモリ 256,464 KB
実行使用メモリ 9,808 KB
最終ジャッジ日時 2024-12-10 23:12:45
合計ジャッジ時間 5,631 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifndef LOCAL
#include <bits/stdc++.h>

using namespace std;

#define debug(...) (void(0))
#else
#include "algo/debug.h"
#endif

#include <atcoder/modint>
using mint = atcoder::modint1000000007;

void solve() {
    int N;
    cin >> N;
    vector<int64_t> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        if (A[i] == 0) {
            cout << 0 << endl;
            return;
        }
    }
    vector<vector<int>> thr(N + 1);
    int j = 0;
    __uint128_t mul = 1;
    constexpr __uint128_t inf = 1e9;
    for (int i = 0; i < N; i++) {
        while (j < N && mul * A[j] < inf) mul *= A[j++];
        // [i, j) < 10^9
        thr[j].push_back(i);
        mul /= A[i];
    }
    vector<mint> pref(N + 1, 1);
    for (int i = 0; i < N; i++) pref[i + 1] = pref[i] * A[i];
    mint ans = 1;
    mint ps = 1;
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        cnt++;
        ps *= mint(A[i]).pow(cnt);
        for (int j : thr[i]) {
            mint t = pref[i + 1] / pref[j];
            ps /= t;
            cnt--;
        }
        ans *= ps;
    }
    cout << ans.val() << endl;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int tt = 1;
    // std::cin >> tt;
    while (tt--) {
        solve();
    }
}
0