UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#211277#2401. 移动mygr02437ms94248kbC++3.3kb2024-08-10 11:32:062024-08-10 12:39:04

answer

#include<bits/stdc++.h>
using namespace std;
int n,m,k;
struct Mp{
	int Map[105][105];
	void init()
	{
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
				Map[i][j]=0x7ffffff;
	}
	void add(int u,int v,int w)
	{
		Map[u][v]=min(Map[u][v],w);
		Map[v][u]=min(Map[v][u],w);
	}
	void floyd()
	{
		for(int k=1;k<=n;k++)
			for(int i=1;i<=n;i++)
				for(int j=1;j<=n;j++)
					Map[i][j]=min(Map[i][j],Map[i][k]+Map[k][j]);
	}
	int dis(int u,int v)
	{
		return Map[u][v];
	}
}M;
struct dp{
	int n[4][4];
	dp()
	{
		for(int i=0;i<k;i++)
			for(int j=0;j<k;j++)
				n[i][j]=0x7fffffff;
	}
	dp operator * (dp &b)
	{
		dp ans;
		for(int i=0;i<k;i++)
			for(int j=0;j<k;j++)
				for(int l=0;l<k;l++)
					ans.n[i][j]=min(ans.n[i][j],n[i][l]+b.n[l][j]);
		return ans;
	}
	int getMin()
	{
		int ans=0x7fffffff;
		for(int i=0;i<k;i++)
			for(int j=0;j<k;j++)
				ans=min(ans,n[i][j]);
		return ans;
	}
};
struct seg_Tree{////////         k--
public:
	dp p[(int(4e5+5))*4];
	void pushup(int now)
	{
		p[now]=p[now<<1]*p[now<<1|1];
	}
	void update(int now,int l,int r,int loc,dp &num)
	{
		if(l==r)
		{
			p[now]=num;
			return ;
		}
		int mid=(l+r)>>1;
		if(loc<=mid)
			update(now<<1,l,mid,loc,num);
		else
			update(now<<1|1,mid+1,r,loc,num);
		pushup(now);
	}
	dp query(int now,int l,int r,int nl,int nr)
	{
		if(l<=nl and nr<=r)
			return p[now];
		int mid=(nl+nr)>>1;
		bool can=false;
		dp ans;
		if(l<=mid)
			ans=query(now<<1,l,r,nl,mid);
		if(mid<r)
		{
			if(can)
			{
				dp in=query(now<<1|1,l,r,mid+1,nr);
				ans=(ans*in);
			}
				
			ans=query(now<<1|1,l,r,mid+1,nr);
		}
		return ans;
	}
}T;
int c,a,q;
int num[(int(4e5+5))][4];
int to[4],vis[4];
int na=0;
void dfs(int dep,int u,int v,int fi,dp &ans)
{
	if(dep>=k)
	{
		ans.n[fi][to[fi]]=min(ans.n[fi][to[fi]],na);
		return ;
	}	
	for(int i=0;i<k;i++)
	{
		if(!vis[i])
		{
			vis[i]=1;
			to[dep]=i;
			if(dep==fi)
				na+=M.dis(num[u][dep],num[v][i])*a;
			else
				na+=M.dis(num[u][dep],num[v][i]);
			dfs(dep+1,u,v,fi,ans);
			vis[i]=0;
			to[dep]=0;
			if(dep==fi)
				na-=M.dis(num[u][dep],num[v][i])*a;
			else
				na-=M.dis(num[u][dep],num[v][i]);
		}
	}
}
dp getdp(int u,int v)
{
	dp ans;
	for(int i=0;i<k;i++)
		dfs(0,u,v,i,ans);
	return ans;
}
dp nxt[(int(4e5+5))];
void build(int now,int l,int r)
{
	if(l==r)
	{
		T.p[now]=nxt[l];
		return ;
	}
	int mid=(l+r)>>1;
	build(now<<1,l,mid);
	build(now<<1|1,mid+1,r);
	T.pushup(now);
}
signed main()
{
	scanf("%d%d%d%d%d%d",&n,&m,&c,&k,&a,&q);
	int u,v,w;
	M.init();
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d%d",&u,&v,&w);
		M.add(u,v,w);
	}
	M.floyd();
	for(int i=1;i<=c;i++)
	{
		for(int j=0;j<k;j++)
			scanf("%d",&num[i][j]);
	}
	for(int i=1;i<c;i++)
		nxt[i]=getdp(i,i+1);
	build(1,1,c-1);
	int op,l,r;
	while(q--)
	{
		scanf("%d",&op);
		if(op==1)
		{
			scanf("%d",&l);
			for(int i=0;i<k;i++)
				scanf("%d",&num[l][i]);
			if(l!=c)
			{
				nxt[l]=getdp(l,l+1);
				T.update(1,1,c-1,l,nxt[l]);
			}
			if(l!=1)
			{
				nxt[l-1]=getdp(l-1,l);
				T.update(1,1,c-1,l-1,nxt[l-1]);
			}
		}
		else
		{
			scanf("%d%d",&l,&r);
			if(l==r)
			{
				printf("0\n");
				continue;
			}
			dp ans;
			ans=T.query(1,l,r-1,1,c-1);
			printf("%d\n",ans.getMin());
		}
	}
}

