結果

問題 No.2698 Many Asakatsu
ユーザー kotatsugamekotatsugame
提出日時 2024-03-22 22:24:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 368 ms / 2,000 ms
コード長 1,493 bytes
コンパイル時間 722 ms
コンパイル使用メモリ 71,484 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-22 22:24:21
合計ジャッジ時間 6,172 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 3 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 3 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 4 ms
6,676 KB
testcase_12 AC 3 ms
6,676 KB
testcase_13 AC 4 ms
6,676 KB
testcase_14 AC 4 ms
6,676 KB
testcase_15 AC 3 ms
6,676 KB
testcase_16 AC 4 ms
6,676 KB
testcase_17 AC 4 ms
6,676 KB
testcase_18 AC 5 ms
6,676 KB
testcase_19 AC 20 ms
6,676 KB
testcase_20 AC 21 ms
6,676 KB
testcase_21 AC 20 ms
6,676 KB
testcase_22 AC 182 ms
6,676 KB
testcase_23 AC 200 ms
6,676 KB
testcase_24 AC 233 ms
6,676 KB
testcase_25 AC 184 ms
6,676 KB
testcase_26 AC 199 ms
6,676 KB
testcase_27 AC 207 ms
6,676 KB
testcase_28 AC 304 ms
6,676 KB
testcase_29 AC 41 ms
6,676 KB
testcase_30 AC 90 ms
6,676 KB
testcase_31 AC 368 ms
6,676 KB
testcase_32 AC 279 ms
6,676 KB
testcase_33 AC 19 ms
6,676 KB
testcase_34 AC 303 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<cassert>
using namespace std;
int N;
long M;
long A[1<<17],B[1<<17];
int Q;
long X;
int C[1<<17];
long s(long a,long b,long n)
{
	long ret=a*n;
	ret+=n*(n-1)/2*b;
	return ret;
}
long f(int id,long R)
{
	if(A[id]>=R)
	{
		return s(A[id],B[id],M)-R*M;
	}
	else if(A[id]+(M-1)*B[id]<=R)
	{
		return R*M-s(A[id],B[id],M);
	}
	//A[id]+k*B[id]<=R
	//k<=(R-A[id])/B[id]
	long k=(R-A[id])/B[id];
	assert(0<=k&&k<M-1);
	long ret=0;
	ret+=R*(k+1)-s(A[id],B[id],k+1);
	ret+=s(A[id]+(k+1)*B[id],B[id],M-k-1)-R*(M-k-1);
	return ret;
}
long g(int i,int j)
{
	assert(i<j);
	assert(A[i]!=A[j]||B[i]!=B[j]);
	long l=0,r=1e9;
	while(r-l>1)
	{
		long mid=(l+r)/2;
		if(f(j,mid)<f(i,mid))r=mid;
		else l=mid;
	}
	return r;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>N>>M;
	for(int i=0;i<N;i++)cin>>A[i]>>B[i];
	cin>>Q>>X;
	for(int i=0;i<N;i++)cin>>C[i];
	vector<int>P;
	P.push_back(0);
	for(int i=1;i<N;i++)
	{
		if(A[i-1]==A[i]&&B[i-1]==B[i])continue;
		while(P.size()>=2)
		{
			long a=g(P[P.size()-2],P[P.size()-1]);
			long b=g(P[P.size()-1],i);
			if(b<=a)P.pop_back();
			else break;
		}
		P.push_back(i);
	}
	int idx=0;
	for(int q=0;q<Q;q++)
	{
		assert(0<=idx&&idx<P.size());
		//cout<<X<<": ";for(int j=0;j<P.size();j++)cout<<f(P[j],X)<<", ";cout<<endl;
		long cur=f(P[idx],X);
		while(idx+1<N)
		{
			long tst=f(P[idx+1],X);
			if(cur>tst)cur=tst,idx++;
			else break;
		}
		cout<<P[idx]+1<<(q+1==Q?"\n":" ");
		X+=C[P[idx]];
	}
}
0