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\) 个操作,操作有 ...
随机推荐
- .Net Core中IOC容器的使用
打代码之前先说一下几个概念,那就是什么是IOC.DI.DIP 虽然网上讲这些的已经有很多了,我这里还是要再赘述一下 IOC容器就是一个工厂,负责创建对象的 IOC控制反转:只是把上端对下端的依赖,换成 ...
- 通过open上网并设置开机自启与自动连接
注意:这里所说的上网并不是FQ.只是简单的通过iptables让客户端可以访问外网.因为有些时候有这样的需求 上一篇文章为大家介绍了OpenVPN.以及它的部署工作.而这一篇主要就是讲解如何让客户端可 ...
- Uncaught Error: Call to undefined function mcrypt_get_iv_size() 解决办法
函数 mcrypt_get_iv_size 在只在(PHP 4 >= 4.0.2, PHP 5, PHP 7 < 7.2.0, PECL mcrypt >= 1.0.0) 这几个版本 ...
- ls-remote -h -t git://github.com/adobe-webplatform/eve.git
npm WARN deprecated bfj-node4@5.3.1: Switch to the `bfj` package for fixes and new features! npm WAR ...
- Git Gui for Windows下载(pull)的正确操作方法
- React之this绑定
一.首先看一下没有绑定this的情况 class App extends React.Component{ constructor(props){ super(props) console.log(' ...
- string的基本操作
在C++中,string 可以来定义一个字符串,用之前得调用下相应的库 #include<string> . 可以不用初始化字符串容量大小,系统会根据后续的赋值自动安排其容量大 ...
- golang单元测试简述
Golang中内置了对单元测试的支持,不需要像Java一样引入第三方Jar才能进行测试,下面将分别介绍Golang所支持的几种测试: 一.测试类型 Golang中单元测试有功能测试.基准测试. ...
- Linux分区工具-parted
parted用于操纵磁盘分区的程序,通常用于规则大小超过2T的分区,也可用于小分区的规划:它支持多种分区表格式,包括MS-DOS(MBR)和GPT:这对于为新操作系统创建空间,重新组织磁盘使用以及将数 ...
- Office Tool Plus - 一个OFFICE 管理、下载、安装器
文章选自我的博客:https://blog.ljyngup.com/archives/160.html/ 教程摘自官方教程. 官网:https://otp.landian.vip/zh-cn/ Off ...