QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#721407#1880. Nikanor Loves GamesNt_YesterWA 1ms9776kbC++201.4kb2024-11-07 16:03:022024-11-07 16:03:08

Judging History

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

  • [2024-11-07 16:03:08]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:9776kb
  • [2024-11-07 16:03:02]
  • 提交

answer

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>

#define N 1000005
#define LL long long
#define INF 0x3f3f3f3f3f3f3f3f

inline int R() {
    int x=0; bool f=0; char c=getchar();
    while (!isdigit(c)) f|=(c=='-'),c=getchar();
    while (isdigit(c)) x=x*10+c-'0',c=getchar();
    return f?-x:x;
}

template<typename T>
void W(T x,int op=0) {
    if (x<0) return putchar('-'),W(-x,op);
    if (x>9) W(x/10); putchar(x%10+'0');
    if (op) putchar(op==1?' ':'\n');
}

using namespace std;
int n,a[N],b[N],x[N],k,c[N]; LL ans=-INF,sum[N];

void sol(int l,int r,int L,int R) {
    if (l>r) return;
    int mid=(l+r>>1),pos=0; LL res=-INF;
    for (int i=L;i<=R;i++)
        if (sum[i]+sum[mid]-4ll*c[i]*c[mid]>res)
            res=sum[i]+sum[mid]-4ll*c[i]*c[mid],pos=i;
    ans=max(ans,res);
    sol(l,mid-1,pos,R); sol(mid+1,r,L,pos);
}

int main() {
    // freopen("b.in","r",stdin);
    n=R();
    for (int i=1;i<=n;i++)
        c[++k]=a[i]=R(),c[++k]=b[i]=R(),x[i]=R();
    c[++k]=1; LL Sum=0;
    sort(c+1,c+k+1); k=unique(c+1,c+k+1)-c-1;
    for (int i=1;i<=n;i++) {
        a[i]=lower_bound(c+1,c+k+1,a[i])-c;
        b[i]=lower_bound(c+1,c+k+1,b[i])-c;
        sum[a[i]]+=x[i],sum[b[i]]+=x[i],Sum+=2*x[i];
    }
    for (int i=1;i<=k;i++) sum[i]+=sum[i-1];
    for (int i=1;i<=k;i++) sum[i]=2*sum[i]-Sum;
    sol(1,k,1,k); W(ans,2);
    // printf("%.7lf\n",ans/4.0);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 9776kb

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'