結果
| 問題 |
No.2940 Sigma Sigma Div Floor Problem
|
| コンテスト | |
| ユーザー |
SnowBeenDiding
|
| 提出日時 | 2024-10-18 22:56:26 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,380 bytes |
| コンパイル時間 | 5,383 ms |
| コンパイル使用メモリ | 312,652 KB |
| 実行使用メモリ | 29,984 KB |
| 最終ジャッジ日時 | 2024-10-18 22:57:18 |
| 合計ジャッジ時間 | 13,423 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 14 TLE * 1 -- * 15 |
ソースコード
#include <atcoder/all>
#include <bits/stdc++.h>
#define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
using namespace atcoder;
using namespace std;
typedef long long ll;
template <class T, class S = T> struct AllPairOperationSum {
// https://shakayami.hatenablog.com/entry/2021/01/01/044946
// Σ op(a[i], a[j]) (i < j)
ll n;
vector<T> a;
AllPairOperationSum() {}
AllPairOperationSum(vector<T> a) : a(a), n(a.size()) {}
T floor() {
// floor(A / B)
// O(N √maxA log maxA)
T maxa = *max_element(a.begin(), a.end());
T sqrtmaxa = sqrt(maxa);
vector<T> v(sqrtmaxa, 0);
fenwick_tree<T> ft(maxa + 1);
T ret = 0;
rep(i, 0, n) {
if (a[i] < sqrtmaxa) {
ret += v[a[i]];
} else {
for (T k = 0; k < maxa + 1; k += a[i]) {
ret += (k / a[i]) * ft.sum(k, std::min(k + a[i], maxa + 1));
}
}
ft.add(a[i], 1);
for (T j = 1; j < sqrtmaxa; j++) {
v[j] += a[i] / j;
}
}
return ret;
}
};
int main() {
ll n;
cin >> n;
vector<ll> a(n);
rep(i, 0, n) a[i] = i + 1;
reverse(a.begin(), a.end());
AllPairOperationSum<ll> op(a);
ll ans = op.floor() + n;
ans %= 998244353;
cout << ans << endl;
}
SnowBeenDiding