QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#127182#5113. BridgeshenxingeTL 2ms32364kbC++141.6kb2023-07-19 13:53:302023-07-19 13:54:03

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-19 13:54:03]
  • 评测
  • 测评结果:TL
  • 用时:2ms
  • 内存:32364kb
  • [2023-07-19 13:53:30]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
constexpr int maxn(5e5+10);
struct link_cut_tree{
	int ch[maxn][2],f[maxn];
	#define ls ch[x][0]
	#define rs ch[x][1]
	#define get(x) (ch[f[x]][1]==x)
	inline bool nroot(int x){return (ch[f[x]][0]==x||ch[f[x]][1]==x);}
	inline void rotate(int x){
		int fa=f[x],ffa=f[fa],k=get(x),w=ch[x][!k];
		if(nroot(fa)) ch[ffa][get(fa)]=x;
		ch[x][!k]=fa,ch[fa][k]=w;if(w) f[w]=fa;
		f[x]=ffa,f[fa]=x;
	}
	inline void Splay(int x){for(int y=0;y=f[x],nroot(x);rotate(x))if(nroot(y)) rotate(get(x)==get(y)?y:x);}
	inline void access(int x){for(int y=0;x;x=f[y=x]) Splay(x),rs=y;}
	inline void link(int x,int y){access(x),Splay(x),f[x]=y;}
	inline void cut(int x,int y){access(x),Splay(x),f[ls]=ls=0;}
	inline int findroot(int x){access(x),Splay(x);while(ls) x=ls;Splay(x);return x;}
}lct;
int n,m,q,col[maxn],nxt[maxn],colcnt=1;
map<int,int> mp[maxn];
inline void link(int u,int v){
	if(nxt[u]) lct.cut(u,nxt[u]);
	nxt[u]=v,lct.link(u,v);
}
signed main(){
	ios::sync_with_stdio(false),cin.tie(nullptr);
	cin >> n >> m >> q;
	for(int op,a,b;q--;){cin >> op >> a;
		if(op==1){cin >> b;
			int x=++colcnt,y=++colcnt;col[x]=a,col[y]=a+1,mp[a][b]=x,mp[a+1][b]=y;
			auto it1=mp[a].lower_bound(b),it2=mp[a+1].lower_bound(b);
			if(it1!=mp[a].begin()) link(prev(it1)->second,y);
			if(next(it1)!=mp[a].end()) link(x,next(it1)->second^1);
			if(it2!=mp[a+1].begin()) link(prev(it2)->second,x);
			if(next(it2)!=mp[a+1].end()) link(y,next(it2)->second^1);
		}else{
			if(mp[a].empty()) cout << a << '\n';
			else cout << col[lct.findroot(mp[a].begin()->second^1)] << '\n';
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 32364kb

input:

3 4 13
2 2
1 1 3
2 1
2 2
2 3
1 2 4
2 1
2 2
2 3
1 2 1
2 1
2 2
2 3

output:

2
2
1
3
3
1
2
3
2
1

result:

ok 10 numbers

Test #2:

score: -100
Time Limit Exceeded

input:

3 100000 99997
2 2
2 2
2 3
2 3
2 3
2 3
2 3
1 2 11047
1 1 98732
1 2 90045
1 1 43556
2 1
2 3
1 2 17242
1 1 17027
2 1
1 1 94195
2 1
2 2
2 1
2 3
1 1 34124
1 2 14354
1 2 673
1 2 39812
1 2 35520
1 2 16046
2 3
2 2
1 1 25410
2 3
2 1
2 3
2 2
1 2 55684
2 1
1 2 24811
1 2 92268
1 2 60268
2 2
1 1 89272
1 2 19232...

output:


result: