QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#575129#7905. Ticket to RidesyxsyxWA 2ms4136kbC++141.6kb2024-09-19 10:46:562024-09-19 10:46:56

Judging History

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

  • [2024-09-19 10:46:56]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:4136kb
  • [2024-09-19 10:46:56]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=10005;
int T,n,m,k;
long long ans[N];
struct nd
{
	int l,v;
	bool operator <(const nd &b) const
	{
		return l<b.l;
	}
};
vector <nd> hav[N];
long long sum[N];
long long pre[N],f[N];
//in time t:f[i]:cnt=i-t,now=i,max value
int fa[N];
long long res[N];
int find(int x)
{
	if(x==fa[x]) return x;
	return fa[x]=find(fa[x]);
}
void mrg(int x,int y)//x<-y
{
	int fx=find(x),fy=find(y);
	if(fx==fy) return;
	res[fx]+=res[fy];
	fa[fy]=fx;
}
void clr()
{
	for(int i=1;i<=n;i++) f[i]=0;
	for(int i=1;i<=n;i++) fa[i]=i,res[i]=0;
}
void init()
{
	for(int i=1;i<=n;i++) hav[i].clear(),sum[i]=0;
}
int main()
{
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d%d",&n,&m);
		init();
		for(int i=1;i<=m;i++)
		{
			int l,r,v;
			scanf("%d%d%d",&l,&r,&v);
			l++;
			hav[r].push_back((nd){l,v});
			sum[r]+=v;
		}
		for(int i=1;i<=n;i++) sort(hav[i].begin(),hav[i].end());
		for(int i=1;i<=n;i++) pre[i]=pre[i-1]+sum[i];
		ans[n]=pre[n];
		for(int t=1;t<=n;t++)
		{
			clr();
			for(int i=t;i<=n;i++)
			{
				for(int j=0;j<hav[i].size();j++)
				{
					int l=hav[i][j].l,v=hav[i][j].v;
					res[find(l)]+=v;
				}
				while(1)
				{
					int pos1=find(i),pos2=find(find(i)-1);
					if(pos2<=t) break;
					int res1=f[pos1-1]+res[pos1],res2=f[pos2-1]+res[pos1]+res[pos2];
					if(res1<=res2) mrg(pos2,pos1);
					else break;
				}
				int pos=find(i);
				f[i]=max(pre[i-1],f[pos-1]+res[pos]);
				if(i==t) f[i]=0;
//				printf("%d %d:%d %lld\n",t,i,pos,f[i]);
			}
			for(int i=t;i<=n;i++) pre[i]=f[i];
			ans[n-t]=f[n];
		}
		for(int i=1;i<=n;i++) printf("%lld ",ans[i]);
		printf("\n");
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 4052kb

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 1334798432 2675644351 2675644351 
976357580 1594205360 2103791342 2347908675 3241574409 3936588085 418...

result:

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