結果
問題 | No.885 アマリクエリ |
ユーザー | kusaf_ |
提出日時 | 2024-10-11 14:45:34 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 465 ms / 2,000 ms |
コード長 | 608 bytes |
コンパイル時間 | 3,366 ms |
コンパイル使用メモリ | 252,688 KB |
実行使用メモリ | 15,488 KB |
最終ジャッジ日時 | 2024-10-11 14:45:40 |
合計ジャッジ時間 | 6,070 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll N; cin >> N; map<ll, ll> m; ll ans = 0; for(ll i = 0; i < N; i++) { ll a; cin >> a; m[a]++; ans += a; } ll Q; cin >> Q; while(Q--) { ll x; cin >> x; auto it = m.lower_bound(x); map<ll, ll> add; for(auto i = it; i != m.end(); i++) { auto [v, c] = *i; add[v % x] += c; ans -= (v - v % x) * c; } m.erase(it, m.end()); for(auto &[v, c] : add) { m[v] += c; } cout << ans << "\n"; } }