CF1093E Intersection of Permutations [分块 +bitset]
大家好, 我非常喜欢暴力数据结构, 于是就用分块A了此题
分块题,考虑前缀和 \(b_i\) 表示 bitset 即 \(0\) ~ \(i
\) 出现过的数字,然后考虑直接暴力复制块然后前缀和,修改也很简单,直接删除完了 swap 一下,再弄回去
时间复杂度 \(O(q \sqrt n + q \frac{n}{w})\)
// by Isaunoya
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <cstdio>
#include <bitset>
using namespace std;
#define rep(i, x, y) for (register int i = (x); i <= (y); ++i)
#define Rep(i, x, y) for (register int i = (x); i >= (y); --i)
//#define int long long
const int _ = 1 << 21;
struct I {
char fin[_], *p1 = fin, *p2 = fin;
inline char gc() {
return (p1 == p2) && (p2 = (p1 = fin) + fread(fin, 1, _, stdin), p1 == p2) ? EOF : *p1++;
}
inline I& operator>>(int& x) {
bool sign = 1;
char c = 0;
while (c < 48) ((c = gc()) == 45) && (sign = 0);
x = (c & 15);
while ((c = gc()) > 47) x = (x << 1) + (x << 3) + (c & 15);
x = sign ? x : -x;
return *this;
}
inline I& operator>>(double& x) {
bool sign = 1;
char c = 0;
while (c < 48) ((c = gc()) == 45) && (sign = 0);
x = (c - 48);
while ((c = gc()) > 47) x = x * 10 + (c - 48);
if (c == '.') {
double d = 1.0;
while ((c = gc()) > 47) d = d * 0.1, x = x + (d * (c - 48));
}
x = sign ? x : -x;
return *this;
}
inline I& operator>>(char& x) {
do
x = gc();
while (isspace(x));
return *this;
}
inline I& operator>>(string& s) {
s = "";
char c = gc();
while (isspace(c)) c = gc();
while (!isspace(c) && c != EOF) s += c, c = gc();
return *this;
}
} in;
struct O {
char st[100], fout[_];
signed stk = 0, top = 0;
inline void flush() {
fwrite(fout, 1, top, stdout), fflush(stdout), top = 0;
}
inline O& operator<<(int x) {
if (top > (1 << 20)) flush();
if (x < 0) fout[top++] = 45, x = -x;
do
st[++stk] = x % 10 ^ 48, x /= 10;
while (x);
while (stk) fout[top++] = st[stk--];
return *this;
}
inline O& operator<<(char x) {
fout[top++] = x;
return *this;
}
inline O& operator<<(string s) {
if (top > (1 << 20)) flush();
for (char x : s) fout[top++] = x;
return *this;
}
} out;
#define pb emplace_back
#define fir first
#define sec second
template < class T > inline void cmax(T & x , const T & y) {
(x < y) && (x = y) ;
}
template < class T > inline void cmin(T & x , const T & y) {
(x > y) && (x = y) ;
}
int n , m ;
const int maxn = 2e5 + 200 ;
template < int bl >
struct BLOCK {
bitset < maxn > b[maxn / bl] ;
bitset < maxn > temp ;
int per[maxn] ;
inline void ins(int x , int v) {
per[x] = v ;
for(register int i = x ; i <= n ; i += bl)
b[i / bl].set(v) ;
}
inline void del(int x , int v) {
for(register int i = x ; i <= n ; i += bl)
b[i / bl].reset(v) ;
}
inline bitset < maxn > qry(int x) {
temp = x / bl ? b[x / bl - 1] : 0 ;
rep(i , max(x / bl * bl , 1) , x)
temp.set(per[i]) ;
return temp ;
}
inline bitset < maxn > qry(int l , int r) {
return qry(r) ^ qry(l - 1) ;
}
};
int a[maxn] , b[maxn] ;
BLOCK < 256 > A ;
BLOCK < 512 > B ;
signed main() {
#ifdef _WIN64
freopen("testdata.in" , "r" , stdin) ;
#endif
in >> n >> m ;
rep(i , 1 , n) in >> a[i] , A.ins(i , a[i]) ;
rep(i , 1 , n) in >> b[i] , B.ins(i , b[i]) ;
while(m --) {
int opt ;
in >> opt ;
if(opt == 1) {
int l , r , a , b ;
in >> l >> r >> a >> b ;
int ans = (A.qry(l , r) & B.qry(a , b)).count() ;
out << ans << '\n' ;
}
else {
int x , y ;
in >> x >> y ;
B.del(x , b[x]) ; B.del(y , b[y]) ;
swap(b[x] , b[y]) ;
B.ins(x , b[x]) ; B.ins(y , b[y]) ;
}
}
return out.flush(), 0;
}
CF1093E Intersection of Permutations [分块 +bitset]的更多相关文章
- [CF1093E]Intersection of Permutations
[CF1093E]Intersection of Permutations 题目大意: 给定两个长度为\(n(n\le2\times10^5)\)的排列\(A,B\).\(m(m\le2\times1 ...
- CF1093E Intersection of Permutations 树状数组套权值线段树
\(\color{#0066ff}{ 题目描述 }\) 给定整数 \(n\) 和两个 \(1,\dots,n\) 的排列 \(a,b\). \(m\) 个操作,操作有两种: \(1\ l_a\ r_a ...
- [CF1093E]Intersection of Permutations:树套树+pbds
分析 裸的二维数点,博主用树状数组套平衡树写的,顺便pbds真好用. Update on 2018/12/20:再解释一下为什么是二维数点,第一维是\(la \leq i \leq ra\),第二维是 ...
- CF 1093 E. Intersection of Permutations
E. Intersection of Permutations 链接 题意: 给定两个序列,询问第一个排列的[l1,r1]和第二个排列[l2,r2]中有多少个共同的数,支持在第二个排列中交换两个数. ...
- 2015北京网络赛 J Clarke and puzzle 求五维偏序 分块+bitset
Clarke and puzzle Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://hihocoder.com/contest/acmicpc20 ...
- hihocoder1236(北京网络赛J):scores 分块+bitset
北京网络赛的题- -.当时没思路,听大神们说是分块+bitset,想了一下发现确实可做,就试了一下,T了好多次终于过了 题意: 初始有n个人,每个人有五种能力值,现在有q个查询,每次查询给五个数代表查 ...
- Codeforces 1093E Intersection of Permutations [CDQ分治]
洛谷 Codeforces 思路 一开始想到莫队+bitset,发现要T. 再想到分块+bitset,脑子一抽竟然直接开始写了,当然也T了. 最后发现这就是个裸的CDQ分治-- 发现\(a\)不变,可 ...
- 种树 by yoyoball [树分块+bitset]
题面 给定一棵树,有点权 每次询问给出一些点对,求这些点对之间的路径的并集上不同权值的个数,以及这些权值的$mex$ 思路 先考虑只有一对点对,只询问不同权值个数的问题:树上莫队模板题 然后加个$me ...
- 【cdq分治】【CF1093E】 Intersection of Permutations
传送门 果然前两天写完咕咕咕那个题的题解以后博客就开始咕咕咕了-- Description 给定整数 \(n\) 和两个 \(1~\sim~n\) 的排列 \(A,B\). \(m\) 个操作,操作有 ...
随机推荐
- ansible hosts配置
编辑/etc/ansible/hosts 添加本机的public SSH key到目标机器的authorized_keys #ssh-copy-id 添加本机的私钥到Ansible 运行ansib ...
- 杭电--1009 C语言实现
思路:要用有限的猫粮得到最多的javabean,则在房间中得到的javabean比例应尽可能的大. 用一个结构体,保存每个房间中的javabean和猫粮比例和房间号,然后将结构体按比例排序,则从比例最 ...
- Leetcode:面试题 04.03. 特定深度节点链表
Leetcode:面试题 04.03. 特定深度节点链表 Leetcode:面试题 04.03. 特定深度节点链表 先贴一下自己写过一个模板,按层数遍历: https://www.cnblogs.co ...
- [dubbo 源码之 ]1. 服务提供方如何发布服务
服务发布 启动流程 1.ServiceConfig#export 服务提供方在启动部署时,dubbo会调用ServiceConfig#export来激活服务发布流程,如下所示: Java API: ` ...
- C# 中Trim()、TrimStart()、TrimEnd()、ToUpper()、ToLower()的用法
Trim():删除字符串头部及尾部出现的空格,删除的过程为从外到内,直到碰到一个非空格的字符为止,所以不管前后有多少个连续的空格都会被删除掉. TrimStart():只删除字符串的头部的空格. Tr ...
- 表关联使用INNER JOIN实现更新功能
准备一些数据,创建2张表,表1为学生表: CREATE TABLE [dbo].[Student] ( [SNO] INT NOT NULL PRIMARY KEY, ) NOT NULL, ,) N ...
- Linux Samba文件共享服务,安装与案例配置
Samba服务器安装和配置 1:安装Samba服务器软件包 [root@localhost ~]# rpm -qa | grep samba [root@localhost ~]# yum -y in ...
- Microchip SPI串行SRAM和NVSRAM器件
Microchip的SRAM和NVSRAM系列(SPI串行SRAM和NVSRAM设备)提供了一种轻松添加外部RAM的方式,且具有以下特性功能 特性低功耗CMOS技术:4μA最大待机电流 标准4引脚SP ...
- P2214 [USACO14MAR]哞哞哞Mooo Moo
链接:Miku ---------------------- 这道题还是个背包 --------------------- 首先看一下声音的组成,对于每一个农场的声音,它是由两部分组成的 :上一个农场 ...
- WebStorm 2019.3.1 永久破解
PS:动手能力强的来,手残的去淘宝买吧,大概15块钱1年.建议看完后在动手,有一个全局观,浪费不了多少时间 一. 下载破解补丁文件 链接:https://pan.baidu.com/s/16-rPPH ...