QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#111919#1875. NeinlingchenWA 2ms3480kbC++141.0kb2023-06-09 10:10:192023-06-09 10:10:23

Judging History

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

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

answer

#include<bits/stdc++.h>
using namespace std;

struct node { int l,r,x; };

node a[500100];
long long s[1000100],sum;
long long f[1000100];
int stk[1000100],top;
long long ans=-1e18;

double slope(int a, int b) { return 1.0*(f[a]-f[b])/(s[a]-s[b]); }
int main()
{
    int n;

    cin>>n;
    for(int i=1; i<=n; i++)
    {
        scanf("%d%d%d", &a[i].l, &a[i].r, &a[i].x);
        s[i]=a[i].l; s[i+n]=a[i].r;
    }

    s[n*2+1]=1;
    sort(s+1, s+1+n*2+1);
    sum=unique(s+1, s+1+n*2+1)-s-1;
    for(int i=1; i<=n; i++)
    {
        int l=lower_bound(s+1, s+1+sum, a[i].l)-s;
        int r=lower_bound(s+1, s+1+sum, a[i].r)-s;
        f[l]+=a[i].x*2; f[r]+=a[i].x*2; f[0]-=a[i].x*2;
    }

    for(int i=1; i<=sum; i++) f[i]+=f[i-1];
    for(int i=1; i<=sum; i++)
    {
        while(top>1&&slope(stk[top-1], stk[top])<slope(stk[top-1], i)) top--;
        stk[++top]=i;
        while(top>1&&slope(stk[top-1], stk[top])<4*s[i]) top--;
        ans=max(ans, f[i]+f[stk[top]]-s[i]*s[stk[top]]*4);
    }
    cout<<ans;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 3480kb

input:

1 1

output:

0

result:

wrong answer expected '2', found '0'