結果

問題 No.1233 割り切れない気持ち
ユーザー vjudge1vjudge1
提出日時 2024-05-02 11:05:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 817 bytes
コンパイル時間 1,616 ms
コンパイル使用メモリ 166,096 KB
実行使用メモリ 6,784 KB
最終ジャッジ日時 2024-05-02 11:05:23
合計ジャッジ時間 9,442 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
5,248 KB
testcase_01 AC 137 ms
5,376 KB
testcase_02 AC 136 ms
5,376 KB
testcase_03 AC 137 ms
5,376 KB
testcase_04 AC 137 ms
5,376 KB
testcase_05 AC 137 ms
5,376 KB
testcase_06 AC 137 ms
5,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 148 ms
5,376 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 149 ms
5,376 KB
testcase_21 AC 150 ms
5,376 KB
testcase_22 AC 151 ms
5,376 KB
testcase_23 AC 152 ms
5,376 KB
testcase_24 AC 153 ms
5,376 KB
testcase_25 AC 151 ms
5,376 KB
testcase_26 AC 151 ms
5,376 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 137 ms
5,376 KB
testcase_38 AC 150 ms
5,376 KB
testcase_39 WA -
testcase_40 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int cnt[200020], ci[200020], n, arr[200020];

void add(int x, int v) {
  int tmp = x * v;
  for(; x <= 200000; x += x & -x) {
    ci[x] += tmp;
  }
}

int queryi(int l) {
  int ans = 0;
  for(; l; l -= l & -l) {
    ans += ci[l];
  }
  return ans;
}

int cal(int l, int r, int c) {
  return c * (queryi(r) - queryi(l - 1));
}

signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  cin >> n;
  for(int i = 1; i <= n; i++) {
    cin >> arr[i];
    cnt[arr[i]]++;
  }
  long long ans = 0;
  for(int i = 1; i <= 20000; i++) {
    ans += n * cnt[i] * i;
    add(i, cnt[i]);
    for(int j = 1; j <= i; ) {
      int r = i / (i / j);
      ans -= cnt[i] * cal(j, r, i / j);
      j = r + 1;
    }
  }
  cout << ans << '\n';
  return 0;
}
0