QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#78200 | #3029. The Great Drone Show | AFewSuns | AC ✓ | 10832ms | 911920kb | C++14 | 6.1kb | 2023-02-17 11:18:20 | 2023-02-17 11:18:21 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
namespace my_std{
#define ll long long
#define bl bool
ll my_pow(ll a,ll b,ll mod){
ll res=1;
if(!b) return 1;
while(b){
if(b&1) res=(res*a)%mod;
a=(a*a)%mod;
b>>=1;
}
return res;
}
ll qpow(ll a,ll b){
ll res=1;
if(!b) return 1;
while(b){
if(b&1) res*=a;
a*=a;
b>>=1;
}
return res;
}
#define db double
#define pf printf
#define pc putchar
#define fr(i,x,y) for(register ll i=(x);i<=(y);i++)
#define pfr(i,x,y) for(register ll i=(x);i>=(y);i--)
#define go(u) for(ll i=head[u];i;i=e[i].nxt)
#define enter pc('\n')
#define space pc(' ')
#define fir first
#define sec second
#define MP make_pair
#define il inline
#define inf 8e18
#define random(x) rand()*rand()%(x)
#define inv(a,mod) my_pow((a),(mod-2),(mod))
il ll read(){
ll sum=0,f=1;
char ch=0;
while(!isdigit(ch)){
if(ch=='-') f=-1;
ch=getchar();
}
while(isdigit(ch)){
sum=sum*10+(ch^48);
ch=getchar();
}
return sum*f;
}
il void write(ll x){
if(x<0){
x=-x;
pc('-');
}
if(x>9) write(x/10);
pc(x%10+'0');
}
il void writeln(ll x){
write(x);
enter;
}
il void writesp(ll x){
write(x);
space;
}
}
using namespace my_std;
set<pair<pair<ll,ll>,pair<ll,ll> > > sl[500050],sr[500050];
set<pair<pair<ll,ll>,pair<ll,ll> > >::iterator it;
set<pair<ll,ll> > s;
vector<pair<ll,ll> > vec[500050];
ll t,n,m,k,q,head[500050],cnt=1,d[500050],tot=0;
ll mp[500050][11];
bl ck[500050],pd[500050][11];
struct Node{
ll x,y,z;
}a[500050];
struct node{
ll nxt,to,w;
}e[3000030];
struct edge{
ll u,v,t;
}E[1500015];
il bl cmp(edge x,edge y){
return x.t>y.t;
}
void add(ll u,ll v,ll ww){
e[++cnt].nxt=head[u];
e[cnt].to=v;
e[cnt].w=ww;
head[u]=cnt;
}
struct kruskal{
ll head[1000010],cnt=0,fa[1000010],tott=0;
ll dep[1000010],f[1000010][22],minn[1000010][22];
node e[1000010];
void add(ll u,ll v,ll ww){
e[++cnt].nxt=head[u];
e[cnt].to=v;
e[cnt].w=ww;
head[u]=cnt;
}
ll find(ll x){
if(x==fa[x]) return x;
return fa[x]=find(fa[x]);
}
void clr(){
fr(i,1,tott) head[i]=0;
cnt=0;
fr(i,1,tott) dep[i]=0;
fr(i,1,tott) fr(j,0,20) f[i][j]=0;
tott=0;
}
void dfs(ll faa,ll u){
dep[u]=dep[faa]+1;
f[u][0]=faa;
fr(i,1,20) f[u][i]=f[f[u][i-1]][i-1];
fr(i,1,20) minn[u][i]=min(minn[u][i-1],minn[f[u][i-1]][i-1]);
go(u){
ll v=e[i].to;
minn[v][0]=e[i].w;
dfs(u,v);
}
}
ll get_ans(ll x,ll y){
ll ans=inf;
if(dep[x]<dep[y]) swap(x,y);
pfr(i,20,0){
if(dep[f[x][i]]>=dep[y]){
ans=min(ans,minn[x][i]);
x=f[x][i];
}
}
if(x==y) return ans;
pfr(i,20,0){
if(f[x][i]!=f[y][i]){
ans=min(ans,minn[x][i]);
ans=min(ans,minn[y][i]);
x=f[x][i];
y=f[y][i];
}
}
ans=min(ans,minn[x][0]);
ans=min(ans,minn[y][0]);
return ans;
}
void solve(){
fr(i,1,n) fa[i]=i;
tott=n;
sort(E+1,E+m+1,cmp);
fr(i,1,m){
ll x=find(E[i].u),y=find(E[i].v);
if(x==y) continue;
tott++;
fa[tott]=tott;
add(tott,x,E[i].t);
add(tott,y,E[i].t);
fa[x]=tott;
fa[y]=tott;
}
minn[tott][0]=inf;
fr(i,0,20) minn[0][i]=inf;
dfs(0,tott);
q=read();
while(q--){
ll u=read(),v=read(),ans=get_ans(u,v);
if(ans==inf) writeln(-1);
else writeln(ans);
}
}
}T;
il pair<ll,ll> calc(ll x,ll y,ll w){
ll tmp=w*w-(a[x].x-a[y].x)*(a[x].x-a[y].x)-(a[x].y-a[y].y)*(a[x].y-a[y].y);
if(tmp<0) return MP(-inf,-inf);
ll res=sqrt(tmp);
while((res+1)*(res+1)<=tmp) res++;
while(res*res>tmp) res--;
return MP(a[y].z-res,a[y].z+res);
}
void clr(){
T.clr();
fr(i,1,n) head[i]=0;
cnt=1;
fr(i,1,n){
sl[i].clear();
sr[i].clear();
vec[i].clear();
}
s.clear();
fr(i,1,n) d[i]=0;
tot=0;
fr(i,1,n) ck[i]=0;
fr(i,1,n) fr(j,0,6) pd[i][j]=0;
fr(i,1,n) a[i].z=0;
}
int main(){
t=read();
while(t--){
n=read();
fr(i,1,n){
a[i].x=read();
a[i].y=read();
}
m=read();
fr(i,1,m){
E[i].u=read();
E[i].v=read();
E[i].t=inf;
ll l=read();
add(E[i].u,E[i].v,l);
add(E[i].v,E[i].u,l);
d[E[i].u]++;
d[E[i].v]++;
}
fr(i,1,n) s.insert(MP(d[i],i));
fr(_,1,n){
pair<ll,ll> tmp=*s.begin();
s.erase(tmp);
ll u=tmp.sec;
ck[u]=1;
go(u){
ll v=e[i].to;
if(ck[v]) continue;
vec[u].push_back(MP(v,e[i].w));
mp[u][vec[u].size()-1]=i/2;
s.erase(MP(d[v],v));
d[v]--;
s.insert(MP(d[v],v));
}
d[u]=0;
}
fr(i,1,n){
fr(j,0,(ll)vec[i].size()-1){
ll u=vec[i][j].fir;
pair<ll,ll> tmp=calc(u,i,vec[i][j].sec);
sl[u].insert(MP(tmp,MP(i,j)));
swap(tmp.fir,tmp.sec);
sr[u].insert(MP(tmp,MP(i,j)));
}
}
k=read();
fr(_,1,k){
ll u=read(),h=read();
fr(i,0,(ll)vec[u].size()-1){
if(pd[u][i]) continue;
ll x=vec[u][i].fir,w=vec[u][i].sec;
pair<ll,ll> now=calc(x,u,w);
sl[x].erase(MP(now,MP(u,i)));
swap(now.fir,now.sec);
sr[x].erase(MP(now,MP(u,i)));
}
a[u].z+=h;
fr(i,0,(ll)vec[u].size()-1){
if(pd[u][i]) continue;
ll x=vec[u][i].fir,w=vec[u][i].sec;
pair<ll,ll> now=calc(x,u,w);
if(a[x].z<now.fir||a[x].z>now.sec){
E[mp[u][i]].t=_;
pd[u][i]=1;
continue;
}
sl[x].insert(MP(now,MP(u,i)));
swap(now.fir,now.sec);
sr[x].insert(MP(now,MP(u,i)));
}
it=sl[u].lower_bound(MP(MP(a[u].z+1,-inf),MP(0,0)));
while(it!=sl[u].end()){
pair<ll,ll> now=(*it).fir;
ll v=(*it).sec.fir,id=(*it).sec.sec;
pd[v][id]=1;
E[mp[v][id]].t=_;
sl[u].erase(MP(now,MP(v,id)));
swap(now.fir,now.sec);
sr[u].erase(MP(now,MP(v,id)));
swap(now.fir,now.sec);
it=sl[u].lower_bound(MP(now,MP(v,id)));
}
it=sr[u].lower_bound(MP(MP(a[u].z-1,inf),MP(0,0)));
while(1){
if(it==sr[u].begin()) break;
it--;
pair<ll,ll> now=(*it).fir;
ll v=(*it).sec.fir,id=(*it).sec.sec;
pd[v][id]=1;
E[mp[v][id]].t=_;
sr[u].erase(MP(now,MP(v,id)));
swap(now.fir,now.sec);
sl[u].erase(MP(now,MP(v,id)));
swap(now.fir,now.sec);
it=sr[u].lower_bound(MP(now,MP(v,id)));
}
}
T.solve();
clr();
}
}
详细
Test #1:
score: 100
Accepted
time: 285ms
memory: 63852kb
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: 10492ms
memory: 784636kb
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: 10268ms
memory: 911920kb
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: 10832ms
memory: 773812kb
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