详细

小提示:点击横条可展开更详细的信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 7ms
memory: 1272kb

input:

100 4950 100 3 8 100
1 2 100000
1 3 100000
1 4 100000
1 5 100000
1 6 100000
1 7 100000
1 8 100000
1 ...

output:

1000000
2000000
3000000
1000000
2000000
24206760
1000000
25000000
23207896
1000000
6000000
1000000
1...

result:

wrong answer 1st lines differ - expected: '19200000', found: '1000000'

Subtask #2:

score: 0
Wrong Answer

Test #10:

score: 0
Wrong Answer
time: 861ms
memory: 94248kb

input:

100 4950 351493 3 10 100000
1 2 100000
1 3 100000
1 4 100000
1 5 100000
1 6 100000
1 7 100000
1 8 10...

output:

3600000
2400000
1200000
212320
1200000
1615230
1200000
1200000
7200000
3600000
19189149
207430
20594...

result:

wrong answer 1st lines differ - expected: '240622197023', found: '3600000'

Subtask #3:

score: 0
Wrong Answer

Test #19:

score: 0
Wrong Answer
time: 344ms
memory: 94244kb

input:

100 4950 351493 1 10 100000
1 2 100000
1 3 100000
1 4 100000
1 5 100000
1 6 100000
1 7 100000
1 8 10...

output:

2000000
6000000
3000000
5000000
1000000
1000000
1000000
1000000
2000000
1000000
1000000
2000000
4750...

result:

wrong answer 1st lines differ - expected: '88025960740', found: '2000000'

Subtask #4:

score: 0
Wrong Answer

Test #28:

score: 0
Wrong Answer
time: 368ms
memory: 94248kb

input:

100 4950 351493 1 10 100000
1 2 100000
1 3 100000
1 4 100000
1 5 100000
1 6 100000
1 7 100000
1 8 10...

output:

2000000
6000000
3000000
5000000
1000000
1000000
1000000
1000000
2000000
1000000
1000000
2000000
4750...

result:

wrong answer 1st lines differ - expected: '88025960740', found: '2000000'

Subtask #5:

score: 0
Wrong Answer

Test #46:

score: 0
Wrong Answer
time: 852ms
memory: 94244kb

input:

100 4950 351493 3 10 100000
1 2 100000
1 3 100000
1 4 100000
1 5 100000
1 6 100000
1 7 100000
1 8 10...

output:

3600000
2400000
1200000
212320
1200000
1615230
1200000
1200000
7200000
3600000
19189149
207430
20594...

result:

wrong answer 1st lines differ - expected: '240622197023', found: '3600000'

Subtask #6:

score: 0
Wrong Answer

Test #64:

score: 0
Wrong Answer
time: 5ms
memory: 1268kb

input:

100 4950 100 3 8 100
1 2 100000
1 3 100000
1 4 100000
1 5 100000
1 6 100000
1 7 100000
1 8 100000
1 ...

output:

1000000
2000000
3000000
1000000
2000000
24206760
1000000
25000000
23207896
1000000
6000000
1000000
1...

result:

wrong answer 1st lines differ - expected: '19200000', found: '1000000'