結果

問題 No.2046 Ans Mod? Mod Ans!
ユーザー t98slidert98slider
提出日時 2022-08-24 09:18:40
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,273 bytes
コンパイル時間 1,654 ms
コンパイル使用メモリ 168,024 KB
実行使用メモリ 7,368 KB
最終ジャッジ日時 2023-08-22 11:53:53
合計ジャッジ時間 4,328 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
7,128 KB
testcase_01 AC 12 ms
6,976 KB
testcase_02 AC 23 ms
7,064 KB
testcase_03 AC 62 ms
6,992 KB
testcase_04 AC 42 ms
6,880 KB
testcase_05 AC 62 ms
7,036 KB
testcase_06 AC 45 ms
6,948 KB
testcase_07 AC 59 ms
7,028 KB
testcase_08 AC 8 ms
6,872 KB
testcase_09 AC 8 ms
6,976 KB
testcase_10 AC 9 ms
7,000 KB
testcase_11 AC 10 ms
6,920 KB
testcase_12 AC 9 ms
7,176 KB
testcase_13 RE -
testcase_14 AC 57 ms
7,076 KB
testcase_15 AC 99 ms
6,920 KB
testcase_16 RE -
testcase_17 AC 87 ms
6,996 KB
testcase_18 AC 136 ms
7,168 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;
        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) * tb[i] * i;
        for(int j = 1; i * j <= r; j++){
            ans -= tb[i] * (fw1.sum(i * j, min(r + 1, i * (j + 1))) - i * j * fw2.sum(i * j, min(r + 1, i * (j + 1))));
        }
    }
    cout << ans << '\n';
}
0