QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#639087#7905. Ticket to Ridelsj2009WA 3ms4056kbC++202.3kb2024-10-13 17:51:462024-10-13 17:51:49

Judging History

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

  • [2024-10-13 17:51:49]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:4056kb
  • [2024-10-13 17:51:46]
  • 提交

answer

#include<bits/stdc++.h>
//#pragma GCC optimize(3,"Ofast","inline")
#define int long long
#define i128 __int128
#define ll long long
#define ull unsigned long long
#define uint unsigned int
#define ld double
#define PII pair<int,int>
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f
#define chkmax(a,b) a=max(a,b)
#define chkmin(a,b) a=min(a,b)
#define rep(k,l,r) for(int k=l;k<=r;++k)
#define per(k,r,l) for(int k=r;k>=l;--k)
#define cl(f,x) memset(f,x,sizeof(f))
#define pcnt(x) __builtin_popcount(x)
#define lg(x) (31-__builtin_clz(x))
using namespace std;
void file_IO() {
//	system("fc .out .ans");
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
}
bool M1;
const int N=1e4+5;
int f[2][N],g[2][N],w[N],d[N],ans[N];
vector<PII> vec[N];
struct dsu {
	int fa[N];
	void init(int n) {
		rep(i,0,n)
			fa[i]=i;
	}
	int find(int x) {
		if(fa[x]!=x)
			fa[x]=find(fa[x]);
		return fa[x];
	}
	void to(int u,int v) {
		fa[u]=v;
	}
}; dsu pre,suf;
void solve() {
	int n,m;
	scanf("%lld%lld",&n,&m);
	rep(i,0,n)
		vec[i].clear();
	while(m--) {
		int l,r,val;
		scanf("%lld%lld%lld",&l,&r,&val);
		vec[r].push_back(make_pair(l,val));
	}
	rep(i,0,n)
		f[0][i]=g[0][i]=-INFLL;
	f[0][0]=g[0][0]=0;
	rep(k,0,n) {
		rep(i,0,n) {
			w[i]=-INFLL;
			d[i]=0;
			if(k)
				f[k&1][i]=g[k&1][i]=-INFLL;
		}
		pre.init(n);
		suf.init(n);
		rep(i,k,n) {
			if(k)
				g[k&1][i]=max(g[(k-1)&1][i-1],f[(k-1)&1][i-1]);
			w[i]=g[k&1][i];
			if(i!=k) {
				int x=pre.find(i-1);
				if(w[x]+d[x]>=w[i]+d[i]) {
					pre.to(i,i-1);
					suf.to(i-1,i);
				}
			}
			for(auto x:vec[i]) {
				int p=x.first,val=x.second;
				int l=pre.find(p),r=suf.find(p);
				d[l]+=val;
				if(r!=i&&w[l]+d[l]>=w[r+1]+d[r+1]) {
					pre.to(r+1,r);
					suf.to(r,r+1);
					d[l]+=d[r+1];
				}
			}
			if(i!=k) {
				int x=pre.find(i-1);
				f[k&1][i]=w[x]+d[x];
			}
		}
		ans[n-k]=max(f[k&1][n],g[k&1][n]);
	}
	rep(i,1,n)
		printf("%lld ",ans[i]);
	puts("");
}
/*
1
6 2
2 5 451394766
0 5 695984050
*/
bool M2;
signed main() {
	//file_IO();
	int testcase=1;
	scanf("%lld",&testcase);
	while(testcase--)
		solve();
	fprintf(stderr,"used time = %ldms\n",1000*clock()/CLOCKS_PER_SEC);
	fprintf(stderr,"used memory = %lldMB\n",(&M2-&M1)/1024/1024);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

result:

wrong answer 45th lines differ - expected: '701543846 1264948865 1406826784 1970231803 2657976406 3406628496', found: '701543846 1264948865 126494886...70231803 2657976406 3406628496 '