QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#564167#7905. Ticket to Riderqoi031WA 2ms1648kbC++201.6kb2024-09-14 20:59:562024-09-14 20:59:57

Judging History

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

  • [2024-09-14 20:59:57]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:1648kb
  • [2024-09-14 20:59:56]
  • 提交

answer

#include<stdio.h>
#include<algorithm>
#include<numeric>
#include<vector>
typedef long long ll;
struct seg {
    int l,r,v;
};
seg a[10005];
ll dp[10005];
int fa[10005],nxt[10005];
ll del[10005];
int getf(const int &x) {
    return fa[x]==x?x:fa[x]=getf(fa[x]);
}
inline void modify(const int &n,int x,const int &y) {
    del[x=getf(x)]+=y;
    while(del[x]>=0&&nxt[x]<=n) {
        fa[nxt[x]]=x;
        nxt[x]=nxt[nxt[x]];
    }
}
inline void append(const int &x,const ll &y) {
    const int &_x(getf(x-1));
    if(y>del[_x]) {
        del[_x]-=y,del[x]=y;
    }
    else {
        fa[x]=_x,nxt[_x]=nxt[x];
    }
}
inline void solve() {
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++) {
        scanf("%d%d%d",&a[i].l,&a[i].r,&a[i].v);
    }
    std::sort(a+1,a+m+1,[&](const seg &x,const seg &y)->bool {
        return x.r<y.r;
    });
    std::fill(dp,dp+n+1,0);
    for(int d=0,p=1;d<=n;d++) {
        std::iota(fa,fa+(n-d)+1,0);
        std::iota(nxt,nxt+(n-d)+1,1);
        std::fill(del,del+(n-d)+1,0);
        while(p<=m&&a[p].r<=d) {
            ++p;
        }
        for(int i=1,j=p;i<=n-d;i++) {
            while(j<=m&&a[j].r==i+d) {
                if(a[j].l>=d) {
                    modify(i-1,a[j].l-d,a[j].v);
                }
                ++j;
            }
            dp[i]=std::max(dp[i],del[getf(i-1)]);
            append(i,dp[i]);
        }
    }
    for(int i=1;i<=n;i++) {
        printf("%lld%c",dp[i],i==n?'\n':' ');
    }
}
int main() {
    int t;
    scanf("%d",&t);
    while(t--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 1572kb

input:

2
4 3
0 2 3
3 4 2
0 3 1
3 1
1 3 100

output:

2 3 5 6
0 100 100

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 1648kb

input:

1000
2 9
0 2 396628655
1 2 268792718
0 2 16843338
1 2 717268783
0 1 693319712
0 1 856168102
1 2 407246545
1 2 527268921
0 1 536134606
6 2
2 5 451394766
0 5 695984050
9 7
0 6 73936815
2 9 505041862
4 5 223718927
5 7 179262261
3 5 449258178
0 5 493128
0 3 994723920
6 6
3 5 433389755
2 4 773727734
4 5 ...

output:

2085622420 4419671380
0 0 451394766 451394766 1147378816 1147378816
223718927 672977105 994723920 1218442847 1668194153 1742130968 1921393229 1921393229 2426435091
127680943 773727734 1334798432 2184421582 2675644351 2675644351
976357580 1594205360 2103791342 2721639122 2965756455 3485691742 4180705...

result:

wrong answer 4th lines differ - expected: '127680943 773727734 1334798432 2227456393 2675644351 2675644351', found: '127680943 773727734 1334798432 2184421582 2675644351 2675644351'