結果
問題 | No.1233 割り切れない気持ち |
ユーザー |
![]() |
提出日時 | 2024-05-02 11:09:23 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 888 bytes |
コンパイル時間 | 1,526 ms |
コンパイル使用メモリ | 167,508 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-23 00:28:20 |
合計ジャッジ時間 | 22,875 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 38 WA * 1 |
ソースコード
#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 = 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; }