結果

問題 No.885 アマリクエリ
ユーザー kotamanegikotamanegi
提出日時 2019-09-13 22:03:19
言語 C++17(clang)
(14.0.0 + boost 1.83.0)
結果
AC  
実行時間 255 ms / 2,000 ms
コード長 1,958 bytes
コンパイル時間 1,249 ms
コンパイル使用メモリ 115,156 KB
実行使用メモリ 10,912 KB
最終ジャッジ日時 2023-08-20 12:55:44
合計ジャッジ時間 4,251 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 255 ms
4,832 KB
testcase_01 AC 154 ms
4,852 KB
testcase_02 AC 197 ms
10,912 KB
testcase_03 AC 196 ms
9,492 KB
testcase_04 AC 144 ms
4,844 KB
testcase_05 AC 134 ms
4,896 KB
testcase_06 AC 121 ms
4,752 KB
testcase_07 AC 15 ms
4,380 KB
testcase_08 AC 154 ms
8,924 KB
testcase_09 AC 160 ms
4,800 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 3 ms
4,384 KB
testcase_14 AC 3 ms
4,384 KB
testcase_15 AC 4 ms
4,384 KB
testcase_16 AC 3 ms
4,388 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 4 ms
4,384 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define MOD 998244353LL
#define seg_size 262144*4
#define REP(a,b) for(long long a = 0;a < b;++a)
long long ans[1000000] = {};
long long encoding(long long a, long long b) {
	return -a * 1e6 + b;
}
pair<long long, long long> decoding(long long now) {
	long long hoge = -now;
	//a * 1e6 - b
	long long tmp = hoge / 1e6;
	tmp++;
	return make_pair(tmp, tmp * 1e6 - hoge);
}
int main(){
	iostream::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	set<long long> queries;
	vector<long long> A;
	REP(i, n) {
		long long b;
		cin >> b;
		A.push_back(b);
	}
	int query;
	cin >> query;
	int back;
	cin >> back;
	queries.insert(encoding(back, 1));
	REP(i, query - 1) {
		int a;
		cin >> a;
		if (back > a) {
			back = a;
			queries.insert(encoding(back,i+2));
		}
	}
	for (int i = 0; i < n; ++i) {
		ans[0] += A[i];
		long long now = A[i];
		while (true) {
			auto q = queries.lower_bound(-(now) * (1e6));
			if (q == queries.end()) break;
			pair<long long, long long> geko = decoding(*q);
			long long next = now % geko.first;
			ans[geko.second] -= now - next;
			now = next;
		}
	}
	for (int i = 1; i <= query; ++i) {
		ans[i] += ans[i - 1];
		cout << ans[i] << endl;
	}
}
0