結果
問題 |
No.1233 割り切れない気持ち
|
ユーザー |
![]() |
提出日時 | 2024-05-02 11:11:04 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2,921 ms / 3,153 ms |
コード長 | 894 bytes |
コンパイル時間 | 1,676 ms |
コンパイル使用メモリ | 168,100 KB |
実行使用メモリ | 6,656 KB |
最終ジャッジ日時 | 2024-11-23 00:30:41 |
合計ジャッジ時間 | 22,996 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 39 |
ソースコード
#include <bits/stdc++.h> using namespace std; int cnt[200020], n, arr[200020]; long long ci[200020]; void add(int x, int v) { long long tmp = 1ll * x * v; for(; x <= 200000; x += x & -x) { ci[x] += tmp; } } long long queryi(int l) { long long ans = 0; for(; l; l -= l & -l) { ans += ci[l]; } return ans; } long long cal(int l, int r, int c) { return 1ll * 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 <= 200000; i++) { if(!cnt[i]) { continue; } ans += 1ll * n * cnt[i] * i; add(i, cnt[i]); for(int j = 1; j <= i; ) { int r = i / (i / j); ans -= 1ll * cnt[i] * cal(j, r, i / j); j = r + 1; } } cout << ans << '\n'; return 0; }