QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#413704#7905. Ticket to Ridegrass8cow#WA 3ms4088kbC++171.8kb2024-05-17 21:53:292024-05-17 21:53:29

Judging History

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

  • [2024-05-17 21:53:29]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:4088kb
  • [2024-05-17 21:53:29]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,m;
#define ll long long
#define mp make_pair
#define pi pair<int,int>
#define pb push_back
#define fi first
#define se second
vector<pi>g[10100];
const ll I=1e18;
ll dp[10100],dp2[10100],ans[10010],all,cf[10100];
int nx[10100],fa[10100],pr[10100];
int F(int x){if(x==fa[x])return x;return fa[x]=F(fa[x]);}
void del(int x,int io){
    int a=pr[x],b=nx[x];nx[a]=b,pr[b]=a;
    cf[b]+=cf[x];
    if(b==io)all-=cf[x];
    fa[x+1]=F(x);
}
void sol(){
    scanf("%d%d",&n,&m);n++;
    for(int i=1;i<=n+3;i++)g[i].clear();
    for(int i=1,l,r,z;i<=m;i++)scanf("%d%d%d",&l,&r,&z),l+=2,r+=2,g[r].pb(mp(l,z));
    dp[1]=0;
    for(int i=2;i<=n+1;i++)dp[i]=-I;
    for(int e=1;e<n;e++){
        all=0;
        dp[0]=0;
        for(int i=1;i<=n+1;i++)nx[i]=i+1,pr[i]=i-1,cf[i]=dp[i]-dp[i-1];
        pr[n+2]=n+1,nx[0]=1;
        for(int i=1;i<=n+3;i++)fa[i]=i;
        for(int i=1;i<=n+1;i++){
            if(i>1){
                all+=cf[i-1];
                if(pr[i-1]==0||cf[i-1]>=0);
                else del(i-1,i);
            }
            dp2[i]=-I;
            for(auto it:g[i]){
                int z=F(it.fi)-1;
                if(!z)continue;
                z=nx[z];
                cf[nx[0]]+=it.se;
                if(z<i){
                    cf[z]-=it.se;
                    while(z<i&&cf[z]<0){
                        int v=nx[z];
                        del(z,i),z=v;
                    }
                }
                else all+=it.se;
            }
            if(pr[i])dp2[i]=max(dp2[i],all);
        }
        for(int i=1;i<=n+1;i++)dp[i]=dp2[i];
        ans[n-e]=dp[n+1];
    }
    for(int i=1;i<n;i++)printf("%lld ",ans[i]);puts("");
}
int main(){
    int T;scanf("%d",&T);while(T--)sol();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 4088kb

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: 3ms
memory: 3988kb

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 
225198311 673963361 995217048 1218442847 1668194153 1742130968 1921393229 1921393229 2426435091 
127680943 773727734 1334798432 2355137336 2803325294 2675644351 
3231225104 2721639122 2103791342 2721639122 3241574409 4046349310 41...

result:

wrong answer 3rd lines differ - expected: '223718927 672977105 994723920 ...921393229 1921393229 2426435091', found: '225198311 673963361 995217048 ...21393229 1921393229 2426435091 '