QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#439568#6872. Magma CaveAcoippWA 2520ms44576kbC++143.8kb2024-06-12 11:31:572024-06-12 11:31:58

Judging History

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

  • [2024-06-12 11:31:58]
  • 评测
  • 测评结果:WA
  • 用时:2520ms
  • 内存:44576kb
  • [2024-06-12 11:31:57]
  • 提交

answer

#include<bits/stdc++.h>
#define ll int
#define inf 0x3f3f3f3f
#define get(x) (tr[tr[x].fa].ch[1]==x)
#define isroot(p) (tr[tr[p].fa].ch[0]!=p&&tr[tr[p].fa].ch[1]!=p)
#define N 100005
#define Q 1000005
using namespace std;
inline char nc(){
	static char buf[1000000],*p=buf,*q=buf;
	return p==q&&(q=(p=buf)+fread(buf,1,1000000,stdin),p==q)?EOF:*p++;
}
inline ll read(){
	ll res = 0;
	char c = nc();
	while(c<'0'||c>'9')c=nc();
	while(c<='9'&&c>='0')res=res*10+c-'0',c=nc();
	return res;
}
char obuf[1<<21],*p3=obuf; 
inline void pc(char c){ 
	p3-obuf<=(1<<20)?(*p3++=c):(fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=c); 
} 
inline void write(ll x){ 
	if(x<0) pc('-'),x=-x; 
	if(x>9) write(x/10); 
	pc(x%10+'0'); 
}
ll T,n,m,q,opt,u,v,w,vis[Q];
struct poly{ll x,y,z;};
inline poly max(poly a,poly b,poly c){
	if(a.z>=b.z&&a.z>=c.z) return a;
	if(b.z>=a.z&&b.z>=c.z) return b;
	return c;
}
struct node{ll ch[2],tag,fa;poly val,p;}emp;
struct bit{
	ll tr[Q];
	inline void add(ll k,ll x){
		while(k<=q) tr[k]+=x,k+=k&(-k);
	}
	inline ll query(ll k){
		ll num = 0;
		while(k) num+=tr[k],k-=k&(-k);
		return num;
	}
};
struct lct{
	ll m;
	node tr[N];
	map<ll,ll> maps[N];
	bit bitt;
	inline void pushup(ll p){tr[p].p = max(tr[tr[p].ch[0]].p,tr[tr[p].ch[1]].p,tr[p].val);}
	inline void pushtag(ll p){
		if(!p) return ;
		swap(tr[p].ch[0],tr[p].ch[1]),tr[p].tag^=1;
	}
	inline void pushdown(ll p){if(tr[p].tag) pushtag(tr[p].ch[0]),pushtag(tr[p].ch[1]),tr[p].tag=0;}
	inline void upd(ll p){pushup(p);if(!isroot(p)) upd(tr[p].fa);pushdown(p);}
	inline void rotate(ll p){
		ll y=tr[p].fa,z=tr[y].fa,k=get(p);
		if(!isroot(y)) tr[z].ch[tr[z].ch[1]==y]=p;
		tr[y].ch[k]=tr[p].ch[!k],tr[tr[p].ch[!k]].fa=y,tr[p].ch[!k]=y,tr[y].fa=p,tr[p].fa=z;
		pushup(y),pushup(p);
	}
	inline void splay(ll p){
		upd(p);
		for(ll f;f=tr[p].fa,!isroot(p);rotate(p)) if(!isroot(f)) rotate(get(f)==get(p)?f:p);
	}
	inline ll access(ll p){
		ll i;
		for(i=0;p;i=p,p=tr[p].fa) splay(p),tr[p].ch[1]=i,pushup(p);
		return i;
	}
	inline void makeroot(ll p){pushdown(p),access(p),splay(p),pushtag(p),pushup(p);}
	inline void link(ll x,ll y){
		makeroot(x),splay(x),tr[x].fa=y,pushup(x),pushup(y);
	}
	inline void cut(ll x,ll y){
		makeroot(x),access(y),splay(y),tr[x].fa=0,tr[y].ch[0]=0,pushup(x),pushup(y);
	}
	inline ll find(ll p){
		access(p),splay(p),pushdown(p);
		while(tr[p].ch[0]) p=tr[p].ch[0],pushdown(p);
		splay(p);
		return p;
	}
	inline poly query(ll x,ll y){return makeroot(x),access(y),splay(y),tr[y].p;}
	inline void add(ll u,ll v,ll w){
		if(find(u)!=find(v)){
			m++,tr[m].val = tr[m].p = (poly){u,v,w},link(u,m),link(m,v);
			bitt.add(w,1);
			maps[u][v] = maps[v][u] = m;
			return ;
		}
		poly res = query(u,v);
		if(res.z>w){
			ll id = maps[res.x][res.y];
			bitt.add(res.z,-1),bitt.add(w,1),maps[res.x][res.y] = maps[res.y][res.x] = 0,maps[u][v] = maps[v][u] = id;
			cut(res.x,id),cut(id,res.y),tr[id].val = tr[id].p = (poly){u,v,w},link(u,id),link(id,v);
		}
	}
	inline void clear(){
		for(ll i=1;i<=q;i++) bitt.tr[i]=0;
		for(ll i=1;i<=m;i++) tr[i]=emp;
		for(ll i=1;i<=n;i++) maps[i].clear();
	}
}lct1,lct2;
inline void add(ll u,ll v,ll w){
	vis[w] = 1,lct1.add(u,v,w),lct2.add(u,v,q-w+1);
}
inline void solve(){
	n=read(),q=read(),lct1.m = n,lct2.m = n;
	for(ll i=1;i<=q;i++){
		opt=read();
		if(opt==1) u=read(),v=read(),w=read(),add(u,v,w);
		else{
			u=read(),w=read();
			if(lct1.m==2*n-1&&vis[w]&&lct1.bitt.query(w)>=u&&n-1-lct2.bitt.query(q-w+1)<=u) pc('Y'),pc('E'),pc('S'),pc('\n');
			else pc('N'),pc('O'),pc('\n');
		}
	}
}
inline void clear(){
	for(ll i=1;i<=q;i++) vis[i]=0;
	lct1.clear(),lct2.clear();
}
int main(){
//	freopen("1.in","r",stdin);
	T=read();
	while(T--){
		solve();
		clear();
	}
	return fwrite(obuf,p3-obuf,1,stdout),0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2520ms
memory: 44576kb

input:

100
500 1999
1 112 419 318
1 419 208 1700
1 208 255 603
1 255 202 306
1 202 54 326
1 54 468 1506
1 468 23 856
1 23 90 758
1 90 271 1104
1 271 442 1900
1 442 441 19
1 441 378 1227
1 378 466 24
1 466 186 228
1 186 399 1387
1 399 288 297
1 288 144 1763
1 144 418 1896
1 418 217 673
1 217 281 1259
1 281 ...

output:

NO
NO
YES
NO
YES
NO
NO
YES
YES
NO
YES
YES
NO
YES
YES
YES
NO
YES
NO
YES
YES
YES
YES
YES
YES
YES
NO
YES
NO
YES
NO
YES
YES
NO
YES
YES
NO
NO
NO
NO
NO
YES
YES
NO
NO
NO
YES
YES
NO
NO
YES
NO
NO
NO
YES
YES
YES
YES
NO
NO
YES
NO
YES
NO
NO
NO
YES
NO
YES
NO
NO
YES
NO
YES
NO
NO
YES
YES
YES
YES
NO
NO
NO
YES
YES
N...

result:

wrong answer 3rd lines differ - expected: 'NO', found: 'YES'