結果

問題 No.2046 Ans Mod? Mod Ans!
ユーザー t98slidert98slider
提出日時 2022-08-24 09:21:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,294 bytes
コンパイル時間 1,752 ms
コンパイル使用メモリ 171,788 KB
実行使用メモリ 7,552 KB
最終ジャッジ日時 2024-05-09 17:35:16
合計ジャッジ時間 4,321 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
7,296 KB
testcase_01 AC 9 ms
7,296 KB
testcase_02 AC 17 ms
7,296 KB
testcase_03 AC 48 ms
7,168 KB
testcase_04 AC 34 ms
7,168 KB
testcase_05 AC 47 ms
7,168 KB
testcase_06 AC 36 ms
7,296 KB
testcase_07 AC 44 ms
7,296 KB
testcase_08 AC 8 ms
7,168 KB
testcase_09 AC 7 ms
7,168 KB
testcase_10 AC 8 ms
7,296 KB
testcase_11 AC 9 ms
7,296 KB
testcase_12 AC 8 ms
7,168 KB
testcase_13 RE -
testcase_14 AC 52 ms
7,168 KB
testcase_15 AC 89 ms
7,168 KB
testcase_16 RE -
testcase_17 AC 78 ms
7,168 KB
testcase_18 AC 120 ms
7,296 KB
testcase_19 RE -
testcase_20 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

template <class T> struct fenwick_tree {
    using U = T;

  public:
    fenwick_tree() : _n(0) {}
    fenwick_tree(int n) : _n(n), data(n) {}

    void add(int p, T x) {
        assert(0 <= p && p < _n);
        p++;
        while (p <= _n) {
            data[p - 1] += U(x);
            p += p & -p;
        }
    }

    T sum(int l, int r) {
        assert(0 <= l && l <= r && r <= _n);
        return sum(r) - sum(l);
    }

  private:
    int _n;
    std::vector<U> data;

    U sum(int r) {
        U s = 0;
        while (r > 0) {
            s += data[r - 1];
            r -= r & -r;
        }
        return s;
    }
};

int main(){
    int n, v, r = 200000;
    cin >> n;
    vector<int> tb(r + 1);
    fenwick_tree<ll> fw1(r + 1), fw2(r + 1);
    for(int i = 0; i < n; i++){
        cin >> v;
        assert(1 <= v && v <= 200000);
        tb[v]++;
        fw1.add(v, v);
        fw2.add(v, 1);
    }
    ll ans = 0;
    for(int i = 1; i <= r; i++){
        if(tb[i] == 0)continue;
        ans += fw2.sum(i + 1, r) * i;
        for(int j = 1; i * j <= r; j++){
            ans -= fw1.sum(i * j, min(r + 1, i * (j + 1))) - fw2.sum(i * j, min(r + 1, i * (j + 1))) * i * j;
        }
    }
    cout << ans << '\n';
}
0