結果

問題 No.885 アマリクエリ
ユーザー tarattata1tarattata1
提出日時 2019-09-14 06:18:47
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,401 bytes
コンパイル時間 826 ms
コンパイル使用メモリ 82,288 KB
実行使用メモリ 25,624 KB
最終ジャッジ日時 2023-09-18 13:26:01
合計ジャッジ時間 7,622 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);

    set<pair<int,int> > z;
    ll sum=0;
    int i;
    for(i=0; i<n; i++) {
        int tmp;
        scanf("%d", &tmp);
        z.insert(make_pair(tmp,i));
        sum+=tmp;
    }

    int Q;
    scanf("%d", &Q);
    for(i=0; i<Q; i++) {
        set<pair<int,int> > del;
        set<pair<int,int> > add;
        int tmp;
        scanf("%d", &tmp);
        auto it=z.lower_bound(make_pair(tmp,0));
        for(; it!=z.end(); ++it) {
            del.insert(*it);
            add.insert(make_pair(it->first %tmp, it->second));
            sum -= (it->first - it->first %tmp);
        }
        printf("%lld\n", sum);

        it=del.begin();
        for(; it!=del.end(); ++it) {
            z.erase(*it);
        }
        it=add.begin();
        for(; it!=add.end(); ++it) {
            z.insert(*it);
        }
    }
 

    return 0;
}
0