QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#387652#7905. Ticket to RideciuimWA 2ms4100kbC++141.9kb2024-04-12 18:15:362024-04-12 18:15:36

Judging History

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

  • [2024-04-12 18:15:36]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:4100kb
  • [2024-04-12 18:15:36]
  • 提交

answer

#include <cstdio>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <cstring>
#include <array>
#include <algorithm>
#include <queue>
#include <vector>
#include <bitset>
#include <ctime>
#include <cstdlib>
#include <random>
#include <set>
#include <ctime>
#include <map>
#include <stack>
#include <unordered_map>
#define ll long long
#define ull unsigned long long
#define reg register
#define fo(a,b,c) for(reg ll a=b;a<=c;++a)
#define re(a,b,c) for(reg ll a=b;a>=c;--a)
#define pii pair<ll,ll>
#define fi first
#define pb push_back
#define se second
#define ite set<ll> ::iterator
using namespace std;
//const ll mod=998244353;
inline ll gi()
{
	ll x = 0, f = 1;
	char ch = getchar();
	while(ch < '0' || ch > '9')
	{
		if (ch == '-')
			f = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9')
	{
		x = (x<<1) + (x<<3) + (ch^48);
		ch = getchar();
	}
	return x * f;
}
ll _=1;
const ll inf=1e17;
const ll N=10005;
ll dp[N],ans[N],nxt[N],fa[N],val[N],f[N];
vector<pii> vec[N];
ll fd(ll x)
{
	if(fa[x]==x) return x;
	return fa[x]=fd(fa[x]);
}
void add(ll st,ll ed,ll w)
{
	val[st]+=w;
	while(nxt[st]!=ed)
	{
		if(val[st]+dp[st]>dp[nxt[st]])
		{
			val[st]+=val[nxt[st]];
			fa[nxt[st]]=st;
			nxt[st]=nxt[nxt[st]];
		}
		else break;
	}
}
void sol()
{
	ll n=gi(),m=gi();
	fo(i,1,m)
	{
		ll l=gi()+1,r=gi(),w=gi();
		vec[r].pb({l,w});
	}
	fo(i,0,n) ans[i]=0;
	fo(j,0,n)
	{
		fo(i,0,n)
		{
			dp[i]=-inf;
			fa[i]=i;
			val[i]=0;
			nxt[i]=i+1;
		}
		dp[j]=0;
		fo(i,j+1,n)
		{
			for(pii p:vec[i])
			{
				if(p.fi<=j) continue;
				add(p.fi-1,i,p.se);
			}
			dp[i]=max(f[i-1],dp[fd(i-1)]+val[fd(i-1)]);
		}
		fo(i,j+1,n)
		{
			ans[i-j]=max(ans[i-j],dp[i]);
		}
		fo(i,0,n) f[i]=dp[i];
	}
	fo(i,1,n)
	{
		ans[i]=max(ans[i-1],ans[i]);
		cout<<ans[i]<<" ";
		vec[i].clear();
	}
}
int main()
{
	_=gi();
	while(_--)
	{
		sol();
		printf("\n");
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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 2499094413 
0 0 451394766 451394766 1147378816 1147378816 
223718927 672977105 994723920 1218442847 1668194153 1742130968 1742130968 1742130968 1742130968 
127680943 773727734 901408677 1794066638 1794066638 1794066638 
976357580 1594205360 2103791342 2721639122 2798805018 3321168631 3321...

result:

wrong answer 1st lines differ - expected: '2085622420 4419671380', found: '2085622420 2499094413 '