QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#80322#3029. The Great Drone ShowXZTmaxsmall67AC ✓18650ms851572kbC++233.8kb2023-02-23 14:17:422023-02-23 14:17:44

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-23 14:17:44]
  • 评测
  • 测评结果:AC
  • 用时:18650ms
  • 内存:851572kb
  • [2023-02-23 14:17:42]
  • 提交

answer

#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define int long long
using namespace std;
const int N=1e6+100,inf=1e18+7;
int n,m,k,q;
struct Edge{int x,y,lim,v;}e[N<<1];
int X[N],Y[N],Z[N],deg[N],vis[N];
set<tuple<int,int,int> ,greater<tuple<int,int,int> > >l[N];
set<tuple<int,int,int> >r[N];
set<pii>g[N];
int get(int id)
{
	__int128 x=(X[e[id].x]-X[e[id].y]),y=(Y[e[id].x]-Y[e[id].y]),z=e[id].lim;
	__int128 v=z*z-x*x-y*y,d=(__int128)sqrt((int)v);d=max(d-5,(__int128)0);
	while((d+1)*(d+1)<=v)d++;
	return d;
}
#undef int long long
namespace G
{
	int tot;
	int fa[N<<1],dep[N<<1],st[N<<1][22],val[N<<1][22];
	void clear(int n,int m)
	{
		tot=n;
		for(int i=0;i<=n+m;i++)fa[i]=i,dep[i]=0; 
		for(int i=0;i<=20;i++)
			for(int j=0;j<=n+m;j++)
				st[j][i]=0,val[j][i]=inf;
	}
	int get(int x){return x==fa[x]?x:fa[x]=get(fa[x]);}
	void add(int x,int y,int v)
	{
		x=get(x);y=get(y);if(x==y)return;
		fa[x]=fa[y]=++tot;
		st[x][0]=st[y][0]=tot;
		val[x][0]=val[y][0]=v;
	}
	void build()
	{
		clear(n,m);
		sort(e+1,e+m+1,[&](const Edge&x,const Edge&y){return x.v>y.v;});
		for(int i=1;i<=m;i++)add(e[i].x,e[i].y,e[i].v);
		for(int i=tot;i>=1;i--)dep[i]=dep[st[i][0]]+1;
		for(int i=1;i<=20;i++)
			for(int j=tot;j>=1;j--)
				st[j][i]=st[st[j][i-1]][i-1],
				val[j][i]=min(val[j][i-1],val[st[j][i-1]][i-1]);
	}
	int query(int x,int y)
	{
		if(dep[x]<dep[y])swap(x,y);
		int v=1e9+7;
		for(int i=20;i>=0;i--) 
			if(dep[st[x][i]]>=dep[y])v=min(v,val[x][i]),x=st[x][i];
		if(x==y)return v;
		for(int i=20;i>=0;i--)
			if(st[x][i]!=st[y][i])v=min({v,val[x][i],val[y][i]}),x=st[x][i],y=st[y][i];
		return min({v,val[x][0],val[y][0]});
	}
};
#define int long long
void solve()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
		deg[i]=Z[i]=vis[i]=0,l[i].clear(),r[i].clear(),g[i].clear(),e[i]={0,0,0,0};
	for(int i=1;i<=n;i++)scanf("%lld%lld",&X[i],&Y[i]);
	scanf("%lld",&m);
	for(int i=1,x,y,z;i<=m;i++)
	{
		scanf("%lld%lld%lld",&x,&y,&z);
		g[x].insert(mp(y,i));
		g[y].insert(mp(x,i));
		deg[x]++,deg[y]++;
		e[i]={x,y,z,0};e[i].lim=get(i);
	}
	queue<int>q;
	for(int i=1;i<=n;i++)if(deg[i]<=4)q.push(i),vis[i]=1;
	while(!q.empty())
	{
		int x=q.front();q.pop();
		for(auto t:g[x])
		{
			int y,id;tie(y,id)=t;
			g[y].erase(mp(x,id));deg[y]--;
			if(deg[y]<=4&&!vis[y])vis[y]=1,q.push(y);
			l[y].insert(mt(Z[x]-e[id].lim,x,id));
			r[y].insert(mt(Z[x]+e[id].lim,x,id));
//			cout<<"Edge::"<<' '<<y<<" "<<x<<endl;
		}
	}
	scanf("%lld",&k);
	for(int i=1;i<=m;i++)e[i].v=k+1;
	for(int i=1,x,v;i<=k;i++)
	{
		scanf("%lld%lld",&x,&v);Z[x]+=v;
		auto it=l[x].begin();
		while(it!=l[x].end()&&get<0>(*it)>Z[x])
		{
			int z,y,id;tie(z,y,id)=*it;
			g[y].erase(mp(x,id));
			it=l[x].erase(it);r[x].erase(mt(z+2*e[id].lim,y,id));
			e[id].v=i;
		}
		it=r[x].begin();
		while(it!=r[x].end()&&get<0>(*it)<Z[x])
		{
			int z,y,id;tie(z,y,id)=*it;
			g[y].erase(mp(x,id));
			it=r[x].erase(it);l[x].erase(mt(z-2*e[id].lim,y,id));
			e[id].v=i;
		}
		for(auto it=g[x].begin();it!=g[x].end();)
		{
			int y,id;tie(y,id)=*it;
			l[y].erase(mt(Z[x]-v-e[id].lim,x,id));
			r[y].erase(mt(Z[x]-v+e[id].lim,x,id));
			if(abs(Z[x]-Z[y])<=e[id].lim)
			{
				it++;
				l[y].insert(mt(Z[x]-e[id].lim,x,id));
				r[y].insert(mt(Z[x]+e[id].lim,x,id));
				continue;
			}
			else it=g[x].erase(it),e[id].v=i;
		}
	}
	G::build();
	int _;scanf("%lld",&_);
	while(_--)
	{
		int x,y,z;scanf("%lld%lld",&x,&y);
		printf("%lld\n",(z=(int)G::query(x,y))>k?-1ll:z);
	}
}
signed main()
{
	int _;scanf("%lld",&_);
	while(_--)solve();
	return 0;
}
/*
1
4
0 0
0 12
0 24
0 25
3
1 2 13
2 3 13
3 4 1
4
3 1
2 6
3 1
2 -6
4
1 2
2 3
3 4
1 4
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 380ms
memory: 145828kb

input:

389
686
10357458 -45685083
-13525616 -46849548
13245371 -52959727
1533241 -47731445
29767995 -57009848
8709026 -49429890
-10596975 -37749761
-2292572 -57107130
-9505231 -38312854
-61987063 -5380598
31126084 -56985867
2632716 -48068309
17172532 -54294658
-9557851 -38286352
12761654 -53122994
16653770...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 139675 lines

Test #2:

score: 0
Accepted
time: 14909ms
memory: 653848kb

input:

2
500000
14564495 88542502
14369974 88737023
14295451 88811546
14576134 88530863
14275155 88831842
14376399 88730598
14495717 88611280
14627448 88479549
14409262 88697735
14197920 88909077
14514752 88592245
14230630 88876367
14593804 88513193
14254688 88852309
14446490 88660507
14601040 88505957
143...

output:

499999
499999
499999
362592
499999
499999
499999
499999
499999
499999
500000
499999
499999
499999
500000
499999
499999
500000
500000
500000
499999
499999
499999
499999
499999
499999
499999
499999
499999
499999
499999
499999
499999
499999
499999
499999
499999
499999
499999
499999
499999
499999
500000...

result:

ok 1000000 lines

Test #3:

score: 0
Accepted
time: 13234ms
memory: 851572kb

input:

2
500000
-19378149 -1495147
-63216117 1581244
-19385210 -1493025
-19413444 -1485172
-19378687 -1494837
-19385262 -1493222
-19416893 -1484193
-19382610 -1493888
-19394475 -1490854
-19389700 -1492007
-19368978 -1497516
-19411475 -1485807
-19409427 -1486310
-19410593 -1486127
-19398571 -1489556
-194185...

output:

-1
-1
-1
-1
-1
-1
287736
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
438438
-1
-1
-1
426237
434139
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
343746
-1
-1
-1
228939
-1
-1
263585
-1
-1
-1
-1
-1
-1
491977
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
108087
-1
-1
-1
...

result:

ok 700000 lines

Test #4:

score: 0
Accepted
time: 18650ms
memory: 656128kb

input:

2
500000
-14328778 23720400
-14328778 23760511
-14328778 23608513
-14328778 23472063
-14328778 23478531
-14328778 23831736
-14328778 23498966
-14328778 23429182
-14328778 23466244
-14328778 23663462
-14328778 23798751
-14328778 23731882
-14328778 23476840
-14328778 23514441
-14328778 23747035
-14328...

output:

451240
397300
-1
331036
363448
166109
-1
352060
-1
424519
-1
-1
-1
250539
-1
152767
-1
474347
300896
306646
185236
417574
493445
-1
442324
414082
379274
414954
-1
178698
120502
-1
120599
396406
-1
325710
350531
304703
485967
498734
165205
406031
-1
397300
335709
-1
323677
386421
399220
393304
23021
...

result:

ok 1000000 lines