結果
問題 |
No.3284 Picnic with Friends
|
ユーザー |
|
提出日時 | 2025-09-26 22:19:59 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,204 bytes |
コンパイル時間 | 4,200 ms |
コンパイル使用メモリ | 259,852 KB |
実行使用メモリ | 172,260 KB |
最終ジャッジ日時 | 2025-09-26 22:20:29 |
合計ジャッジ時間 | 20,547 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 15 WA * 10 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using isize = size_t; using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; using i128 = __int128_t; using u128 = __uint128_t; using f64 = long double; using p2 = pair<i64, i64>; using el = tuple<i64, i64, i64>; using mint = atcoder::modint998244353; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(18); _main(); } i64 pow(i64 x, i64 n) { i64 res = 1; i64 t = x; while (n > 0) { if (n & 1) res *= t; t *= t; n >>= 1; } return res; } i64 pow(i64 x, i64 n, i64 m) { i64 res = 1; i64 t = x % m; while (n > 0) { if (n & 1) res = res * t % m; t = t * t % m; n >>= 1; } return res; } void _main() { i64 n; cin >> n; vector<p2> s(n); for (i64 i = 0; i < n; i++) { cin >> s[i].first; s[i].second = i; } sort(s.begin(), s.end()); i64 q; cin >> q; vector<i64> v; i64 now = 0, sum = 0; for (;q--;) { i64 t, f; cin >> t >> f; if (now >= t) now += f, sum += f; else { v.push_back(sum); now = t + f; sum = f; } } if (sum > 0) v.push_back(sum); vector<i64> cnt(10000000, 0); vector<i64> cnts(10000000, 0); vector<p2> p; for (i64 x : v) { i64 b; for (i64 i = 1; true; i++) { if (x / i < i) { b = x / i; break; } if (i < cnt.size()) { cnt[i] += x / i; } else { p.push_back({i, x / i}); p.push_back({i + 1, -(x / i)}); } } for (i64 i = b; i >= 1; i--) { i64 l = x / (i + 1) + 1, r = x / i + 1; if (l < cnt.size()) cnts[l] += i; else p.push_back({l, i}); if (r < cnt.size()) cnts[r] -= i; else p.push_back({r, -i}); } } for (i64 i = 1; i < cnts.size(); i++) cnts[i] += cnts[i - 1]; sort(p.begin(), p.end()); i64 idx = 0; i64 ss = 0; vector<i64> ans(n, 0); for (auto [x, i] : s) { while (idx < p.size() && p[idx].first <= x) { ss += p[idx].second; idx++; } ans[i] = ss; if (x < cnt.size()) ans[i] += cnt[x] + cnts[x]; } for (i64 x : ans) cout << x << "\n"; }