結果

問題 No.1233 割り切れない気持ち
ユーザー vjudge1
提出日時 2024-05-02 11:00:57
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 760 bytes
コンパイル時間 1,535 ms
コンパイル使用メモリ 167,504 KB
実行使用メモリ 8,264 KB
最終ジャッジ日時 2024-11-23 00:11:46
合計ジャッジ時間 4,838 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 4 WA * 35
権限があれば一括ダウンロードができます

ソースコード

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() {
  cin >> n;
  for(int i = 1; i <= n; i++) {
    cin >> arr[i];
    cnt[arr[i]]++;
  }
  long long ans = 0;
  for(int i = 1; i <= 10; 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