QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#77602 | #3029. The Great Drone Show | CharlieVinnie | AC ✓ | 11469ms | 802176kb | C++23 | 6.3kb | 2023-02-15 10:00:43 | 2023-02-15 10:00:46 |
Judging History
answer
#include "bits/stdc++.h"
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Rev(i,a,b) for(int i=a;i>=b;i--)
#define Fin(file) freopen(file,"r",stdin)
#define Fout(file) freopen(file,"w",stdout)
#define assume(expr) ((!!(expr))||(exit((fprintf(stderr,"Assumption Failed: %s on Line %d\n",#expr,__LINE__),-1)),false))
using namespace std;
#define fi first
#define se second
#define FASTIO_READ_NEGATIVE
namespace FastIO{
const int BUF_COUNT=10000000,BUF_SIZ=1<<25;
char in_buf[BUF_SIZ],*got_pos=in_buf,*read_pos=in_buf,out_buf[BUF_SIZ],*write_pos=out_buf;
inline char get_next_char(){if(read_pos==got_pos){got_pos=read_pos=in_buf;got_pos+=fread(got_pos,sizeof(char),BUF_COUNT,stdin);}return*(read_pos++);}
inline void flush_output(){fwrite(out_buf,sizeof(char),write_pos-out_buf,stdout);write_pos=out_buf;}
inline void put_char(char ch){*(write_pos++)=ch;if(write_pos==out_buf+BUF_SIZ)flush_output();}
#ifndef FASTIO_READ_NEGATIVE
template<typename T> inline void read(T& res){char ch;while(!isdigit(ch=get_next_char()));res=ch^'0';while(isdigit(ch=get_next_char()))res=(res<<3)+(res<<1)+(ch^'0');}
#else
template<typename T> inline void read(T& res){char ch;bool flg=0;while(!isdigit(ch=get_next_char()))flg|=ch=='-';res=ch^'0';while(isdigit(ch=get_next_char()))res=(res<<3)+(res<<1)+(ch^'0');if(flg)res=-res;}
#endif
template<typename T> inline void write(T x){if(!x){put_char('0');return;}static int lis[25],*lp=lis;while(x){*(++lp)=x%10;x/=10;}while(lp!=lis)put_char((*(lp--))+'0');}
template<typename T> inline void writeln(const T& x){write(x);put_char('\n');}
template<typename T> inline void writesp(const T& x){write(x);put_char(' ');}
class _IO_Flusher{public:~_IO_Flusher(){flush_output();}}__Flusher;
class IStream{public:
template<typename T> inline IStream& operator>>(T& x){read(x);return *this;}
inline IStream& operator>>(char* str){char ch;while(isspace(ch=get_next_char()));(*(str++))=ch;while(!isspace(ch=get_next_char())){if(ch==EOF)break;(*(str++))=ch;}return *this;}
}Cin;
class OStream{public:
inline OStream& operator<< (const int& x){if(x>=0)write(x);else put_char('-'),write(-x);return *this;}
inline OStream& operator<< (const long long& x){if(x>=0)write(x);else put_char('-'),write(-x);return *this;}
inline OStream& operator<< (const char& ch){put_char(ch);return *this;}
inline OStream& operator<< (const char* str){for(const char* p=str;*p;put_char(*(p++)));return *this;}
}Cout;
}
using namespace FastIO;
#define cin Cin
#define cout Cout
const int N=3e6+5,M=3e6+5; typedef long long ll; using pii = pair<int,int>;
class KruskalTree{
struct Edge { int x,y,z; bool operator< (const Edge& e) const { return z>e.z; } } ed[M];
int n,m,pa[N],val[N],fa[N][21],dep[N];
int getfa(int x) { return x==pa[x]?x:pa[x]=getfa(pa[x]); }
public:
void init(int _n) { For(i,1,n) { pa[i]=val[i]=dep[i]=0; For(j,0,21) fa[i][j]=0; } n=_n; m=0; }
void add_edge(int x,int y,int z) { ed[++m]=Edge{x,y,z}; }
void build(){
sort(ed+1,ed+1+m); For(i,1,n) pa[i]=i;
For(i,1,m){
int x=getfa(ed[i].x),y=getfa(ed[i].y); if(x==y) continue;
n++; val[n]=ed[i].z; pa[n]=pa[x]=pa[y]=n; fa[x][0]=fa[y][0]=n;
}
Rev(u,n,1) dep[u]=dep[fa[u][0]]+1;
For(i,1,20) For(u,1,n) fa[u][i]=fa[fa[u][i-1]][i-1];
}
int query(int x,int y){
if(dep[x]<dep[y]) swap(x,y);
Rev(i,20,0) if(dep[fa[x][i]]>=dep[y]) x=fa[x][i];
if(x==y) return val[x];
Rev(i,20,0) if(fa[x][i]!=fa[y][i]) x=fa[x][i],y=fa[y][i];
return val[fa[x][0]];
}
}T;
struct Seg { int l,r,x; } ;
struct Cmp1 { bool operator() (const Seg& A,const Seg& B) const { return A.l!=B.l?A.l<B.l:A.x<B.x; } } ;
struct Cmp2 { bool operator() (const Seg& A,const Seg& B) const { return A.r!=B.r?A.r<B.r:A.x<B.x; } } ;
int n,m,Q,Q2,X[N],Y[N],Z[N],vis[N],deg[N],head[N],nxt[M],to[M],edge[M],tot; vector<pii> fa[N]; set<Seg,Cmp1> st1[N]; set<Seg,Cmp2> st2[N]; map<pii,int> done;
// inline ll Sqrt(ll x) { assume(x>=0); ll y=max(sqrtl(x)-1,0.0L); while(y*y<=x) y++;; return y-1; }
inline ll Sqrt(ll x) { return sqrtl(x); }
inline Seg getseg(int u,int v,int z) { int s=Sqrt(1ll*z*z-1ll*(X[u]-X[v])*(X[u]-X[v])-1ll*(Y[u]-Y[v])*(Y[u]-Y[v])); return Seg{Z[u]-s,Z[u]+s,u}; }
inline void add_edge(int x,int y,int z) { nxt[++tot]=head[x]; head[x]=tot; to[tot]=y; edge[tot]=z; }
void Erase(int u,int v,int t) { done[pii(u,v)]=t; }
int QQQ,_X[N],_Y[N],_Z[N],_U[N],_H[N];
void solve(){
cin>>n; For(i,1,n) cin>>X[i]>>Y[i],Z[i]=0,head[i]=0,fa[i].clear(),st1[i].clear(),st2[i].clear();
cin>>m; tot=1; For(i,1,m) { int x,y,z; cin>>x>>y>>z; _X[i]=x; _Y[i]=y; _Z[i]=z; add_edge(x,y,z); add_edge(y,x,z); deg[x]++; deg[y]++; }
priority_queue<pii> q; For(i,1,n) vis[i]=0,q.emplace(-deg[i],i);
while(q.size()) { int u=q.top().second; q.pop(); if(vis[u]) continue;; vis[u]=1; for(int e=head[u],v=to[e];e;e=nxt[e],v=to[e]) if(!vis[v]) deg[v]--,q.emplace(-deg[v],v),fa[u].emplace_back(v,edge[e]); }
For(u,1,n) for(auto pr:fa[u]) { Seg sg=getseg(u,pr.fi,pr.se); st1[pr.fi].insert(sg); st2[pr.fi].insert(sg); }
cin>>Q; done.clear(); For(TT,1,Q){
int u,hh; cin>>u>>hh; Z[u]+=hh; _U[TT]=u; _H[TT]=hh;
while(st1[u].size()&&prev(st1[u].end())->l>Z[u]) { Seg sg=*--st1[u].end(); Erase(u,sg.x,TT); st1[u].erase(sg); st2[u].erase(sg); }
while(st2[u].size()&&st2[u].begin()->r<Z[u]) { Seg sg=*st2[u].begin(); Erase(u,sg.x,TT); st1[u].erase(sg); st2[u].erase(sg); }
for(auto pr:fa[u]) if(!done.count(pii(pr.fi,u))){
int p=pr.fi; Z[u]-=hh; Seg sg=getseg(u,p,pr.se); st1[p].erase(sg); st2[p].erase(sg);
Z[u]+=hh; sg=getseg(u,p,pr.se); if(sg.l<=Z[p]&&Z[p]<=sg.r) st1[p].insert(sg),st2[p].insert(sg); else Erase(p,u,TT);
}
}
For(u,1,n) for(auto pr:fa[u]) if(!done.count(pii(pr.fi,u))) done[pii(pr.fi,u)]=Q+1;
T.init(n); for(auto ed:done) T.add_edge(ed.fi.fi,ed.fi.se,ed.se);; T.build();
cin>>Q2; while(Q2--) { int x,y; cin>>x>>y; int res=T.query(x,y); if(res>Q) res=-1;; cout<<res<<'\n'; }
}
signed main(){
// Fin("hh.in"); Fout("hh.out");
int Ti; cin>>Ti; while(Ti--) solve();
cerr<<"Time = "<<clock()<<" ms"<<endl;
return 0;
}
// START TYPING IF YOU DON'T KNOW WHAT TO DO
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 417ms
memory: 365568kb
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: 11347ms
memory: 740088kb
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: 11469ms
memory: 802176kb
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: 10541ms
memory: 744080kb
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