제출 #94223

#제출 시각아이디문제언어결과실행 시간메모리
94223jhnah917Salesman (IOI09_salesman)C++14
0 / 100
694 ms66560 KiB
#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> p;

const int MAX_N = 1<<19;
struct SegTree {
	int seg[MAX_N*2-1];
	SegTree() {
		for(int i=0; i<MAX_N*2-1; i++) seg[i] = -1e9;
	}
	
	int query(int a, int b, int k=0, int l=0, int r=MAX_N){
    	if (b <= l || r <=a)return -1e9;
    	if (a<=l&&r<=b) return seg[k];
		return max(query(a,b,k*2+1,l,(l+r)/2), query(a,b,k*2+2,(l+r)/2,r));
	}
	
	void update(int k, int v) {
    	k += MAX_N-1;
    	seg[k] = v;
		while (k > 0) {
			k=(k-1)/2;
			seg[k]=max(seg[k*2+1],seg[k*2+2]);
		}
	}
};

SegTree s1, s2;
vector<p> v[505050];
vector<int> dpl[505050], dpr[505050];
int n, u, s, d;

void update(int i, int j){
	s1.update(v[i][j].first, max(dpl[i][j], dpr[i][j]) + d * v[i][j].first);
	s2.update(v[i][j].first, max(dpl[i][j], dpr[i][j]) - u * v[i][j].first);
}

int get1(int i, int j){
	int ret = -1e9;
	if(j-1 >= 0) ret = dpl[i][j-1] - d * (v[i][j].first - v[i][j-1].first) + v[i][j].second;
	int t1 = s1.query(0, v[i][j].first) - d*v[i][j].first + v[i][j].second;
	int t2 = s2.query(v[i][j].first, 500001) + u*v[i][j].first + v[i][j].second;
	
	return max({ret, t1, t2});
}

int get2(int i, int j){
	int ret = -1e9;
	if(j+1 < v[i].size()) ret = dpr[i][j+1] - u * (v[i][j+1].first - v[i][j].first) + v[i][j].second;
	int t1 = s1.query(0, v[i][j].first) - d*v[i][j].first + v[i][j].second;
	int t2 = s2.query(v[i][j].first, 500001) + u*v[i][j].first + v[i][j].second;
	
	return max({ret, t1, t2});
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n >> u >> d >> s;
	
	for(int i=0; i<n; i++){
		int a, b, c; cin >> a >> b >> c;
		v[a].push_back({b, c});
	}
	v[0].push_back({s, 0});
	v[500001].push_back({s, 0});
	for(int i=0; i<=500001; i++){
		dpl[i].resize(v[i].size()), dpr[i].resize(v[i].size());
		sort(v[i].begin(), v[i].end());
	}
	
	dpl[0][0] = dpr[0][0] = 0;
	update(0, 0);
	for(int i=1; i<=n+1; i++){
		for(int j=0; j<v[i].size(); j++){
			dpl[i][j] = get1(i, j);
			dpr[i][j] = get2(i, j);
		}
		for(int j=0; j<v[i].size(); j++){
			update(i, j);
		}
	}
	
	cout << max(dpl[n+1][0], dpr[n+1][0]);
}

컴파일 시 표준 에러 (stderr) 메시지

salesman.cpp: In function 'int get2(int, int)':
salesman.cpp:50:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(j+1 < v[i].size()) ret = dpr[i][j+1] - u * (v[i][j+1].first - v[i][j].first) + v[i][j].second;
     ~~~~^~~~~~~~~~~~~
salesman.cpp: In function 'int main()':
salesman.cpp:75:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0; j<v[i].size(); j++){
                ~^~~~~~~~~~~~
salesman.cpp:79:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0; j<v[i].size(); j++){
                ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...