結果
問題 | 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,169 ms |
コンパイル使用メモリ | 217,508 KB |
実行使用メモリ | 33,764 KB |
最終ジャッジ日時 | 2024-07-03 17:17:11 |
合計ジャッジ時間 | 4,386 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 84 ms
31,440 KB |
testcase_05 | AC | 7 ms
6,944 KB |
testcase_06 | AC | 85 ms
31,436 KB |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | AC | 2 ms
6,948 KB |
testcase_09 | AC | 12 ms
6,944 KB |
testcase_10 | AC | 2 ms
6,944 KB |
testcase_11 | AC | 4 ms
6,944 KB |
testcase_12 | AC | 33 ms
17,860 KB |
testcase_13 | AC | 68 ms
32,912 KB |
testcase_14 | AC | 21 ms
10,924 KB |
testcase_15 | AC | 20 ms
10,888 KB |
testcase_16 | AC | 75 ms
32,732 KB |
testcase_17 | AC | 30 ms
17,820 KB |
testcase_18 | AC | 42 ms
18,232 KB |
testcase_19 | AC | 67 ms
32,932 KB |
testcase_20 | AC | 16 ms
10,744 KB |
testcase_21 | AC | 20 ms
10,800 KB |
testcase_22 | AC | 18 ms
10,808 KB |
testcase_23 | AC | 37 ms
18,040 KB |
testcase_24 | AC | 34 ms
17,956 KB |
testcase_25 | AC | 65 ms
32,796 KB |
testcase_26 | AC | 75 ms
32,992 KB |
testcase_27 | AC | 74 ms
32,996 KB |
testcase_28 | AC | 71 ms
32,864 KB |
testcase_29 | AC | 73 ms
33,764 KB |
testcase_30 | AC | 70 ms
32,744 KB |
testcase_31 | AC | 69 ms
33,640 KB |
ソースコード
#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; }