結果

問題 No.1084 積の積
ユーザー Y17Y17
提出日時 2020-06-19 21:50:19
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 1,514 bytes
コンパイル時間 1,587 ms
コンパイル使用メモリ 168,416 KB
実行使用メモリ 6,340 KB
最終ジャッジ日時 2023-09-16 13:57:12
合計ジャッジ時間 3,896 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 35 ms
6,148 KB
testcase_05 AC 15 ms
4,384 KB
testcase_06 AC 36 ms
6,168 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 36 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 3 ms
4,384 KB
testcase_12 AC 19 ms
4,420 KB
testcase_13 AC 37 ms
5,640 KB
testcase_14 AC 15 ms
4,384 KB
testcase_15 AC 14 ms
4,384 KB
testcase_16 AC 43 ms
6,304 KB
testcase_17 AC 17 ms
4,380 KB
testcase_18 AC 29 ms
5,252 KB
testcase_19 AC 38 ms
5,656 KB
testcase_20 AC 10 ms
4,380 KB
testcase_21 AC 15 ms
4,384 KB
testcase_22 AC 11 ms
4,384 KB
testcase_23 AC 24 ms
4,636 KB
testcase_24 AC 21 ms
4,688 KB
testcase_25 AC 38 ms
5,684 KB
testcase_26 AC 26 ms
6,256 KB
testcase_27 AC 26 ms
6,260 KB
testcase_28 AC 26 ms
6,168 KB
testcase_29 AC 27 ms
6,340 KB
testcase_30 AC 26 ms
6,224 KB
testcase_31 AC 26 ms
6,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template <typename T>
struct cumulative_sum_linear {
    int n;
    std::vector<T> x, a, b;

    cumulative_sum_linear(int n_ = 0) : n(n_), x(n), a(n + 1), b(n + 1) {}

    void add(int l, int r, T aa, T bb) {
        a[l] += aa;
        a[r] -= aa;
        a[l] -= bb * l;
        a[r] += bb * l;
        b[l] += bb;
        b[r] -= bb;
    }

    void exec() {
        for (int i = 0; i < n; ++i) {
            x[i] = a[i] + b[i] * i;
            a[i + 1] += a[i];
            b[i + 1] += b[i];
        }
    }

    T operator[](int i) const { return x[i]; }
};

#define MOD 1000000007;

int pow_mod(int n, int m){
	int ans = 1;
	while(m > 0){
		if(m & 1) ans = (ans * n) % MOD;
		n = (n * n) % MOD;
		m >>= 1;
	}
	return ans;
}

signed main(){
	int n;
	cin >> n;

	int a[100010];
	bool f = false;
	for(int i = 0;i < n;i++){
		cin >> a[i];
		f |= (a[i] == 0);
	}

	if(f){
		cout << 0 << endl;
		return 0;
	}

	int r = 0;
	int now = 1;
	a[n] = 1000000001;
	cumulative_sum_linear<int> imo(n); 
	for(int l = 0;l < n;l++){
		while(now*a[r] < (long long)1e9){
			now *= a[r];
			r++;
		}
		imo.add(l, r, r-l, -1);
		now /= a[l];
	}

	int ans = 1;
	imo.exec();
	for(int i = 0;i < n;i++){
		ans *= pow_mod(a[i], imo[i]);
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}
0