結果
問題 |
No.885 アマリクエリ
|
ユーザー |
![]() |
提出日時 | 2019-11-29 21:10:14 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 343 ms / 2,000 ms |
コード長 | 909 bytes |
コンパイル時間 | 1,933 ms |
コンパイル使用メモリ | 179,672 KB |
実行使用メモリ | 12,236 KB |
最終ジャッジ日時 | 2024-11-20 21:37:50 |
合計ジャッジ時間 | 4,270 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#include<bits/stdc++.h> using namespace std; typedef long long ll; signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); ll n; cin>>n; map<ll,ll> mp; ll sum = 0; for(ll i=0;i<n;i++){ ll a; cin>>a; sum += a; mp[a]++; } ll q; cin>>q; while(q--){ ll a; cin>>a; vector<ll> era; vector<ll> cnt; auto itr = mp.lower_bound(a); if(itr == mp.end()){ cout << sum << "\n"; continue; } while(itr != mp.end()){ era.push_back(itr->first); cnt.push_back(itr->second); itr++; } for(ll i=0;i<era.size();i++){ mp.erase(era[i]); mp[era[i]%a] += cnt[i]; sum += (era[i]%a - era[i]) * cnt[i]; } cout << sum << "\n"; } }