結果

問題 No.885 アマリクエリ
ユーザー kotatsugame
提出日時 2019-09-16 19:51:37
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 198 ms / 2,000 ms
コード長 738 bytes
コンパイル時間 742 ms
コンパイル使用メモリ 78,812 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-07 02:30:57
合計ジャッジ時間 3,681 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    8 | main()
      | ^~~~

ソースコード

diff #

#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