結果

問題 No.1233 割り切れない気持ち
ユーザー rokahikou1rokahikou1
提出日時 2020-11-26 17:12:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 213 ms / 3,153 ms
コード長 3,071 bytes
コンパイル時間 1,587 ms
コンパイル使用メモリ 176,868 KB
実行使用メモリ 18,508 KB
最終ジャッジ日時 2023-10-01 03:26:38
合計ジャッジ時間 6,074 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
4,636 KB
testcase_01 AC 3 ms
4,696 KB
testcase_02 AC 14 ms
4,512 KB
testcase_03 AC 26 ms
4,640 KB
testcase_04 AC 23 ms
4,648 KB
testcase_05 AC 15 ms
4,588 KB
testcase_06 AC 17 ms
4,700 KB
testcase_07 AC 71 ms
6,968 KB
testcase_08 AC 95 ms
8,908 KB
testcase_09 AC 156 ms
12,188 KB
testcase_10 AC 171 ms
12,836 KB
testcase_11 AC 64 ms
6,768 KB
testcase_12 AC 193 ms
14,184 KB
testcase_13 AC 190 ms
14,068 KB
testcase_14 AC 188 ms
14,056 KB
testcase_15 AC 196 ms
14,116 KB
testcase_16 AC 213 ms
14,092 KB
testcase_17 AC 23 ms
6,208 KB
testcase_18 AC 181 ms
18,508 KB
testcase_19 AC 25 ms
6,276 KB
testcase_20 AC 27 ms
6,144 KB
testcase_21 AC 39 ms
6,220 KB
testcase_22 AC 39 ms
6,144 KB
testcase_23 AC 38 ms
6,232 KB
testcase_24 AC 38 ms
6,212 KB
testcase_25 AC 38 ms
6,272 KB
testcase_26 AC 37 ms
6,116 KB
testcase_27 AC 44 ms
6,124 KB
testcase_28 AC 44 ms
6,280 KB
testcase_29 AC 43 ms
6,240 KB
testcase_30 AC 43 ms
6,240 KB
testcase_31 AC 42 ms
6,176 KB
testcase_32 AC 43 ms
6,112 KB
testcase_33 AC 42 ms
6,120 KB
testcase_34 AC 43 ms
6,268 KB
testcase_35 AC 43 ms
6,236 KB
testcase_36 AC 42 ms
6,176 KB
testcase_37 AC 3 ms
4,608 KB
testcase_38 AC 27 ms
6,172 KB
testcase_39 AC 102 ms
12,616 KB
testcase_40 AC 101 ms
12,512 KB
権限があれば一括ダウンロードができます

ソースコード

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++) {
        if(table.count(A[i])) {
            sub += A[i] * table[A[i]];
        } else {
            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;
            table[A[i]] = modsum;
        }
    }
    ll res = sum * N - sub;
    cout << res << endl;
}
0