分析

裸的二维数点,博主用树状数组套平衡树写的,顺便pbds真好用。

Update on 2018/12/20:再解释一下为什么是二维数点,第一维是\(la \leq i \leq ra\),第二维是\(lb \leq c_i \leq rb\),其中\(c_i\)表示\(a\)中第\(i\)个数在\(b\)中出现的位置。

代码

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define lowbit(x) ((x)&(-(x)))
#define rin(i,a,b) for(int i=(a);i<=(b);i++)
#define rec(i,a,b) for(int i=(a);i>=(b);i--)
#define trav(i,a) for(int i=head[(a)];i;i=e[i].nxt)
typedef long long LL;
using namespace std;
using namespace __gnu_pbds; inline int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
return x*f;
} const int MAXN=200005;
int n,m,a[MAXN],b[MAXN],c[MAXN],ic[MAXN],pos[MAXN];
tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> rbt[MAXN]; inline void Ins(int x,int kk){
for(int i=x;i<=n;i+=lowbit(i)) rbt[i].insert(kk);
} inline void Del(int x,int kk){
for(int i=x;i<=n;i+=lowbit(i)) rbt[i].erase(kk);
} inline int Ask(int x,int lb,int rb){
int ret=0;
for(int i=x;i;i-=lowbit(i)){
auto it=rbt[i].lower_bound(lb);
if(it==rbt[i].end()) continue;
int bg=*it;
it=rbt[i].upper_bound(rb);
if(it==rbt[i].begin()) continue;
int ed=*(--it);
ret+=rbt[i].order_of_key(ed)-rbt[i].order_of_key(bg)+1;
}
return ret;
} inline int Ask(int la,int ra,int lb,int rb){
return Ask(ra,lb,rb)-Ask(la-1,lb,rb);
} int main(){
n=read(),m=read();
rin(i,1,n) a[i]=read();
rin(i,1,n) b[i]=read(),pos[b[i]]=i;
rin(i,1,n) c[i]=pos[a[i]],ic[pos[a[i]]]=i;
rin(i,1,n) Ins(i,c[i]);
while(m--){
int opt=read();
if(opt==1){
int la=read(),ra=read(),lb=read(),rb=read();
printf("%d\n",Ask(la,ra,lb,rb));
}
else{
int x=read(),y=read();
Del(ic[x],x);Del(ic[y],y);
Ins(ic[x],y);Ins(ic[y],x);
swap(ic[x],ic[y]);
}
}
return 0;
}

[CF1093E]Intersection of Permutations:树套树+pbds的更多相关文章

  1. CF1093E Intersection of Permutations 树状数组套权值线段树

    \(\color{#0066ff}{ 题目描述 }\) 给定整数 \(n\) 和两个 \(1,\dots,n\) 的排列 \(a,b\). \(m\) 个操作,操作有两种: \(1\ l_a\ r_a ...

  2. Educational Codeforces Round 56 (Rated for Div. 2) E(1093E) Intersection of Permutations (树套树,pb_ds)

    题意和分析在之前的链接中有:https://www.cnblogs.com/pkgunboat/p/10160741.html 之前补题用三维偏序的cdq的分治A了这道题,但是感觉就算比赛再次遇到类似 ...

  3. Codeforces 1093E Intersection of Permutations (CDQ分治+树状数组)

    题意:给你两个数组a和b,a,b都是一个n的全排列:有两种操作:一种是询问区间在数组a的区间[l1,r1]和数组b的区间[l2,r2]出现了多少相同的数字,另一种是交换数组b中x位置和y位置的数字. ...

  4. [CF1093E]Intersection of Permutations

    [CF1093E]Intersection of Permutations 题目大意: 给定两个长度为\(n(n\le2\times10^5)\)的排列\(A,B\).\(m(m\le2\times1 ...

  5. BZOJ 3110: [Zjoi2013]K大数查询 [树套树]

    3110: [Zjoi2013]K大数查询 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 6050  Solved: 2007[Submit][Sta ...

  6. BZOJ4170 极光(CDQ分治 或 树套树)

    传送门 BZOJ上的题目没有题面-- [样例输入] 3 5 2 4 3 Query 2 2 Modify 1 3 Query 2 2 Modify 1 2 Query 1 1 [样例输出] 2 3 3 ...

  7. bzoj3262: 陌上花开(树套树)

    #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...

  8. bzoj3295: [Cqoi2011]动态逆序对(树套树)

    #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...

  9. BZOJ 3110 k大数查询 & 树套树

    题意: 有n个位置,每个位置可以看做一个集合,现在要求你实现一个数据结构支持以下功能: 1:在a-b的集合中插入一个数 2:询问a-b集合中所有元素的第k大. SOL: 调得火大! 李建说数据结构题能 ...

  10. BZOJ 3110 树套树 && 永久化标记

    感觉树套树是个非常高深的数据结构.从来没写过 #include <iostream> #include <cstdio> #include <algorithm> ...

随机推荐

  1. 【Qt开发】几个傻不拉几关于char*和const char*的不兼容问题

    1. string转const char* string s ="abc";constchar* c_s = s.c_str(); 2. const char*转string   ...

  2. swagger @ApiModel添加实体类不生效

    在使用swagger时, 以为加上@ApiModel在实体类上就可以在swagger-ui.html的Models里面显示. 但是我创建了很多实体类, 但怎么也只显示了一个??? Models中无论如 ...

  3. 安装开发环境vs2017+sql2016+tfs2017

    安装开发环境vs2017+sql2016+tfs2017 编写人:左丘文 2019-7-16 近一年了,一直没空着手写点什么,跟大家交待下吧,去年一次机会,其实也不完全是去年,因此离开了我工作15年的 ...

  4. 创建MySQL数据库账号

    为本项目创建数据库用户(不再使用root账户) create user 账号 identified by '密码'; grant all on 数据库.* to '用户'@'%'; flush pri ...

  5. P2510 [HAOI2008]下落的圆盘

    传送门 首先考虑两个圆覆盖的情况,我们可以求出圆心与交点连线 $A$ 的极角 具体就是求出两圆心连线 $B$ 极角加上余弦定理加反余弦求出 $A,B$ 之间夹角 ,然后覆盖了多少就可以得出 但是多个圆 ...

  6. iOS微信浏览器回退不刷新(监听浏览器回退事件)

    兼容性:兼容全部ios系统 $(function(){ pushHistory(); }); function pushHistory(){ window.addEventListener(" ...

  7. vue(js)点击目标div以外区域将目标div隐藏

    今天开发新项目的时候,有个需求,点击一个div 展示出个弹出窗 弹出窗标题的颜色要跟点击的div图标颜色一致, 所以这就需要我遍历一下多个数据, 然后需要点击弹出div的外部其他区域,隐藏这个div. ...

  8. Java程序员集合框架面试题

    Java集合框架是最常被问到的Java面试问题,要理解Java技术强大特性,就有必要掌握集合框架.这里有一些实用问题,常在Java面试中问到. 1. 什么是Java集合API Java集合框架API是 ...

  9. Taro -- 文字左右滚动公告效果

    文字左右滚动公告效果 设置公告的左移距离,不断减小,当左移距离大于公告长度(即公告已移出屏幕),重新循环. <View className='scroll-wrap'> <View ...

  10. 一、.net Core bundleconfig.json

    一.bundleconfig.json [ { "outputFileName": "wwwroot/css/site.min.css", "inpu ...