提交记录 4110


用户 题目 状态 得分 用时 内存 语言 代码长度
__A_C_T_G__ noi18a. 【NOI2018】归程 Accepted 100 1.618 s 243444 KB C++ 3.61 KB
提交时间 评测时间
2018-07-18 20:59:31 2020-07-31 22:28:41
#include<cstring>
#include<cstdio>
#include<algorithm>
#define N 400100
#define ll long long
#define fo(i,a,b) for(int i=a,E=b;i<=E;i++)
#define M 20000010

using namespace std;

int l[N+N],v[N+N],nex[N+N],hd[N],top,heap[N],pos[N],d[N],K,n,m,q,a[N],t,S,lg[N];
int fa[N],to[N+N],nxt[N+N],fir[N],tot,cnt,son[M][2],left[M],right[M],opu,opv,opl,opr,rt[N];
int dfl[N],dfr[N];
ll f[N],mn[20][N];
bool vis[N];
struct road{int u,v,l,a;}r[N];
bool cmp(road a,road b){return a.a>b.a;}

void link(int x,int y,int val){
	l[++top]=val;v[top]=y;nex[top]=hd[x];hd[x]=top;
}

void down(int x){
	for(int y=x+x,z=y+1;y<=top;swap(heap[x],heap[y]),pos[heap[x]]=x,pos[heap[y]]=y,x=y,y=x+x,z=y+1){
		if(f[heap[y]]>f[heap[z]])y=z;
		if(f[heap[x]]<=f[heap[y]])break;
	}
}
void up(int x){
	for(int y=x>>1;y;swap(heap[x],heap[y]),pos[heap[x]]=x,pos[heap[y]]=y,x=y,y=x>>1)
		if(f[heap[x]]>=f[heap[y]])break;
}
int get(){
	int r=heap[1];pos[heap[top]]=1;heap[1]=heap[top--];down(1);return r;
}
void put(int x){
	heap[++top]=x;pos[x]=top;up(top);
}

void dijk(){
	fo(i,1,n)f[i]=1e18,d[i]=i,vis[i]=0;
	f[1]=0;top=0;
	fo(i,1,n)put(i);
	fo(i,1,n){
		int x=get();vis[x]=1;
		for(int o=hd[x];o;o=nex[o])if(!vis[v[o]])
			if(f[v[o]]>f[x]+l[o]){
				f[v[o]]=f[x]+l[o];up(pos[v[o]]);
			}
	}
}

int find(int *a,int v,int l){
	int h=1,t=l,m,r=l;
	while(h<=t)if(a[m=h+t>>1]<=v)t=m-1,r=m;else h=m+1;
	return r;
}

ll getmn(int h,int t){
	int l=lg[t-h+1];
	return min(mn[l][h],mn[l][t-(1<<l)+1]);
}

int get(int x){return x==fa[x]?x:(fa[x]=get(fa[x]));}

void con(int x,int y){
	to[++top]=y;nxt[top]=fir[x];fir[x]=top;
}
void dfs(int x){
	dfl[x]=dfr[x]=++top;
	for(int i=fir[x];i;i=nxt[i])dfs(to[i]),dfr[x]=dfr[to[i]];
}
void build(int &w,int h,int t){
	w=++cnt;
	if(h==t){
		left[w]=h;right[w]=t;return;
	}left[w]=right[w]=-1;
	int m=h+t>>1;
	build(son[w][0],h,m);build(son[w][1],m+1,t);
}
void cover(int &u,int v,int h,int t){
	u=++cnt;
	if(opl<=h && opr>=t){
		left[u]=opl;right[u]=opr;return;
	}son[u][0]=son[v][0];son[u][1]=son[v][1];
	left[u]=right[u]=-1;
	int m=h+t>>1;
	if(opl<=m)cover(son[u][0],son[v][0],h,m);
	if(opr>m)cover(son[u][1],son[v][1],m+1,t);
}
void query(int w,int h,int t){
	if(left[w]!=-1){
		opu=left[w];opv=right[w];return;
	}int m=h+t>>1;
	if(opl<=m)query(son[w][0],h,m);else query(son[w][1],m+1,t);
}

