結果

問題 No.1233 割り切れない気持ち
ユーザー rokahikou1rokahikou1
提出日時 2020-11-26 17:10:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,919 bytes
コンパイル時間 1,563 ms
コンパイル使用メモリ 171,536 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2023-10-01 03:26:26
合計ジャッジ時間 10,789 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
4,556 KB
testcase_01 AC 7 ms
4,652 KB
testcase_02 AC 20 ms
4,516 KB
testcase_03 AC 50 ms
4,652 KB
testcase_04 AC 36 ms
4,660 KB
testcase_05 AC 27 ms
4,640 KB
testcase_06 AC 26 ms
4,656 KB
testcase_07 AC 71 ms
4,796 KB
testcase_08 AC 75 ms
5,364 KB
testcase_09 AC 89 ms
5,968 KB
testcase_10 AC 90 ms
5,852 KB
testcase_11 AC 65 ms
4,920 KB
testcase_12 AC 96 ms
6,316 KB
testcase_13 AC 93 ms
6,208 KB
testcase_14 AC 95 ms
6,248 KB
testcase_15 AC 96 ms
6,116 KB
testcase_16 AC 99 ms
6,236 KB
testcase_17 TLE -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#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 LLA(v) (v).rbegin(), (v).rend()
#define PB push_back
#define MP(a, b) make_pair((a), (b))
using namespace std;
template <class T> inline vector<T> make_vec(size_t a, T val) {
    return vector<T>(a, val);
}
template <class... Ts> inline auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec(ts...))>(a, make_vec(ts...));
}
template <typename T> inline T read() {
    T t;
    cin >> t;
    return t;
}
template <typename T> inline vector<T> readv(size_t sz) {
    vector<T> ret(sz);
    rep(i, sz) cin >> ret[i];
    return ret;
}
template <typename... Ts> inline tuple<Ts...> reads() {
    return {read<Ts>()...};
}
template <typename T> struct edge {
    int to;
    T cost;
    edge(int t, T c) : to(t), cost(c) {}
};
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
template <typename T> using WGraph = vector<vector<edge<T>>>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

// 参考:https://qiita.com/drken/items/1b7e6e459c24a83bb7fd
// 1-indexed BIT
// add:log(N),sum:log(N),get_k-th:log(N)
// https://codeforces.com/contest/1354/problem/D
struct BIT {
    vector<ll> dat;

    BIT(int n) {
        dat.resize(n + 1);
        for(int i = 0; i < (int)dat.size(); i++)
            dat[i] = 0;
    }

    // a is 1-indexed
    void add(int a, ll x) {
        for(int i = a; i < (int)dat.size(); i += i & -i)
            dat[i] = dat[i] + x;
    }

    // [1,a], a is 1-indexed
    ll sum(int a) {
        ll res = 0;
        for(int i = a; i > 0; i -= i & -i) {
            res = res + dat[i];
        }
        return res;
    }

    // [a,b), a and b are 1-indexed
    ll sum(int a, int b) { return sum(b - 1) - sum(a - 1); }

    // k-th number (k is 1-indexed)
    // lower_bound
    int get(ll k) {
        if(k <= 0)
            return 0;
        int res = 0;
        int N = 1;
        while(N < (int)dat.size())
            N *= 2;
        for(int i = N / 2; i > 0; i /= 2) {
            if(res + i < (int)dat.size() && dat[res + i] < k) {
                k = k - dat[res + i];
                res = res + i;
            }
        }
        return res + 1;
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N = read<ll>();
    auto A = readv<ll>(N);

    BIT bit(200010);
    ll sum = 0;
    rep(i, N) {
        bit.add(A[i], 1);
        sum += A[i];
    }
    map<ll, ll> table;
    ll sub = 0;
    for(int i = 0; i < N; i++) {
        ll modsum = 0;
        for(int j = 1; A[i] * j <= 200000; j++) {
            modsum += bit.sum(j * A[i], min(200001LL, (j + 1) * A[i])) * j;
        }
        sub += A[i] * modsum;
    }
    ll res = N * sum - sub;
    cout << res << endl;
}
0