結果

問題 No.1336 Union on Blackboard
ユーザー uw_yu1rabbit
提出日時 2021-01-17 01:25:37
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 3,193 bytes
コンパイル時間 3,562 ms
コンパイル使用メモリ 106,692 KB
最終ジャッジ日時 2025-01-17 23:56:20
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

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

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<cstdint>
#include<cstddef>
#include<vector>
#include<queue>
//#include<atcoder/all>
//using namespace atcoder;
using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using usize = size_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using i128 = __int128_t;
using u128 = __uint128_t;
template<typename T>
using vec = vector<T>;
#define rep(i, n) for (i64 i = 0; i < (i64)(n); ++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define len(hoge) (i64)((hoge).size())
using P = pair<i64,i64>;
constexpr i64 MAX = 10000000;
constexpr i64 MOD = 1000000007;
i64 fac[MAX], finv[MAX], inv[MAX];
template <i64 modulus>
class modcal
{
public:
i64 a;
constexpr modcal(const i64 x = 0) noexcept : a(x % modulus) {}
constexpr i64 &value() noexcept { return a; }
constexpr const i64 &value() const noexcept { return a; }
constexpr modcal operator+(const modcal rhs) const noexcept
{
return modcal(*this) += rhs;
}
constexpr modcal operator-(const modcal rhs) const noexcept
{
return modcal(*this) -= rhs;
}
constexpr modcal operator*(const modcal rhs) const noexcept
{
return modcal(*this) *= rhs;
}
constexpr modcal operator/(const modcal rhs) noexcept
{
return modcal(*this) /= rhs;
}
constexpr modcal &operator+=(const modcal rhs) noexcept
{
a += rhs.a;
if (a >= modulus)
{
a -= modulus;
}
return *this;
}
constexpr modcal &operator-=(const modcal rhs) noexcept
{
if (a < rhs.a)
{
a += modulus;
}
a -= rhs.a;
return *this;
}
constexpr modcal &operator*=(const modcal rhs) noexcept
{
a = a * rhs.a % modulus;
return *this;
}
constexpr modcal &operator/=(modcal rhs) noexcept
{
i64 exp = modulus - 2;
while (exp)
{
if (exp % 2)
{
*this *= rhs;
}
rhs *= rhs;
exp /= 2;
}
return *this;
}
void COMninit()
{
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++)
{
fac[i] = fac[i - 1] * i % modulus;
inv[i] = MOD - inv[modulus % i] * (modulus / i) % modulus;
finv[i] = finv[i - 1] * inv[i] % modulus;
}
}
i64 COMn(i64 n, i64 k)
{
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % modulus) % modulus;
}
constexpr modcal<1000000007> modpow(const modcal<1000000007> &a, i64 n)
{
if (n == 0)
return 1;
auto t = modpow(a, n / 2);
t = t * t;
if (n & 1)
t = t * a;
return t;
}
};
using modc = modcal<1000000007>;
void solve(){
i64 n;
cin >> n;
queue<i64> que;
modc ans = 0;
rep(i,n){
i64 k;
cin >> k;
que.push(k);
}
ans = que.front();
que.pop();
while(!que.empty()){
ans = (ans + que.front()) + (ans * que.front());
que.pop();
}
cout << ans.a << endl;
}
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
i64 t;
cin >> t;
rep(i,t)solve();
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0