HihoCoder1236 Scores
Scores
求五维偏序(≤)。强制在线。
\(n,q\le 50000\)
烂大街的题解
考虑如果我们能用bitset找到每一维有哪些比询问点小,然后把每一维的结果取交集,得到的就是答案了。
然后对每一维分块处理前缀,询问时二分得到排名,将前面整块的和末尾的合并一下就行了。
时间复杂度\(O(\frac{nq}{32})\)。分块对时间复杂度几乎没什么影响,重要的是bitset的操作。
#include<bits/stdc++.h>
#define co const
#define il inline
template<class T> T read(){
T x=0,w=1;char c=getchar();
for(;!isdigit(c);c=getchar())if(c=='-') w=-w;
for(;isdigit(c);c=getchar()) x=x*10+c-'0';
return x*w;
}
template<class T>il T read(T&x){
return x=read<T>();
}
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
co int N=50000+1,M=250;
int n,m,q,L[M],R[M],B[N];
pii scores[5][N];
bitset<N> S[5][M],A[5];
void solve(int u,int x){
int t=lower_bound(scores[u],scores[u]+n,pii(x,n))-scores[u];
A[u]=S[u][B[t]-1];
for(int i=L[B[t]];i<t;++i) A[u][scores[u][i].second]=1;
}
void real_main(){
read(n),read(m);
for(int i=0;i<n;++i)
for(int j=0;j<5;++j) read(scores[j][i].first),scores[j][i].second=i;
int len=sqrt(n),block=n/len+(n%len?1:0);
L[0]=R[0]=-1;
for(int i=1;i<=block;++i) L[i]=(i-1)*len,R[i]=i*len;
R[block]=n;
for(int i=0;i<5;++i){
sort(scores[i],scores[i]+n);
S[i][0]=0;
for(int j=1;j<=block;++j){
S[i][j]=S[i][j-1];
for(int k=L[j];k<R[j];++k) S[i][j][scores[i][k].second]=1;
}
}
for(int i=1;i<=block;++i)
for(int j=L[i];j<R[i];++j) B[j]=i;
read(q);
int ans=0;
while(q--){
for(int i=0;i<5;++i) solve(i,read<int>()^ans);
for(int i=4;i;--i) A[i-1]&=A[i];
ans=A[0].count();
printf("%d\n",ans);
}
}
int main(){
for(int t=read<int>();t--;) real_main();
return 0;
}
HihoCoder1236 Scores的更多相关文章
- [hihoCoder1236 Scores 2015BeijingOnline]简单粗暴的分块+简单粗暴的bitset
题意:50000个5维向量,50000次询问每一维都不大于某一向量的向量个数,强制在线. 思路:做完这题才知道bitset效率这么高,自己本地测试了下1s可以操作1010个bit,orz简单粗暴 令S ...
- hihocoder1236(北京网络赛J):scores 分块+bitset
北京网络赛的题- -.当时没思路,听大神们说是分块+bitset,想了一下发现确实可做,就试了一下,T了好多次终于过了 题意: 初始有n个人,每个人有五种能力值,现在有q个查询,每次查询给五个数代表查 ...
- hihocoder1236(2015长春网赛J题) Scores(bitset && 分块)
题意:给你50000个五维点(a1,a2,a3,a4,a5),50000个询问(q1,q2,q3,q4,q5),问已知点里有多少个点(x1,x2,x3,x4,x5)满足(xi<=qi,i=1,2 ...
- [LeetCode] Rank Scores 分数排行
Write a SQL query to rank scores. If there is a tie between two scores, both should have the same ra ...
- Codeforces Round #370 (Div. 2) D. Memory and Scores DP
D. Memory and Scores Memory and his friend Lexa are competing to get higher score in one popular c ...
- Faster RCNN 运行自己的数据,刚开始正常,后来就报错: Index exceeds matrix dimensions. Error in ori_demo (line 114) boxes_cell{i} = [boxes(:, (1+(i-1)*4):(i*4)), scores(:, i)];
function script_faster_rcnn_demo() close all; clc; clear mex; clear is_valid_handle; % to clear init ...
- LeetCode Database: Rank Scores
Write a SQL query to rank scores. If there is a tie between two scores, both should have the same ra ...
- LeetCode:Rank Scores
做到这题时卡了不少时间,参考了别人的解法,觉得挺不错的,还挺巧妙. SELECT s2.Score,s1.Rank From ( SELECT S1.Score, COUNT(*) as Rank F ...
- (Problem 22)Names scores
Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-tho ...
随机推荐
- leetcode腾讯精选练习(50 题)(持续更新)
1.除自身以外数组的乘积 给定长度为 n 的整数数组 nums,其中 n > 1,返回输出数组 output ,其中 output[i] 等于 nums 中除 nums[i] 之外其余各元素的乘 ...
- python常用的字符串格式化有哪几种?
常用字符串格式化%和format 皇城PK Python中格式化字符串目前有两种阵营:%和format,我们应该选择哪种呢? 自从Python2.6引入了format这个格式化字符串的方法之后,我认为 ...
- kmeans 对表达量进行聚类
代码如下 df = pd.read_csv("../kmeans/gene.fpkm.csv",header=None) print df.head() #去掉第一行 tdf = ...
- kube-proxy运行机制分析【转载】
转自:http://blog.itpub.net/28624388/viewspace-2155433/ 1.Service在很多情况下只是一个概念,而真正将Service的作用实现的是kube-pr ...
- centos6.5升级openssh至7.9p1
环境说明系统环境:centos 6.5 x64 openssh-5.3p1升级原因:低版本openssh存在漏洞升级目标:openssh-7.9p1 检查环境官方文档中提到的先决条件openssh安装 ...
- ESP8266 智能家居简单实现
本文转自CSDN,地址 https://blog.csdn.net/jsagacity/article/details/78531819 全文如下 : 前段时间,公司利用 ESP8266 这个WiFi ...
- dubbo源码阅读之负载均衡
负载均衡 在之前集群的文章中,我们分析了通过监听注册中心可以获取到多个服务提供者,并创建多个Invoker,然后通过集群类如FailoverClusterInvoker将多个Invoker封装在一起, ...
- 解决internal/modules/cjs/loader.js:638 throw err; ^ Error: Cannot find module 'resolve'
internal/modules/cjs/loader.js:638 throw err; ^ Error: Cannot find module 'resolve' 根据提示可以知道有依赖没有安装完 ...
- springMVC + mybatis 下出现JDBC Connection *** will not be managed by Spring错误
仔细查看配置中是否有如下类似的配置 execution(* com.ciguo.service.*.*(..)) <aop:config> <aop:pointcut id=&quo ...
- Java 之 数据库连接池
一.数据库连接池 1.连接池概念 连接池其实就是一个容器(集合),存放数据库连接的容器. 当系统初始化好后,容器被创建,容器中会申请一些连接对象,当用户来访问数据库时,从容器中获取连接对象,用户访问之 ...