結果

問題 No.1084 積の積
ユーザー imoni_kawaii
提出日時 2020-06-21 14:34:45
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 2,670 bytes
コンパイル時間 2,022 ms
コンパイル使用メモリ 196,028 KB
最終ジャッジ日時 2025-01-11 08:57:52
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
#ifdef _DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif
#define REP(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using ll = long long; using ld = long double; using pll = pair<ll, ll>;
const int INF = 1<<30; const ll LINF = 1LL<<60; const ld PI = 3.1415926535897932;
template<class T, class U> inline bool chmax(T &a, const U &b) { if(a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if(a > b) { a = b; return true; } return false; }
constexpr int MOD = 1e9+7;
//constexpr int MOD = 998244353;
struct mint {
long long x;
mint(long long x = 0) noexcept : x((x%MOD + MOD) % MOD) {}
// basis
mint operator-() const { return mint(-x); }
mint& operator+=(const mint a) noexcept { if((x += a.x) >= MOD) x -= MOD; return *this; }
mint& operator-=(const mint a) noexcept { if((x += MOD-a.x) >= MOD) x -= MOD; return *this; }
mint& operator*=(const mint a) noexcept { (x *= a.x) %= MOD; return *this; }
mint operator+(const mint a) const noexcept { return mint(*this) += a; }
mint operator-(const mint a) const noexcept { return mint(*this) -= a; }
mint operator*(const mint a) const noexcept { return mint(*this) *= a; }
mint mpow(long long t) const noexcept {
if(!t) return 1;
mint a = mpow(t>>1);
a *= a;
if(t&1) a *= *this;
return a;
}
// for prime MOD
mint inv() const noexcept { return mpow(MOD-2); }
mint& operator/=(const mint a) noexcept { return *this *= a.inv(); }
mint operator/(const mint a) const noexcept { return mint(*this) /= a; }
// comparison
bool operator==(const mint &a) const noexcept { return this->x == a.x; }
bool operator!=(const mint &a) const noexcept { return this->x != a.x; }
// I/O stream
friend istream& operator>>(istream& is, mint& a) noexcept { return is >> a.x; }
friend ostream& operator<<(ostream& os, const mint& a) noexcept { return os << a.x; }
};
// additional
mint mpow(const long long &a, long long n) noexcept { return mint(a).mpow(n); }
mint mpow(const mint &a, long long n) noexcept { return a.mpow(n); }
int main() {
cin.tie(0); ios::sync_with_stdio(false);
int n;
cin >> n;
vector<ll> a(n);
rep(i, n) {
cin >> a[i];
if(a[i] == 0) {
cout << 0 << '\n';
return 0;
}
}
mint ans = 1;
ll r = 0, cur = 1;
mint prd = 1;
rep(l, n) {
while(r < n && cur*a[r] < 1e9) {
cur *= a[r];
prd *= cur;
r++;
}
ans *= prd;
if(l >= r) r++;
else {
cur /= a[l];
prd /= mpow(a[l], r-l);
}
}
cout << ans << '\n';
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0