QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#728549#9569. Subwayucup-team3555WA 28ms247312kbC++142.4kb2024-11-09 15:25:462024-11-09 15:25:50

Judging History

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

  • [2024-11-09 15:25:50]
  • 评测
  • 测评结果:WA
  • 用时:28ms
  • 内存:247312kb
  • [2024-11-09 15:25:46]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef array<ll,2> Nod;
const ll N=1e6+3,V=1e6+1,INF=1e18;
ll n,m,rt[N],a[N],b[N],len[N],ans[N];
vector<ll>ve[N],W[N];
map<ll,ll>mp[N],F[N];
struct Cmp{bool operator()(int X,int Y){return b[X]!=b[Y]?b[X]<b[Y]:X<Y;}};
set<ll,Cmp>S[N];
set<Nod>Q,q[N];
ll Ans(ll x,ll id,ll z){return F[x].count(id)?F[x][id]+a[x]*z:INF;}
struct LCT
{
	ll tot,tr[N],lc[N],rc[N];
	#define ls lc[p]
	#define rs rc[p]
	#define mi ((l+r)>>1)
	void Upd(ll u,ll id,ll &p,ll l=0,ll r=V)
	{
		if(!p)p=++tot;
		ll &v=tr[p];
		if(!v){v=u;return;}
		if(Ans(u,id,mi)<Ans(v,id,mi))swap(u,v);
		if(Ans(u,id,l)<Ans(v,id,l))Upd(u,id,ls,l,mi);
		if(Ans(u,id,r)<Ans(v,id,r))Upd(u,id,rs,mi+1,r);
	}
	ll Ask(ll d,ll id,ll p,ll l=0,ll r=V)
	{
		if(!p)return INF;
		ll s=Ans(tr[p],id,d);
		return min(s,d<=mi?Ask(d,id,ls,l,mi):Ask(d,id,rs,mi+1,r));
	}
}T;
void Make(int x,int y,ll z)
{
	if(!F[x].count(y))F[x][y]=z;
	else F[x][y]=min(F[x][y],z);
}
void Era(int x,int id)
{
	Q.erase({(*q[id].begin())[0],id});
	q[id].erase({F[x][id],x});S[id].erase(x); 
	int y=!S[id].size()?0:*S[id].begin();
	if(y)
	{
		q[id].erase({F[y][id],y}); 
		Make(y,id,T.Ask(b[y],rt[id],rt[id]));
		q[id].insert({F[y][id],y});
	}
	Q.insert({(*q[id].begin())[0],id});
}
void Upd(int x,int id)
{
	int now=mp[x][id];
	T.Upd(x,id,rt[id]);Era(x,id);
	if(now==len[x]-1)return;
	int to=ve[x][now+1];
	Q.erase({(*q[to].begin())[0],to});
	q[to].erase({F[x][to],x}); 
	Make(x,to,F[x][id]+W[x][now]);
	q[to].insert({F[x][to],x});
	Q.insert({(*q[to].begin())[0],to});
}
int main()
{
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=m;i++)cin>>b[i];
	for(int i=1;i<=m;i++)cin>>a[i];
	for(int i=1;i<=n;i++)ans[i]=INF,q[i].insert({INF,0});
	for(int i=1;i<=m;i++)
	{
		cin>>len[i];ve[i].resize(len[i]);W[i].resize(len[i]);
		for(int j=0;j<len[i];j++)
		{
			int x=0,y=0;cin>>x;ve[i][j]=x;
			if(x==1)F[i][x]=0;
			else F[i][x]=INF;
			if(j<len[i]-1)cin>>y;
			mp[i][x]=j,W[i][j]=y;
			S[x].insert(i);
			q[x].insert({F[i][x],i});
		}
	}
	for(int i=1;i<=n;i++)Q.insert({(*q[i].begin())[0],i});
	while(Q.size())
	{
		Nod t=*Q.begin();
		if(t[0]>=INF)break;
		int id=t[1],x=(*q[id].begin())[1];Upd(x,id);
	}
	for(int i=1;i<=m;i++)for(auto t:F[i])ans[t.first]=min(ans[t.first],t.second);
	for(int i=2;i<=n;i++)cout<<ans[i]<<" ";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 28ms
memory: 245312kb

input:

6 3
1 5 1
5 5 1
3 1 2 2 3 3
3 5 1 2 1 4
3 3 4 5 4 6

output:

2 5 21 14 18 

result:

ok 5 number(s): "2 5 21 14 18"

Test #2:

score: 0
Accepted
time: 24ms
memory: 245312kb

input:

6 3
1 5 1
5 5 1
5 1 2 2 100 3 100 6 1 4
5 1 100 2 4 3 100 5 1 4
2 3 1 5

output:

2 31 43 37 136 

result:

ok 5 number(s): "2 31 43 37 136"

Test #3:

score: -100
Wrong Answer
time: 27ms
memory: 247312kb

input:

5 9
278281 70119 511791 834898 25300 63487 609134 236836 394497
835557 287345 579404 879128 636344 306393 569430 152565 47119
2 3 823004250 4
2 1 25427550 3
2 1 15849621 3
2 1 701911826 5
3 5 679672631 3 907176714 2
2 1 817370554 2
2 3 697987914 2
2 4 873900795 2
2 1 814305954 5

output:

817370554 15849621 1000000000000000000 701911826 

result:

wrong answer 3rd numbers differ - expected: '80811085745', found: '1000000000000000000'