結果
問題 | No.1084 積の積 |
ユーザー | tanimani364 |
提出日時 | 2020-06-23 02:45:45 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,770 bytes |
コンパイル時間 | 2,023 ms |
コンパイル使用メモリ | 207,876 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-03 19:05:30 |
合計ジャッジ時間 | 5,358 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | AC | 7 ms
6,944 KB |
testcase_06 | WA | - |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | WA | - |
testcase_09 | AC | 12 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,944 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
ソースコード
#include <bits/stdc++.h> #define rep(i, a) for (int i = (int)0; i < (int)a; ++i) #define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i) #define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i) #define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i) #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() using ll = long long; constexpr ll mod = 1e9 + 7; constexpr ll INF = 1LL << 60; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } ll gcd(ll n, ll m) { ll tmp; while (m != 0) { tmp = n % m; n = m; m = tmp; } return n; } ll lcm(ll n, ll m) { return abs(n) / gcd(n, m) * abs(m); //gl=xy } using namespace std; template< int mod > struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int) (1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while(b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(int64_t n) const { ModInt ret(1), mul(x); while(n > 0) { if(n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt< mod >(t); return (is); } static int get_mod() { return mod; } }; using modint = ModInt< mod >; template<typename T> struct Linear_imos{ vector<T>imos,imos2; int n;//要素数 bool flag; Linear_imos(int n):n(n){ flag=false; imos=vector<T>(n+1); imos2=vector<T>(n+1); } void add(int l,int r,T a,T b){//[l,r),公差a,初項bについての加算 imos[l]+=a; imos[r]-=a; imos2[r]-=a*(r-l); imos2[l]+=b+1; imos2[r]-=b+1; } void build(){ flag=true; for(int i=0;i<n;++i)imos[i+1]+=imos[i]; for(int i=0;i<n;++i)imos[i]+=imos2[i]; for(int i=0;i<n;++i)imos[i+1]+=imos[i]; } T value(int id){ assert(flag); return imos[id]; } }; void solve() { int n; cin>>n; vector<ll>a(n); rep(i,n)cin>>a[i]; rep(i,n)if(!a[i]){cout<<0<<"\n";return;} Linear_imos<ll>imos(n); modint ans=1; ll right=0; ll sum=1; for(ll left=0;left<n;++left){ while(right<n&&sum*a[right]<1e9){ sum*=a[right]; ++right; } imos.add(left,right,-1,right-left); sum/=a[left]; if(left==right)++right; } imos.build(); rep(i,n+1)cout<<imos.value(i)<<endl; rep(i,n){ modint x=a[i]; ans*=x.pow(imos.value(i)); } cout<<ans<<"\n"; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); solve(); return 0; }