Submission #49040

# Submission time Handle Problem Language Result Execution time Memory
49040 2018-05-21T13:19:15 Z polyfish Wiring (IOI17_wiring) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
 
#define debug(x) cerr << #x << " = " << x << '\n';
#define BP() cerr << "OK!\n";
#define PR(A, n) cerr << #A << " = "; for (int _=1; _<=n; ++_) cerr << A[_] << ' '; cerr << '\n';
#define PR0(A, n) cerr << #A << " = "; for (int _=0; _<n; ++_) cerr << A[_] << ' '; cerr << '\n';

const int maxn = 200002;
const int64_t inf = 1e18;

struct rmq {
	int n;
	int64_t container[maxn*4];

	void init(int _n) {
		n = _n;
		for (int i=0; i<=4*n; ++i)
			container[i] = inf;
	}

	void update(int pos, int64_t val, int l, int r, int id) {
		if (pos<l || pos>r)
			return;
		if (l==pos && pos==r) {
			container[id] = val;
			return;
		}
		int mid = (l+r)/2;
		update(pos, val, l, mid, id*2);
		update(pos, val, mid+1, r, id*2+1);
		container[id] = min(container[id*2], container[id*2+1]);
	}

	int64_t get(int u, int v, int l, int r, int id) {
		if (v<l || u>r)
			return inf;
		if (u<=l && r<=v)
			return container[id];
		int mid = (l+r)/2;
		return min(get(u, v, l, mid, id*2),
					get(u, v, mid+1, r, id*2+1));
	}

	void update(int pos, int val) {
		update(pos, val, 1, n, 1);
	}

	int64_t get(int u, int v) {
		if (u>v)
			return inf;
		return get(u, v, 1, n, 1);
	}
} T1, T2;

int m, n, L[maxn], R[maxn], pos[maxn];
pair<int, int> a[maxn];
int64_t f[maxn], ps[2][maxn];

void enter(vector<int> r, vector<int> b) {
	m = r.size(); n = b.size();
	for (int i=1; i<=m; ++i) {
		a[i] = make_pair(r[i-1], 0);
	}
	for (int i=1; i<=n; ++i) {
		a[m+i] = make_pair(b[i-1], 1);
	}
}

void init() {
	n = m+n;
	sort(a+1, a+n+1);
	int cnt = 0;
	for (int i=1; i<=n+1; ++i) {
		if (i==1 || i==n+1 || a[i].second!=a[i-1].second) {
			++cnt;
			L[cnt] = i;
			R[cnt-1] = i-1;
		}
		pos[i] = cnt;
	}
	for (int i=1; i<=n; ++i) {
		for (int j=0; j<2; ++j)
			ps[j][i] = ps[j][i-1] + (a[i].second==j ? a[i].first : 0);
	}
	T1.init(n);
	T2.init(n);
}

long long min_total_lenght(vector<int> red, vector<int> blue) {
	// freopen("wiring.inp", "r", stdin);
	// freopen("wiring.out", "w", stdout);
	// ios::sync_with_stdio(0); cin.tie(0);
	enter(red, blue);
	init();
	int64_t extra1 = 1LL*(-1+R[pos[1]])*a[L[pos[1]+1]].first;
	int64_t extra2 = -1LL*(1-R[pos[1]])*a[R[pos[1]]].first;
	T1.update(1, extra1);
	T2.update(1, extra2);
	for (int i=1; i<=n; ++i) {
		f[i] = inf;
		if (pos[i]==1) {
			continue;
		}
		int l = L[pos[i]-1], r = R[pos[i]-1];
		int w = a[i].second, b = w^1;
		f[i] = T1.get(l, r-i+L[pos[i]]) + (-i + L[pos[i]])*a[L[pos[i]]].first
				+ ps[w][i] - ps[b][i];
		f[i] = min(f[i], T2.get(max(l, r-i+L[pos[i]]), r) - (i-L[pos[i]])*a[R[pos[i]-1]].first
				 + ps[w][i] - ps[b][i]);
		int64_t extra1 = 1LL*(-i+R[pos[i]])*a[L[pos[i]+1]].first;
		int64_t extra2 = -1LL*(i-R[pos[i]])*a[R[pos[i]]].first;
		T1.update(i, min(f[i], f[i-1])+ps[w][i-1]-ps[b][i-1] + extra1);
		T2.update(i, min(f[i], f[i-1])+ps[w][i-1]-ps[b][i-1] + extra2);
	}
	return f[n];
}

Compilation message

/tmp/cc0xSpqG.o: In function `main':
grader.cpp:(.text.startup+0x23b): undefined reference to `min_total_length(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status