当前位置: 首页 > news >正文

P9358 [ICPC 2022 Xian R] Bridge

狗屎ds题。
写了一个平衡树调了一天没调明白。
转为写分块了。
依然不理解平衡树挂在哪里了。

#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define e_b emplace_back
#define p_b push_back
#define fir first
#define sec second
#define IOS ios::sync_with_stdio(0),cin.tie(0)
#define gc getchar
using namespace std;
const int N=1e5+5;
struct node{int sz,cnt,ch[2],fa,l,r,id;node(){l=r=sz=cnt=fa=ch[0]=ch[1]=0;}
}t[N<<1];
int tot;
void upd(int p){t[p].sz=t[t[p].ch[0]].sz+t[t[p].ch[1]].sz+t[p].cnt;}
void rotate(int p){int f=t[p].fa,ff=t[f].fa;bool k=(p==t[f].ch[1]),k1=(f==t[ff].ch[1]);int s=t[p].ch[k^1];t[f].ch[k]=s,t[s].fa=f,t[p].ch[k^1]=f,t[f].fa=p;t[ff].ch[k1]=p,t[p].fa=ff;
}
void splay(int p,int g){while(t[p].fa!=g){int f=t[p].fa,ff=t[f].fa;if(ff!=g)(f==t[ff].ch[0])^(p==t[f].ch[0])?rotate(p):rotate(f);rotate(p);}
}
int add(int fa,int l,int r,int id){t[++tot].sz=r-l+1,t[tot].cnt=r-l+1,t[tot].fa=fa,t[tot].l=l,t[tot].r=r,t[tot].id=id;return tot;}
int find(int k,int rt){int now=rt;while(1){if(k>=t[now].l){if(t[now].l<=k&&k<=t[now].r){splay(now,0);return now;}now=t[now].ch[1];}else now=t[now].ch[0];if(!now)return now;}
}
int lst(int rt){int now=rt;while(t[now].ch[1])now=t[now].ch[1];return t[now].id;
}
void split(int p,int k){int l=t[p].l,r=t[p].r,s=t[p].ch[1];int p2=add(p,k,r,t[p].id);t[p].r=k-1;if(s)t[s].fa=p2;t[p2].ch[1]=s;t[p].ch[1]=p2;upd(p),upd(p2);
}   
map<int,int>mp[N];
int n,m,q;
signed main(){IOS;cin>>n>>m>>q;m++;for(int i=1;i<=n;i++)add(0,1,m,i),mp[i][0]=i;while(q--){int op,x,b;cin>>op;if(op==1){cin>>x>>b;int y=x+1;auto k1=mp[x].upper_bound(b);k1--;int rx=k1->sec;auto k2=mp[y].upper_bound(b);k2--;int ry=k2->sec;splay(rx,0),splay(ry,0);int rt_x=find(b,rx),rt_y=find(b,rx);split(rt_x,b),split(rt_y,b);swap(t[rt_x].ch[1],t[rt_y].ch[1]);t[t[rt_x].ch[1]].fa=rt_x,t[t[rt_y].ch[1]].fa=rt_y;mp[x][b]=t[rt_y].ch[1],mp[y][b]=t[rt_x].ch[1];//mp[x][k1->fir]=rt_x,mp[y][k2->fir]=rt_y;}else{cin>>x;cout<<lst(x)<<'\n';}}
}
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define e_b emplace_back
#define p_b push_back
#define fir first
#define sec second
#define gc getchar
using namespace std;
const int N=1e5+5;
int rd(){int x=0,f=1;char c=gc();while(c>'9'||c<'0'){if(c=='-')f=-1;c=gc();}while(c<='9'&&c>='0')x=x*10+c-'0',c=gc();return x;
}
int fin[350][N],n,m,q,B,cb;
map<int,int>mp[N];
signed main(){n=rd(),m=rd(),q=rd();B=sqrt(m);cb=m/B+bool(m%B);for(int i=1;i<=n;i++)for(int j=0;j<=cb;j++)fin[j][i]=i;while(q--){int op,a,b;cin>>op>>a;if(op==1){cin>>b;int blk=(b-1)/B+1;int x=a,y=a+1;for(int i=b;i>(blk-1)*B;i--){if(mp[x].count(i))x=mp[x][i];if(mp[y].count(i))y=mp[y][i];}swap(fin[blk][x],fin[blk][y]);mp[a][b]=a+1,mp[a+1][b]=a;}else{//for(int i=1;i<=n;i++){for(int j=0;j<=cb;j++)cout<<fin[j][i]<<' ';cout<<'\n';}for(int i=0;i<=cb;i++)a=fin[i][a];cout<<a<<'\n';}}}

upd:一开始犯了跟永无乡一样的问题

http://www.jsqmd.com/news/379461/

相关文章:

  • 2026年可查实盘配资平台推荐:合规透明安全 - 资讯焦点
  • Spring Cloud 熔断降级实战:Sentinel 熔断策略与规则持久化
  • blender导出fbx没有贴图问题
  • 2026年广州家具搬运公司评测推荐榜单:告别搬家烦恼的实用指南 - 品牌推荐
  • 2026年耐介质腐蚀防护布TOP10厂商推荐榜 - 资讯焦点
  • 临沂有实力的橡胶木板材公司推荐 - 品牌推荐(官方)
  • 2026年度成熟GEO服务公司TOP7综合实力榜:AI搜索时代企业增长与选型深度指南 - 资讯焦点
  • 临沂诚信的橡胶木板材生产厂家哪家好 - 品牌推荐(官方)
  • ContextMenuManager 配置右键运行 python 脚本实现一键克隆仓库 - Higurashi
  • 2026年广州家电搬运公司评测推荐榜单:告别搬运烦恼,轻松开启新生活 - 品牌推荐
  • 2026年广州汉米尔顿手表维修评测推荐:非官方维修点选择指南与网点服务深度分析 - 品牌推荐
  • 2026年广州家电搬运公司推荐评测:告别搬运烦恼,专业团队如何选择? - 品牌推荐
  • 手把手部署mysql_exporter:打通MySQL与Prometheus监控链路
  • 2026年广州积家手表维修推荐评测:非官方维修点排行榜与售后网点选择指南 - 品牌推荐
  • 2026年广州积家手表维修网点推荐评测:非官方服务中心选择指南与避坑分析 - 品牌推荐
  • 真实生产案例:一次错误索引设计如何引发 MySQL 写性能雪崩
  • 2026年可查实盘配资平台分析与推荐 - 资讯焦点
  • 2026广东最新结婚五金批发TOP5推荐:优质厂商权威榜单发布,品质服务双优适配,助力婚嫁选购 - 品牌推荐2026
  • JWT 是 token 的一种格式,我的理解对吗?
  • 2026年广州家具搬运公司评测推荐:告别搬家烦恼,如何选择省心靠谱的服务商 - 品牌推荐
  • 2026年广州汉米尔顿手表维修推荐评测:非官方维修点榜单与售后网点服务指南 - 品牌推荐
  • 2026年广州家电搬运公司评测推荐:告别搬运烦恼,专业团队如何选择 - 品牌推荐
  • 2026年广州豪度手表维修推荐评测:非官方维修网点服务榜单与避坑指南 - 品牌推荐
  • 2026年广州豪度手表非官方维修网点推荐评测:面对维修难题如何选择可靠服务中心 - 品牌推荐
  • 2026广东最新黄金品牌生产厂家TOP5推荐:广州等地优质厂家直销权威榜单发布,覆盖多元场景,打造安心黄金消费体验 - 品牌推荐2026
  • 2026年广州豪利时手表维修推荐评测:非官方维修点榜单与售后网点服务指南 - 品牌推荐
  • 2026年广州豪度手表非官方维修网点推荐评测:寻找可靠售后服务的场景与痛点分析 - 品牌推荐
  • 临沂比较好的橡胶木板材源头厂家排行 - 品牌推荐(官方)
  • 2026年广州积家手表维修推荐评测:非官方维修点榜单与售后网点服务选择指南 - 品牌推荐
  • 数据脱敏与数据质量:如何确保脱敏后数据可用性