hihocoder #1236 Scores (15北京赛区网络赛J) (五维偏序,强制在线,bitset+分块)
链接: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+分块)的更多相关文章
- hdu 4049 2011北京赛区网络赛J 状压dp ***
cl少用在for循环里 #include<cstdio> #include<iostream> #include<algorithm> #include<cs ...
- HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛)
HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛) Panda Time Limit: 10000/4000 MS (Java/Others) Memory Limit: ...
- HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)
HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...
- 2019-ACM-ICPC-徐州站网络赛- I. query-二维偏序+树状数组
2019-ACM-ICPC-徐州站网络赛- I. query-二维偏序+树状数组 [Problem Description] 给你一个\([1,n]\)的排列,查询\([l,r]\)区间内有多少对 ...
- hdu 4046 2011北京赛区网络赛G 线段树 ***
还带这么做的,卧槽,15分钟就被A了的题,居然没搞出来 若某位是1,则前两个为wb,这位就是w #include<cstdio> #include<cstring> #defi ...
- 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 ...
- hdu 4044 2011北京赛区网络赛E 树形dp ****
专题训练 #include<stdio.h> #include<iostream> #include<string.h> #include<algorithm ...
- hdu 4050 2011北京赛区网络赛K 概率dp ***
题目:给出1-n连续的方格,从0开始,每一个格子有4个状态,左右脚交替,向右跳,而且每一步的步长必须在给定的区间之内.当跳出n个格子或者没有格子可以跳的时候就结束了,求出游戏的期望步数 0:表示不能到 ...
- hdu 4045 2011北京赛区网络赛F 组合数+斯特林数 ***
插板法基础知识 斯特林数见百科 #include<iostream> #include<cmath> #include<cstdio> #include<cs ...
随机推荐
- SpringMVC之单/多文件上传
1.准备jar包(图标所指必备包,其他按情况导入) 2.项目结构 3.SingleController.java(控制器代码单文件和多文件) package com.wt.uplaod; import ...
- [Spark][Python]Wordcount 例子
[training@localhost ~]$ hdfs dfs -cat cats.txt The cat on the matThe aardvark sat on the sofa[traini ...
- [C#]使用Windows Form开发的天气预报小工具
用C#编写的天气预报小工具 功能 1.查询中国省份.城市及地区三级的天气预报: 2.显示1-7天一周的天气预报及未来8-15天的天气预报: 3.能定制地区的天气预报. 界面 源代码: https:// ...
- SCP和Rsync远程拷贝的几个技巧
scp是secure copy的简写,用于在Linux下进行远程拷贝文件的命令,和它类似的命令有cp,不过cp只是在本机进行拷贝不能跨服务器,而且scp传输是加密的.可能会稍微影响一下速度.当你服务器 ...
- 剑指offer:二叉树中和为某一值的路径
本来这只是一个普通的算法题,但是当初自己OJ上提交时,总是提交失败,而我自己认定程序逻辑没有任何问题.然后开始就在本机上调试,结果发现这是由于Python的对象机制而引发的.所以先把问题算法题贴出来, ...
- ecna2017-Game of Throwns
这题就是给你一个标号为0-n-1的环,然后给你M个操作,操作有两种,一种是直接给一个数,这数的正负代表我当前向前(向后)仍了xx个位置的球,或者给你一个撤销操作表示为 undo m,表示撤销最近的M个 ...
- 树莓派 Raspberry Pi 更换国内源
http://www.shumeipaiba.com/wanpai/jiaocheng/16.html
- js 时间戳转换为日期格式
//将1525854409000类型的时间转换成“yyyy-MM-dd”或“yyyy-MM-dd hh:mm:ss” //info.birthday是后台获取到的Date类型的出生日期数据, / ...
- python语言几个常见函数的使用
写代码,有如下变量,请按照要求实现每个功能: name = " Kobe Bean Bryant" a. 移除 name 变量对应的值左边的空格,并输出移除后的内容 name = ...
- Maven的课堂笔记2
5 maven的核心概念 5.1 项目对象模型 说明: maven根据pom.xml文件,把它转化成项目对象模型(POM),这个时候要解析依赖关系,然后去相对应的maven库中查找到依赖的jar包. ...