void pre(){
	top=cnt=0;tot=n;
	fo(i,1,n+n)fa[i]=i;
	memset(fir,0,sizeof fir);
	fo(i,1,m){
		int u=r[i].u,v=r[i].v,A=get(u),B=get(v);
		if(A==B)continue;f[++tot]=1e18;fa[A]=tot;fa[B]=tot;con(tot,A);con(tot,B);
	}top=0;dfs(tot);
	fo(i,1,tot)mn[0][dfl[i]]=f[i];
	fo(j,1,19)fo(i,1,tot)if(tot-i+1>=(1<<j))mn[j][i]=min(mn[j-1][i],mn[j-1][i+(1<<j-1)]);
	fo(i,1,n+n)fa[i]=i;
	build(rt[1],1,tot);
	int las=rt[1],tmp=n,w=1;
	fo(i,1,t){
		if(i>1)rt[i]=rt[i-1];
		while(w<=m && r[w].a>a[i]){
			int u=r[w].u,v=r[w].v,A=get(u),B=get(v);w++;
			if(A==B)continue;++tmp;fa[A]=tmp;fa[B]=tmp;
			opl=opu=dfl[tmp];opr=opv=dfr[tmp];
			cover(rt[i],las,1,tot);las=rt[i];
		}
	}
}

int main(){
	int T;scanf("%d",&T);
	lg[1]=0;
	fo(i,2,N-1)lg[i]=lg[i>>1]+1;
	while(T--){
		scanf("%d %d",&n,&m);
		top=0;
		memset(hd,0,sizeof hd);
		fo(i,1,m){
			int fr,to,len,lev;scanf("%d %d %d %d",&fr,&to,&len,&lev);
			a[i]=lev;r[i]=(road){fr,to,len,lev};link(fr,to,len);link(to,fr,len);
		}
		sort(r+1,r+m+1,cmp);sort(a+1,a+m+1);fo(i,1,m/2)swap(a[i],a[m+1-i]);
		fo(i,1,m)if(i==1)t=1;else if(a[i]^a[i-1])a[++t]=a[i];
		a[++t]=0;
		dijk();pre();
		scanf("%d %d %d",&q,&K,&S);
		ll las=0;
		fo(i,1,q){
			ll u,lev;scanf("%lld %lld",&u,&lev);
			u=(u+K*las-1)%n+1;lev=(lev+K*las)%(S+1);
			if(i==28){
				int yyy=0;
				yyy=1;
			}
			opl=dfl[u];query(rt[find(a,(int)lev,t)],1,tot);
			printf("%lld\n",las=getmn(opu,opv));
		}
	}
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #1700.03 us4 MB + 672 KBAcceptedScore: 5

Testcase #2727.06 us4 MB + 704 KBAcceptedScore: 5

Testcase #3883.68 us4 MB + 736 KBAcceptedScore: 5

Testcase #41.108 ms4 MB + 788 KBAcceptedScore: 5

Testcase #55.918 ms5 MB + 812 KBAcceptedScore: 5

Testcase #6933.855 ms187 MB + 840 KBAcceptedScore: 5

Testcase #75.132 ms5 MB + 780 KBAcceptedScore: 5

Testcase #85.177 ms5 MB + 784 KBAcceptedScore: 5

Testcase #95.164 ms5 MB + 784 KBAcceptedScore: 5

Testcase #10709.273 ms181 MB + 80 KBAcceptedScore: 5

Testcase #11708.741 ms181 MB + 104 KBAcceptedScore: 5

Testcase #121.035 s233 MB + 1004 KBAcceptedScore: 5

Testcase #131.036 s234 MB + 120 KBAcceptedScore: 5

Testcase #141.036 s234 MB + 36 KBAcceptedScore: 5

Testcase #156.969 ms5 MB + 960 KBAcceptedScore: 5

Testcase #166.958 ms5 MB + 976 KBAcceptedScore: 5

Testcase #171.035 s234 MB + 60 KBAcceptedScore: 5

Testcase #181.035 s234 MB + 108 KBAcceptedScore: 5

Testcase #191.618 s237 MB + 756 KBAcceptedScore: 5

Testcase #201.617 s237 MB + 480 KBAcceptedScore: 5


Judge Duck Online | 评测鸭在线
Server Time: 2026-04-14 02:47:50 | Loaded in 2 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