提交记录 4287


用户 题目 状态 得分 用时 内存 语言 代码长度
zbw001 noi18a. 【NOI2018】归程 Accepted 100 1.77 s 145852 KB C++ 2.12 KB
提交时间 评测时间
2018-07-19 18:56:31 2020-07-31 22:50:50
//sro zbw ak noi2018 orz
#include<bits/stdc++.h>
using namespace std;
#define FE "return"
#define pb push_back
#define clr(a) memset(a,0,sizeof(a))
const int N=500005,N2=N<<1,inf=0x3f3f3f3f;
int n,m,d[N2],mn[N2],vis[N],t,fa[N2][20],uf[N2],lust,Q,k,s;
struct node{int d,n;};
bool operator<(node a,node b){return b.d<a.d;}
priority_queue<node>q;
vector<int>e[N],f[N];
void dbg(string a,node x){cerr<<a<<"  ("<<x.d<<","<<x.n<<")\n";}
struct edge{int u,v,w,x;}ed[N2];
bool cmp(edge a,edge b){return b.x<a.x;}
void init();
int find(int a){if(uf[a])return uf[a]=find(uf[a]);return a;}
void build(){clr(fa),clr(uf),clr(mn);
	for(int i=1;i<=n;i++)mn[i]=inf;
	for(int i=0,j=n;i<m;i++){
		int v=find(ed[i].v),u=find(ed[i].u);
		if(v==u)continue;
		uf[v]=uf[u]=++j,fa[v][0]=fa[u][0]=j,d[j]=inf,mn[j]=ed[i].x;
	}n=(n<<1)-1;
	for(int i=1;i<=n;i++)
		d[fa[i][0]]=min(d[fa[i][0]],d[i]),mn[fa[i][0]]=min(mn[fa[i][0]],mn[i]);
	for(int k=1;k<20;k++)for(int i=1;i<=n;i++)fa[i][k]=fa[fa[i][k-1]][k-1];
	//for(int i=1;i<=n;i++)printf("%d %d %d\n",d[i],mn[i],fa[i][0]);
}
void solve(){lust=0;
	scanf("%d%d%d",&Q,&k,&s);
	while(Q--){
		int a,b;scanf("%d%d",&a,&b);
		a=(a+(long long)k*lust-1)%((n+1)>>1)+1,b=(b+(long long)k*lust)%(s+1);//printf("query %d %d\n",a,b);
		for(int k=19;~k;k--)if(b<mn[fa[a][k]])a=fa[a][k];
		printf("%d\n",lust=d[a]);
	}
}
int main(){
	freopen(FE".in","r",stdin);
	freopen(FE".out","w",stdout);
	scanf("%d",&t);while(t--){
		init();
		build();
		solve();
	}return 0;
}
void init(){clr(vis),clr(d);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)e[i].clear(),f[i].clear();
	for(int i=0;i<m;i++){
		int a,b,c,d;scanf("%d%d%d%d",&a,&b,&c,&d);
		e[a].pb(b),f[a].pb(c);
		e[b].pb(a),f[b].pb(c);
		ed[i]=(edge){a,b,c,d};
	}sort(ed,ed+m,cmp);
	for(int i=2;i<=n;i++)d[i]=inf;
	q.push((node){0,1});
	while(!q.empty()){
		node nod=q.top();q.pop();//dbg("out",nod);
		int v=nod.n;
		if(vis[v])continue;vis[v]=1;//dbg("ok",nod);
		for(int i=0;i<(int)e[v].size();i++){
			int u=e[v][i],w=d[v]+f[v][i];//dbg("chk",(node){w,u});
			if(!vis[u]&&w<d[u])d[u]=w,q.push((node){w,u});//dbg("in",(node){w,u});
		}
	}//for(int i=1;i<=n;i++){if(d[i]==inf)d[i]=2147483647;printf("%d ",d[i]);}
} 

CompilationN/AN/ACompile OKScore: N/A

Testcase #117.83 ms112 MB + 584 KBAcceptedScore: 5

Testcase #217.962 ms112 MB + 588 KBAcceptedScore: 5

Testcase #318.023 ms112 MB + 596 KBAcceptedScore: 5

Testcase #418.315 ms112 MB + 604 KBAcceptedScore: 5

Testcase #522.654 ms112 MB + 828 KBAcceptedScore: 5

Testcase #61.056 s137 MB + 932 KBAcceptedScore: 5

Testcase #721.579 ms112 MB + 744 KBAcceptedScore: 5

Testcase #821.457 ms112 MB + 748 KBAcceptedScore: 5

Testcase #921.467 ms112 MB + 744 KBAcceptedScore: 5

Testcase #10823.573 ms130 MB + 376 KBAcceptedScore: 5

Testcase #11824.123 ms130 MB + 380 KBAcceptedScore: 5

Testcase #121.203 s139 MB + 520 KBAcceptedScore: 5

Testcase #131.204 s139 MB + 364 KBAcceptedScore: 5

Testcase #141.204 s138 MB + 800 KBAcceptedScore: 5

Testcase #1523.228 ms112 MB + 832 KBAcceptedScore: 5

Testcase #1623.33 ms112 MB + 836 KBAcceptedScore: 5

Testcase #171.203 s139 MB + 32 KBAcceptedScore: 5

Testcase #181.203 s139 MB + 316 KBAcceptedScore: 5

Testcase #191.767 s142 MB + 444 KBAcceptedScore: 5

Testcase #201.77 s141 MB + 964 KBAcceptedScore: 5


Judge Duck Online | 评测鸭在线
Server Time: 2024-12-05 10:29:27 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