QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#329937 | #5113. Bridge | zjnnb | TL | 0ms | 11812kb | C++14 | 1.8kb | 2024-02-17 09:21:32 | 2024-02-17 09:21:32 |
Judging History
answer
#include <bits/stdc++.h>
#define ite set<node>::iterator
using namespace std;
const int N=1e5+3;
int n,son[N*3][2],f[N*3],tot,m,_;
struct node{
int l,r,fr,id;
bool operator <(const node &b)const{
return r<b.r;
}
}sum[N*3];
set<node>s[N];
int get(int x){
return x==son[f[x]][1]?1:0;
}void rotate(int x){
int fa=f[x],g=get(x),gfa=f[fa],gf=get(fa);
f[son[fa][g]=son[x][g^1]]=fa;
f[son[x][g^1]=fa]=x;
if(gfa) son[gfa][gf]=x;
f[x]=gfa;
}
void splay(int x){
for(int fa;fa=f[x];rotate(x))
if(f[fa]) rotate(get(fa)==get(x)?fa:x);
}
void ins(int u,int nw){
if(!son[u][1]){
son[u][1]=nw,f[nw]=u;
return;
}
while(true){
if(!son[u][0]){
son[u][0]=nw,f[nw]=u;
return;
}
u=son[u][0];
}
}
int split(int x,int y){
ite it=s[x].lower_bound(node{0,y,0,0});
splay(it->id);
if(it->r==y){
return it->id;
}
node l=*it,r=l;
l.r=y,
r.l=y+1,r.id=++tot;
sum[l.id]=l,sum[tot]=r;
s[x].erase(it);
s[x].insert(l);s[x].insert(r);
ins(l.id,r.id);
return l.id;
}
void change(int a,int b){
int x=split(a,b),y=split(a+1,b);
swap(son[x][1],son[y][1]);
f[son[x][1]]=x,f[son[y][1]]=y;
}
int query(int x){
int u=(*s[x].begin()).id;
splay(u);
// return 0;
while(son[u][1]){
u=son[u][1];
// cout<<sum[u].fr<<" "<<sum[u].l<<" "<<sum[u].r<<endl;
}
splay(u);
return sum[u].fr;
}
signed main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>n>>m>>_;tot=n;
for(int i=1;i<=n;i++) s[i].insert(node{1,m+1,i,i}),sum[i]=node{1,m+1,i,i};
int op,a,b;
while(_--){
cin>>op>>a;
if(op==1){
cin>>b;
change(a,b);
}
else cout<<query(a)<<"\n";
}
return 0;
}
/*
2 4 4
3 5 5
3 1 4
2 1 3
2 4 4
3 5 5
3 1 4
2 1 3
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;jkfgh
2 2
2 3
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 11812kb
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...