結果

問題 No.1096 Range Sums
ユーザー renjyaku_intrenjyaku_int
提出日時 2020-09-10 19:40:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 186 ms / 2,000 ms
コード長 4,227 bytes
コンパイル時間 2,436 ms
コンパイル使用メモリ 210,332 KB
実行使用メモリ 20,456 KB
最終ジャッジ日時 2023-08-25 11:48:34
合計ジャッジ時間 6,285 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 173 ms
18,816 KB
testcase_01 AC 169 ms
18,820 KB
testcase_02 AC 168 ms
18,636 KB
testcase_03 AC 174 ms
18,868 KB
testcase_04 AC 175 ms
18,536 KB
testcase_05 AC 175 ms
18,532 KB
testcase_06 AC 174 ms
18,516 KB
testcase_07 AC 176 ms
18,728 KB
testcase_08 AC 170 ms
18,532 KB
testcase_09 AC 170 ms
18,644 KB
testcase_10 AC 186 ms
20,280 KB
testcase_11 AC 181 ms
20,456 KB
testcase_12 AC 184 ms
20,376 KB
testcase_13 AC 183 ms
20,136 KB
testcase_14 AC 181 ms
20,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#include <tourist>
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//g++ yarudake.cpp -std=c++17 -I .
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll M = pow(10, 9) + 7;

vector<ll> fac(1000001);  //n!(mod M)
vector<ll> ifac(1000001); //k!^{M-2} (mod M)
ll mpow(ll x, ll n)
{ //x^n(mod M)
    ll ans = 1;
    while (n != 0)
    {
        if (n & 1)
            ans = ans * x % M;
        x = x * x % M;
        n = n >> 1;
    }
    return ans;
}
//conbination
ll comb(ll a, ll b)
{ //aCb(mod M)
    if (a == 0 && b == 0)
        return 1;
    if (a < b || a < 0)
        return 0;
    ll tmp = ifac[a - b] * ifac[b] % M;
    return tmp * fac[a] % M;
}
//素因数分解o√n
map<int, int> prime_factor(int n)
{
    map<int, int> res;
    for (int i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ++res[i];
            n /= i;
        }
    }
    if (n != 1)
        res[n] = 1;
    // for (int i = 2; i <= n; i++)
    //cout << res[i] << "\n";
    return res;
}
//n!
ll fact_mod(ll n)
{
    ll ret = 1;
    for (ll i = 2; i <= n; i++)
        ret = ret * (i % MOD) % MOD;
    return ret;
}

// 繰り返し二乗法
ll pow_mod(ll x, ll n)
{
    if (n == 0)
        return 1;
    ll ret = pow_mod((x * x) % MOD, n / 2);
    if (n & 1)
        ret = (ret * x) % MOD;
    return ret;
}

//nCr O(r) nがでかくても安心
ll combination_mod(ll n, ll r)
{
    if (r > n - r)
        r = n - r;
    if (r == 0)
        return 1;
    ll a = 1;
    //a=n!/(n-r)!=n~n-r+1までの総積->O(r)
    for (ll i = 0; i < r; i++)
        a = a * ((n - i) % MOD) % MOD;
    //b=inv(r!)
    ll b = pow_mod(fact_mod(r), MOD - 2);
    return (a % MOD) * (b % MOD) % MOD;
}

ll inv_mod(ll n)
{
    // フェルマーの小定理
    return pow_mod(n, MOD - 2);
}
const int N_MAX = 1001;
double pascal[N_MAX][N_MAX] = {};

// パスカルの三角形
// 確率Ver
// n段目は 2^n で割った値が入る (横の和 = 1)

void calc_pascal()
{
    FOR(i, 0, N_MAX)
    {
        pascal[i][0] = 1.0 / pow(2.0f, i);
    }
    pascal[1][1] = 1.0 / 2.0;

    FOR(i, 2, N_MAX)
    {
        for (int j = 1; j <= i; j++)
        {
            pascal[i][j] = pascal[i - 1][j] + pascal[i - 1][j - 1];
            pascal[i][j] /= 2.0;
        }
    }
}
//kが大きいときにO(n)でi+kCi (0<i<n)
vector<ll> comb_recur(ll n, ll k)
{
    vector<ll> res(n, 1);
    for (ll i = 1; i < n; i++)
    {
        res[i] *= (k + i);
        res[i] %= MOD;
        res[i] *= inv_mod(i);
        res[i] %= MOD;
        res[i] *= res[i - 1];
        res[i] %= MOD;
    }
    return res;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    fac[0] = 1;
    ifac[0] = 1;
    for (ll i = 0; i < 1000000; i++)
    {
        fac[i + 1] = fac[i] * (i + 1) % M;              // n!(mod M)
        ifac[i + 1] = ifac[i] * mpow(i + 1, M - 2) % M; // k!^{M-2} (mod M)
    }
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll ans=0;
    rep(i,n){
        ans+=(i+1)*(n-i)*a[i];
    }
    cout<<ans<<"\n";
}
0