QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#33283#1880. Nikanor Loves GamescdwWA 5ms14012kbC++201.5kb2022-05-31 09:33:192022-05-31 09:33:20

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-31 09:33:20]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:14012kb
  • [2022-05-31 09:33:19]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct point {
    ll x, y;
};
inline point operator - (const point &a, const point &b) {
    return {a.x - b.x, a.y - b.y};
}
inline __int128 operator ^ (const point &a, const point &b) {
    return (__int128)a.x * b.y - (__int128)a.y * b.x;
}
int x[1000010];
ll y[1000010];
int a[1000010], b[1000010], w[1000010], n;
point sta[1000010];
int top;
int main() {
    scanf("%d", &n);
    int cnt = 0;
    x[++cnt] = 1;
    for (int i = 1; i <= n; i++) {
        scanf("%d%d%d", a + i, b + i, w + i);
        x[++cnt] = a[i];
        x[++cnt] = b[i];
    }
    sort(x + 1, x + 1 + cnt);
    cnt = unique(x + 1, x + 1 + cnt) - x - 1;
    for (int i = 1; i <= n; i++) {
        a[i] = lower_bound(x + 1, x + 1 + cnt, a[i]) - x;
        b[i] = lower_bound(x + 1, x + 1 + cnt, b[i]) - x;
        y[1] -= w[i];
        y[a[i]] += w[i];
        y[b[i]] += w[i];
    }
    for (int i = 2; i <= cnt; i++) y[i] += y[i - 1];
    for (int i = 1; i <= cnt; i++) {
        point cur{x[i], y[i]};
        while (top >= 2 && ((cur - sta[top]) ^ (sta[top] - sta[top - 1])) <= 0) top--;
        sta[++top] = cur;
    }
    ll ans = -1e18;
    for (int i = 1, j = top; i <= top; i++) {
        while (j >= 2 && sta[j - 1].y - 2 * sta[j - 1].x * sta[i].x >= sta[j].y - 2 * sta[j].x * sta[i].x) j--;
        ans = max(ans, sta[i].y + sta[j].y - 2 * sta[i].x * sta[j].x);
    }
    printf("%lld\n", ans * 2);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 5ms
memory: 14012kb

input:

2
1 4 15
3 5 10

output:

10

result:

wrong answer 1st numbers differ - expected: '2.5000000', found: '10.0000000', error = '3.0000000'