提交记录 4148


用户 题目 状态 得分 用时 内存 语言 代码长度
__A_C_T_G__ noi18a. 【NOI2018】归程 Accepted 100 1.601 s 243636 KB C++ 3.66 KB
提交时间 评测时间
2018-07-18 21:31:47 2020-07-31 22:33:04
#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],Top,sta[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){
	for(;(x=fa[x])!=fa[x];)sta[++Top]=x;
	while(Top)fa[sta[Top--]]=x;return 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 #1697.9 us4 MB + 664 KBAcceptedScore: 5

Testcase #2724.29 us4 MB + 700 KBAcceptedScore: 5

Testcase #3882.81 us4 MB + 728 KBAcceptedScore: 5

Testcase #41.093 ms4 MB + 784 KBAcceptedScore: 5

Testcase #55.749 ms5 MB + 812 KBAcceptedScore: 5

Testcase #6920.543 ms187 MB + 844 KBAcceptedScore: 5

Testcase #75.121 ms5 MB + 776 KBAcceptedScore: 5

Testcase #85.12 ms5 MB + 780 KBAcceptedScore: 5

Testcase #95.118 ms5 MB + 780 KBAcceptedScore: 5

Testcase #10696.216 ms181 MB + 80 KBAcceptedScore: 5

Testcase #11696.974 ms181 MB + 108 KBAcceptedScore: 5

Testcase #121.019 s234 MB + 240 KBAcceptedScore: 5

Testcase #131.02 s234 MB + 356 KBAcceptedScore: 5

Testcase #141.02 s234 MB + 200 KBAcceptedScore: 5

Testcase #156.863 ms5 MB + 960 KBAcceptedScore: 5

Testcase #166.848 ms5 MB + 972 KBAcceptedScore: 5

Testcase #171.019 s234 MB + 256 KBAcceptedScore: 5

Testcase #181.019 s234 MB + 340 KBAcceptedScore: 5

Testcase #191.601 s237 MB + 948 KBAcceptedScore: 5

Testcase #201.599 s237 MB + 604 KBAcceptedScore: 5


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