分析

裸的二维数点,博主用树状数组套平衡树写的,顺便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. Java 14 可能带来什么新特性?

    JDK/Java 13 在一个月前已经发布,该版本带来了 5 大新特性,笔者观察到其中的 Text Blocks(文本块)特性似乎被讨论最多. 文本块特性与常见的 Python "" ...

  2. 思维体操: HDU1287破译密码

    破译密码 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  3. 似乎在梦中见过的样子 (KMP)

    # 10047. 「一本通 2.2 练习 3」似乎在梦中见过的样子 [题目描述] 「Madoka,不要相信 QB!」伴随着 Homura 的失望地喊叫,Madoka 与 QB 签订了契约. 这是 Mo ...

  4. 安装最新版Elasticsearch报错

    1 问题:ERROR: bootstrap checks failed max file descriptors [4096] for elasticsearch process likely too ...

  5. python数据结构:pandas(2)数据操作

    一.Pandas的数据操作 0.DataFrame的数据结构 1.Series索引操作 (0)Series class Series(base.IndexOpsMixin, generic.NDFra ...

  6. 解决arcgis10.5直连postgresql报错

    软件版本: arcgis10.5 postgresql9.5.9 最近使用desktop直连postgresql,已经拷贝了类库文件到desktop及pgsql配置完成的前提下,但还是报以下错误: 解 ...

  7. Java全排列递归算法

    Java全排列算法: 第一遍循环:将list数组index==0的元素依次与数组的每个元素交换,从而保证index==0的位置先后出现n个不同元素之一,实现对index==0位置的遍历. 第 i 遍循 ...

  8. Linux系统性能测试工具(六)——磁盘io性能工具之dd

    本文介绍关于Linux系统(适用于centos/ubuntu等)的磁盘io性能测试工具-dd.磁盘io性能测试工具包括: fio: dd

  9. mkpasswd - 为用户产生新口令

    总览 SYNOPSIS mkpasswd [ args ] [ user ] 介绍 INTRODUCTION mkpasswd 为用户产生口令并自动应用.它是基于O'Reilly的书<Explo ...

  10. First one Day(哈哈哈哈)

    今天是我来到园子的第一天,后序会分享一些自己所学的知识(当然我知道没人看,但是我自己看就好).哈哈哈哈哈  请大家多多关照!