結果

問題 No.1084 積の積
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2020-06-20 14:42:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 6,101 bytes
コンパイル時間 2,221 ms
コンパイル使用メモリ 214,708 KB
実行使用メモリ 34,296 KB
最終ジャッジ日時 2023-09-16 17:27:04
合計ジャッジ時間 4,821 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 84 ms
31,364 KB
testcase_05 AC 7 ms
4,376 KB
testcase_06 AC 85 ms
31,524 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 12 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 34 ms
17,576 KB
testcase_13 AC 69 ms
32,708 KB
testcase_14 AC 21 ms
10,504 KB
testcase_15 AC 20 ms
10,600 KB
testcase_16 AC 77 ms
32,820 KB
testcase_17 AC 32 ms
17,640 KB
testcase_18 AC 46 ms
17,944 KB
testcase_19 AC 70 ms
32,728 KB
testcase_20 AC 16 ms
10,304 KB
testcase_21 AC 22 ms
10,516 KB
testcase_22 AC 18 ms
10,608 KB
testcase_23 AC 39 ms
17,896 KB
testcase_24 AC 36 ms
17,832 KB
testcase_25 AC 67 ms
32,648 KB
testcase_26 AC 74 ms
33,644 KB
testcase_27 AC 75 ms
33,876 KB
testcase_28 AC 72 ms
33,172 KB
testcase_29 AC 73 ms
34,296 KB
testcase_30 AC 74 ms
32,716 KB
testcase_31 AC 74 ms
32,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
ll mul(ll a, ll b) { if (a == 0) return 0; if (infl / a < b) return infl; return min(infl, a * b); }
// スパーステーブルをまずは検討しよう
#ifdef _MSC_VER
inline unsigned int __builtin_clz(unsigned int x){unsigned long r;_BitScanReverse(&r,x);return 31-r;}
#endif // _MSC_VER
template<class V> struct SparseTable { // [L,R)
    const V def = 1;
    inline V comp(V a, V b) { return mul(a, b); }

    int n; vector<V> a, b[22]; inline int __lg(int x) { return 32 - 1 - __builtin_clz(x); }
    void init(V* start, V* end) {
        vector<V> v;
        for (auto ite = start; ite != end; ite++) v.push_back(*ite);
        init(v);
    }
    void init(vector<V> v) {
        int nn = v.size(); n = 1; while (n < nn) n *= 2; a.resize(n);
        rep(i, 0, 22) b[i].resize(n); rep(i, 0, nn) a[i] = v[i];

        int d = 1 << __lg(n - 1), e = d << 1;
        for (int h = 0, f; (f = 1 << h) <= d; ++h) {
            for (int i = f, r = f << 1; i < e; i += r) {
                b[h][i - 1] = a[i - 1];
                for (int j = i - 2; j >= i - f; --j) b[h][j] = comp(b[h][j + 1], a[j]);
                b[h][i] = a[i];
                for (int j = i + 1; j < i + f; ++j) b[h][j] = comp(b[h][j - 1], a[j]);
            }
        }
    }

    V get(int L,int R){assert(0<=L&&L<=R);if(L==R)return def;R--;if(L==R)return a[L];int h=__lg(L^R);
        return comp(b[h][L],b[h][R]);}};
template <typename T> struct ImosLinear {
    vector<T> v;
    vector<tuple<int, int, T>> buf;
    ImosLinear(int n) { init(n); } ImosLinear() {}
    void init(int n) { v.resize(n, 0); buf.clear(); }
    // [l,r)に傾きaで、切片bの一次関数を足す
    void set(int l, int r, T a, T b) {
        if (l + 1 < v.size()) v[l + 1] += a; if (r < v.size()) v[r] -= a;
        if (r < v.size()) buf.push_back(make_tuple(r, v.size(), (T)-(r - l - 1) * a));
        buf.push_back(make_tuple(l, r, b));
    }
    void build() {
        rep(i, 1, v.size()) v[i] += v[i - 1];
        for (auto t : buf) {
            int l, r; T b; tie(l, r, b) = t;
            v[l] += b;
            if (r < v.size()) v[r] -= b;
        }
        rep(i, 1, v.size()) v[i] += v[i - 1];
    }
    T operator[](int i) { return v[i]; }
    void dump() {
        cout << "dump : [";
        for (T i : v) cout << " " << i;
        cout << " ]" << endl;
    }
};
template<int MOD> struct ModInt {
    static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
        return ModInt(u); }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
    ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
typedef ModInt<1000000007> mint;
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/









int N; ll A[101010];
SparseTable<ll> st;
ImosLinear<ll> imos;
int limit = 1000000000;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	rep(i, 0, N) cin >> A[i];

    rep(i, 0, N) if (A[i] == 0) {
        cout << 0 << endl;
        return;
    }

    st.init(A, A + N);
    imos.init(N);

    rep(l, 0, N) {
        int ok = l + 1, ng = N + 1;
        while (ok + 1 != ng) {
            int md = (ok + ng) / 2;
            if (st.get(l, md) < limit) ok = md;
            else ng = md;
        }
        imos.set(l, ok, -1, ok - l);
    }

    imos.build();

    mint ans = 1;
    rep(i, 0, N) ans *= mint(A[i]) ^ imos[i];
    cout << ans << endl;
}





0