結果

問題 No.885 アマリクエリ
コンテスト
ユーザー kotatsugame
提出日時 2019-09-16 19:51:37
言語 C++14
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 255 ms / 2,000 ms
+ 105µs
コード長 738 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 563 ms
コンパイル使用メモリ 100,124 KB
実行使用メモリ 9,840 KB
最終ジャッジ日時 2026-10-30 20:40:12
合計ジャッジ時間 4,882 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge7_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    8 | main()
      | ^~~~

ソースコード

diff #
raw source code

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int N;
int A[1<<17],X[1<<17];
long sum[1<<17];
main()
{
	cin>>N;
	for(int i=0;i<N;i++)cin>>A[i];
	int Q;cin>>Q;
	for(int i=0;i<Q;i++)cin>>X[i];
	vector<pair<int,int> >Y;
	Y.push_back(make_pair(X[0],0));
	for(int i=1;i<Q;i++)
	{
		if(X[i]<Y.back().first)
		{
			Y.push_back(make_pair(X[i],i));
		}
	}
	sort(Y.begin(),Y.end());
	long SA=0;
	for(int i=0;i<N;i++)
	{
		SA+=A[i];
		int now=A[i];
		while(true)
		{
			vector<pair<int,int> >::iterator it=
				upper_bound(Y.begin(),Y.end(),make_pair(now,Q));
			if(it==Y.begin())break;
			it--;
			sum[it->second]-=now-now%it->first;
			now%=it->first;
		}
	}
	for(int i=0;i<Q;i++)
	{
		cout<<(SA+=sum[i])<<endl;
	}
}
0