結果

問題 No.1233 割り切れない気持ち
ユーザー ninoinuininoinui
提出日時 2020-09-19 08:38:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 112 ms / 3,153 ms
コード長 1,830 bytes
コンパイル時間 2,144 ms
コンパイル使用メモリ 201,804 KB
実行使用メモリ 5,604 KB
最終ジャッジ日時 2023-09-05 09:28:55
合計ジャッジ時間 10,123 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
4,556 KB
testcase_01 AC 87 ms
4,600 KB
testcase_02 AC 88 ms
4,604 KB
testcase_03 AC 88 ms
4,552 KB
testcase_04 AC 87 ms
4,596 KB
testcase_05 AC 88 ms
4,676 KB
testcase_06 AC 87 ms
4,596 KB
testcase_07 AC 93 ms
4,860 KB
testcase_08 AC 97 ms
4,876 KB
testcase_09 AC 107 ms
5,080 KB
testcase_10 AC 108 ms
5,344 KB
testcase_11 AC 93 ms
4,868 KB
testcase_12 AC 111 ms
5,392 KB
testcase_13 AC 112 ms
5,368 KB
testcase_14 AC 112 ms
5,376 KB
testcase_15 AC 112 ms
5,604 KB
testcase_16 AC 112 ms
5,356 KB
testcase_17 AC 106 ms
5,564 KB
testcase_18 AC 108 ms
5,340 KB
testcase_19 AC 108 ms
5,372 KB
testcase_20 AC 106 ms
5,444 KB
testcase_21 AC 108 ms
5,348 KB
testcase_22 AC 109 ms
5,344 KB
testcase_23 AC 108 ms
5,372 KB
testcase_24 AC 108 ms
5,344 KB
testcase_25 AC 108 ms
5,404 KB
testcase_26 AC 107 ms
5,604 KB
testcase_27 AC 109 ms
5,344 KB
testcase_28 AC 109 ms
5,392 KB
testcase_29 AC 108 ms
5,388 KB
testcase_30 AC 109 ms
5,440 KB
testcase_31 AC 109 ms
5,396 KB
testcase_32 AC 108 ms
5,348 KB
testcase_33 AC 108 ms
5,440 KB
testcase_34 AC 109 ms
5,344 KB
testcase_35 AC 108 ms
5,400 KB
testcase_36 AC 108 ms
5,560 KB
testcase_37 AC 88 ms
4,672 KB
testcase_38 AC 106 ms
5,348 KB
testcase_39 AC 109 ms
5,380 KB
testcase_40 AC 107 ms
5,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

template<typename T, typename U> void cmax(T &a, U b) { if (a < b) a = b; }
template<typename T, typename U> void cmin(T &a, U b) { if (a > b) a = b; }

template<typename T> class FenwickTree {
  int N, M;
  vector<T> B;
public:
  FenwickTree(int n) : N(n + 1), M(1), B(N, 0) {
    while (M * 2 <= N) M *= 2;
  }
  FenwickTree(const vector<T> &v) : N((int) v.size() + 1), M(1), B(N, 0) {
    for (int i = 0; i < N - 1; i++) add(i, v.at(i));
    while (M * 2 <= N) M *= 2;
  }
  void add(int i, T x) {
    i++;
    while (i < N) B.at(i) += x, i += i & -i;
  }
  void add(int l, int r, T x) {
    add(l, x);
    add(r + 1 , -x);
  }
  T sum(int i) {
    i++;
    T ret = 0;
    while (i > 0) ret += B.at(i), i -= i & -i;
    return ret;
  }
  T sum(int l, int r) {
    return sum(r) - sum(l - 1);
  }
  T at(int i) {
    return sum(i) - sum(i - 1);
  }
  int lower_bound(T w) {
    if (w <= 0) return 0;
    int x = 0;
    for (int k = M; k > 0; k /= 2) {
      if (x + k <= N - 1 && B.at(x + k) < w) {
        w -= B.at(x + k);
        x += k;
      }
    }
    return x;
  }
  int upper_bound(T w) {
    if (w < 0) return 0;
    int x = 0;
    for (int k = M; k > 0; k /= 2) {
      if (x + k <= N - 1 && B.at(x + k) <= w) {
        w -= B.at(x + k);
        x += k;
      }
    }
    return x;
  }
};

signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);

  int M = 2e5 + 1;
  FenwickTree<int> FT(M * 2);
  for (auto a : A) FT.add(a, 1);

  long tmp = 0;
  for (int i = 1; i < M; i++) {
    for (int j = i; j < M; j += i) {
      tmp += (long) FT.at(i) * FT.sum(j, j + i - 1) * j;
    }
  }

  long acc = accumulate(A.begin(), A.end(), 0L);
  cout << acc * N - tmp << "\n";
}
0