Mn Zn 求助
查看原帖
Mn Zn 求助
126582
Scintilla楼主2020/12/4 17:59
#include <bits/stdc++.h>
using namespace std;
#define il inline
#define re register
#define Rep(i, s, e) for (re int i = s; i <= e; ++i)
#define Dep(i, s, e) for (re int i = s; i >= e; --i)
#define file(a) freopen(#a".in", "r", stdin), freopen(#a".out", "w", stdout)
typedef long long ll;
typedef double db;
const int N = 300010;
const int INF = 0x3f3f3f3f;
il int read() {
    int x = 0; bool f = true; char c = getchar();
    while (c < '0' || c > '9') {if (c == '-') f = false; c = getchar();}
    while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
    return f ? x : -x;
}
ll n, s, t[N], f[N], st[N], sf[N], dp[N];
il ll X(int i) {return sf[i];}
il ll Y(int i) {return dp[i];}
int head = 1, tail = 1, Q[N];
int main() {
	n = read(), s = read();
	Rep(i, 1, n) {
		t[i] = read(), st[i] = st[i - 1] + t[i];
		f[i] = read(), sf[i] = sf[i - 1] + f[i];
	}
	Rep(i, 1, n) {
		int l = head, r = tail; ll k = s + st[i];
        while (l < r) {
            int mid = (l + r) >> 1;
            if ((Y(Q[mid + 1]) - Y(Q[mid])) < k * (X(Q[mid + 1]) - X(Q[mid]))) l = mid + 1;
            else r = mid;
        }
		dp[i] = dp[Q[l]] + st[i] * (sf[i] - sf[Q[l]]) + s * (sf[n] - sf[Q[l]]);
		while (head < tail && (Y(Q[tail]) - Y(Q[tail - 1])) * (X(i) - X(Q[tail])) >= (Y(i) - Y(Q[tail])) * (X(Q[tail]) - X(Q[tail - 1]))) --tail;
		Q[++tail] = i;
	}
	printf("%lld", dp[n]);
	return 0;
}

为什么把维护凸包比较时的的 >= 改成 > 就会 WA 掉呢?按理来说取等时应该是一条直线,不影响答案啊

萌新求助 qwq

2020/12/4 17:59
加载中...