Submission #71023

#TimeUsernameProblemLanguageResultExecution timeMemory
71023WA_TLESalesman (IOI09_salesman)C++14
100 / 100
632 ms32076 KiB
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*
cout<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1000000009;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
/*
インラインDP!!!
2^あは
 524288
1048576
*/
llint seg[1048576];//例の超絶テクニックをする
//%2==0 segue %2==1 segst
int main(void){
	llint i,j,n,U,D,S,bas;
	scanf("%lld %lld %lld %lld",&n,&D,&U,&S);
	for(i=0;i<(1<<20);i++){seg[i]=-big;}
	//segue 自分より上側からの最適を得る 値=元+D*距離
	//segst 自分より下側からの最適を得る 値=元-U*距離
	bas=(1<<19)+S;
	while(bas>1){
		if(bas%2==0){seg[bas]=D*S;}
		else{seg[bas]=-U*S;}
		bas/=2;
	}
	vector<tuple<int,int,int>>fair(n+1);
	for(i=0;i<n;i++){
		int aa,bb,cc;
		scanf("%d %d %d",&aa,&bb,&cc);
		fair[i]=tie(aa,bb,cc);
	}
	fair[n]=mt(869120,1001,1001);
	SO(fair);
	vector<tuple<int,int,int>>sonohi;
	for(i=0;i<=n;i++){
		if(sonohi.size()>0&&get<0>(sonohi[0])!=get<0>(fair[i])){
			//sonohiを処理する
			//上から順と下から順の二つを考えてクエリにこたえ、合成
			int m=sonohi.size();
			vector<llint>uri(m,-big);//売上
			vector<int>bsy(m);
			vector<int>mon(m);//ああああああ
			for(j=0;j<m;j++){
				//上から下
				int dco=get<1>(sonohi[j]);
				bsy[j]=dco;
				mon[j]=get<2>(sonohi[j]);
				bas=(1<<19)+dco;
				while(bas>1){
					llint ues=seg[bas-1]-D*dco;
					llint sts=seg[bas+1]+U*dco;
					if(bas%2==1){maxeq(uri[j],ues);}
					else{maxeq(uri[j],sts);}
					bas/=2;
				}
				uri[j]+=mon[j];
			}
			//どうにかして更新する
			auto uli=uri;
			for(j=1;j<m;j++){maxeq(uri[j],uri[j-1]+mon[j]-(bsy[j]-bsy[j-1])*D);}
			for(j=m-2;j>=0;j--){maxeq(uli[j],uli[j+1]+mon[j]-(bsy[j+1]-bsy[j])*U);}
			for(j=0;j<m;j++){maxeq(uri[j],uli[j]);}
			//更新を行う
			for(j=0;j<m;j++){
				int dco=bsy[j];
				bas=(1<<19)+dco;
				llint ues=uri[j]+D*dco;
				llint sts=uri[j]-U*dco;
				while(bas>1){
					if(bas%2==0){maxeq(seg[bas],ues);}
					else{maxeq(seg[bas],sts);}
					bas/=2;
				}
			}
			sonohi.clear();
		}
		sonohi.pub(fair[i]);
	}
	llint ans=0;
	bas=(1<<19)+S;
	while(bas>1){
		llint ues=seg[bas-1]-D*S;
		llint sts=seg[bas+1]+U*S;
		if(bas%2==1){maxeq(ans,ues);}
		else{maxeq(ans,sts);}
		bas/=2;
	}
	printf("%lld\n",ans);
	return 0;
}

Compilation message (stderr)

salesman.cpp: In function 'int main()':
salesman.cpp:63:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld %lld %lld %lld",&n,&D,&U,&S);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
salesman.cpp:76:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d",&aa,&bb,&cc);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...