分析

裸的二维数点,博主用树状数组套平衡树写的,顺便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. Mac020--常用插件

    Google浏览器常用插件 1.github插件octotree 2.掘金Chrome网上应用商店 2-1.掘金/老司机的神兵利器 2-2.好用的Google插件:来自掘金 3.Gliffy Diag ...

  2. [Git] 016 远程仓库篇 第三话 删除远程仓库

    1. 来到自己的 GitHub 页面,先点右上角自己的头像,再点 "Your profile" 2. 选择自己的某个远程仓库,我选 "git_skills" 3 ...

  3. [Vim] 01 凡人操作

    历史评价 编辑器之神 一个凡人的自我修养 成神是不可能成神的,只能是先入个门,然后一点一点学 Vim 官网 三种模式 插入模式(注意看光标) 命令模式(注意看光标) 编辑模式(注意看光标) 其实还有一 ...

  4. 极*Java速成教程 - (8)

    Java高级特性 注解 注解可以在代码之外添加更多的信息,更加完整地描述程序,帮助编译器进行工作,或者实现某些特定的Java代码之外的功能. 注解可以简化某些重复的流程,自动化那些过程. 注解的使用 ...

  5. Fedora添加软件桌面快捷方式

    以下以添加Eclipse为例 在桌面上新建Eclipse.desktop 文件,向其写入如下代码 [Desktop Entry] Name=Eclipse Comment=用Eclipse开发 Exe ...

  6. [LeetCode] 103. 二叉树的锯齿形层次遍历

    题目链接 : https://leetcode-cn.com/problems/binary-tree-zigzag-level-order-traversal/ 题目描述: 给定一个二叉树,返回其节 ...

  7. 各种IE(IE6-IE10)兼容问题一行代码搞定

    x-ua-compatible 用来指定IE浏览器解析编译页面的model x-ua-compatible 头标签大小写不敏感,必须用在 head 中,必须在除 title 外的其他 meta 之前使 ...

  8. Huawei交换机路由器远程Telnet配置

    <huawei>system-view Enter system view, return user view with Ctrl+Z.[huawei]interface g0/0/0[h ...

  9. Docker数据目录相关操作

    数据目录挂载 我们可以在创建容器的时候,将宿主机的目录与容器内的目录进行映射,这样我们就可以通过修改宿主机某个目录的文件从而去影响容器.使用 -v 选项 docker run -id -v /宿主机绝 ...

  10. ASSERT()断言

    头文件<assert.h>   作用:用于判断是否有非法的数据,有则程序报告错误,终止运行.(注意是非法情况,而不是错误情况)   ASSERT()和assert()的区别: ASSERT ...