链接:http://hihocoder.com/problemset/problem/1236

思路;

有n个五维的向量,给出q个询问,每个询问是一个五维向量,问有多少个向量没有一维比这个向量大。并且答案需要加密,除了第一个答案,其他答案都要和上一个答案异或。

因为是强制在线所以不能用cdq分治写。。我们可以用stl里面的bitset来写这道题,但是因为数据还是太大了,这里我们可以用分块处理下,降低空间复杂度,需要用的时候直

接二分查找需要的块,预处理后可以o(1)获取前k-1个块的信息,然后我们对当前块逐个更新下就好了。

这里 bit[i][j]代表第i维前j个块有多少个人。

实现代码:

#include<bits/stdc++.h>
using namespace std;
const int M = 5e4+; struct node{
int val,id;
node(){};
node(int val,int id):val(val),id(id){}
bool operator < (const node &b) const{
if(val == b.val) return id < b.id;
return val < b.val;
}
}a[][M];
bitset<M>bit[][];
bitset<M>ans;
bitset<M>temp;
int block;
int num; int main()
{
int t,n,m,q;
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m);
for(int i = ;i <= n;i ++)
for(int j = ;j <= ;j ++)
scanf("%d",&a[j][i].val),a[j][i].id = i; for(int i = ;i <= ;i ++) sort(a[i]+,a[i]+n+);
block = sqrt(n);
//分块,预处理
for(int i = ;i <= ;i ++){
for(int j = ;(j-)*block < n;j ++){
bit[i][j].reset();
bit[i][j] = bit[i][j-];
int st = (j-)*block;
for(int k = ;k <= block&&st+k<=n;k ++){
bit[i][j].set(a[i][st+k].id);
}
}
} int q;
scanf("%d",&q);
int now[];
int pre = ;
while(q--){
for(int i = ;i <= ;i ++){
scanf("%d",&now[i]);
now[i]^=pre;
}
ans.reset();
for(int i = ;i <= ;i ++){
int tmp = lower_bound(a[i]+,a[i]+n+,node(now[i],n+))-a[i]-;
tmp = tmp/block;
temp = bit[i][tmp];//获取之前块的信息
for(int j = tmp*block+;a[i][j].val<=now[i]&&j<=n;j++){ //当前块这个更新
temp.set(a[i][j].id);
}
if(i == )
ans = temp;
else
ans &= temp;
}
int num = ans.count();
pre = num;
printf("%d\n",num);
}
}
return ;
}

hihocoder #1236 Scores (15北京赛区网络赛J) (五维偏序,强制在线,bitset+分块)的更多相关文章

  1. hdu 4049 2011北京赛区网络赛J 状压dp ***

    cl少用在for循环里 #include<cstdio> #include<iostream> #include<algorithm> #include<cs ...

  2. HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛)

    HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛) Panda Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: ...

  3. HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)

    HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...

  4. 2019-ACM-ICPC-徐州站网络赛- I. query-二维偏序+树状数组

    2019-ACM-ICPC-徐州站网络赛- I. query-二维偏序+树状数组 [Problem Description] ​ 给你一个\([1,n]\)的排列,查询\([l,r]\)区间内有多少对 ...

  5. hdu 4046 2011北京赛区网络赛G 线段树 ***

    还带这么做的,卧槽,15分钟就被A了的题,居然没搞出来 若某位是1,则前两个为wb,这位就是w #include<cstdio> #include<cstring> #defi ...

  6. 2017ICPC北京赛区网络赛 Visiting Peking University(简单思维)

    描述 Ming is going to travel for n days and the date of these days can be represented by n integers: 0 ...

  7. hdu 4044 2011北京赛区网络赛E 树形dp ****

    专题训练 #include<stdio.h> #include<iostream> #include<string.h> #include<algorithm ...

  8. hdu 4050 2011北京赛区网络赛K 概率dp ***

    题目:给出1-n连续的方格,从0开始,每一个格子有4个状态,左右脚交替,向右跳,而且每一步的步长必须在给定的区间之内.当跳出n个格子或者没有格子可以跳的时候就结束了,求出游戏的期望步数 0:表示不能到 ...

  9. hdu 4045 2011北京赛区网络赛F 组合数+斯特林数 ***

    插板法基础知识 斯特林数见百科 #include<iostream> #include<cmath> #include<cstdio> #include<cs ...

随机推荐

  1. VS2017中 C# dll引用(C生成dll,C++生成dll)小结 - 简书

    原文:VS2017中 C# dll引用(C生成dll,C++生成dll)小结 - 简书 dll引用小结 一.dll与应用程序 动态链接库(也称为DLL,即为“Dynamic Link Library” ...

  2. 利用数据库触发器让字段与自增长Id相关联

    十年河东,十年河西,莫欺少年穷 学无止境,精益求精 今天是数据库脚本类的代码,所以不想过多阐述 如下数据表: create table Card( Id ,) primary key, CardNo ...

  3. 浅谈左偏树在OI中的应用

    Preface 可并堆,一个听起来很NB的数据结构,实际上比一般的堆就多了一个合并的操作. 考虑一般的堆合并时,当我们合并时只能暴力把一个堆里的元素一个一个插入另一个堆里,这样复杂度将达到\(\log ...

  4. Luogu P2568 GCD

    我们首先发现这样肯定是做不了的,所以我们枚举为\(gcd(x,y)=d\)的\(d\) 然后考虑以下的性质: \(gcd(x,y)=1 \Leftrightarrow gcd(px,py)=p(p为素 ...

  5. [BZOJ2125]最短路[圆方树]

    题意 给定仙人掌,多次询问两点之间的最短路径. \(n\le 10000, Q\le 10000​\) 分析 建出圆方树,分路径 lca 是圆点还是方点讨论. 预处理出根圆点到每个圆点的最短距离 \( ...

  6. Html5计算MD5值

    教程: http://www.tuicool.com/articles/InEBNz 组件: https://github.com/satazor/js-spark-md5

  7. HTML 5 拖放

    拖放(Drag 和 drop)是 HTML5 标准的组成部分. 拖放 拖放是一种常见的特性,即抓取对象以后拖到另一个位置. 在 HTML5 中,拖放是标准的一部分,任何元素都能够拖放. 拖放事件 1. ...

  8. php7与之前的区别和更新【转】

    http://blog.csdn.net/u011957758/article/details/73320083 本文是一篇讲座听后+后续研究的总结. 话说当年追时髦,php7一出就给电脑立马装上了, ...

  9. Java 类的加载

    package com.cwcec.p2; class C { public static final int SIZE; static { SIZE = 100; System.out.printl ...

  10. [BUAA_SE_2017]第零次博客

    结缘计算机 你为什么选择计算机专业?你认为条件如何? 计算机是你喜欢的领域吗?是你擅长的领域吗? 说来也巧,高考选择专业时并不知道自己会这般喜欢计算机这个专业,却将其填在了北航的第一志愿. 第一次接触 ...