結果

問題 No.1084 積の積
ユーザー Y17
提出日時 2020-06-19 21:50:19
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 1,514 bytes
コンパイル時間 1,522 ms
コンパイル使用メモリ 170,836 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-03 14:19:06
合計ジャッジ時間 3,438 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

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