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 ...
随机推荐
- Clean code 关于注释、函数、命名的感想
最近在看代码整洁之道(Clean code)这本书,其实看的有点痛苦,因为越看就会越想自己写的代码是什么鬼?一些不知所云的命名,不整洁的代码格式,本想诠释代码的意思却添加了一段段废话,还有那些被强制加 ...
- TCP/IP学习笔记2--协议分层与OSI参考模型
协议的分层: 为解决不同计算机之间的通信,ISO(International Organization for Standards)指定了一个国际标准OSI(Open Systems Intercon ...
- LeetCode 856. 括号的分数(Score of Parentheses)
856. 括号的分数 856. Score of Parentheses 题目描述 给定一个平衡括号字符串 S,按下述规则计算该字符串的分数: () 得 1 分. AB 得 A + B 分,其中 A ...
- Apache Kafka Producer For Beginners
在我们上一篇Kafka教程中,我们讨论了Kafka Cluster.今天,我们将通过示例讨论Kafka Producer.此外,我们将看到KafkaProducer API和Producer API. ...
- spring项目配置双数据源读写分离
我们最早做新项目的时候一直想做数据库的读写分离与主从同步,由于一些原因一直没有去做这个事情,这次我们需要配置双数据源的起因是因为我们做了一个新项目用了另一个数据库,需要把这个数据库的数据显示到原来的后 ...
- lambda表达式笔记
前几天一位好友分享了一篇文章,其中讲到了lambda表达式,正好最近看了一些内容,就做做笔记吧... lambda表达式服务于函数式接口,如果需要一个函数式接口的对象时,就可以用lambda表达式代替 ...
- python技巧 — pip install 错误,超时
jieba库安装失败 pip install -i https://pypi.tuna.tsinghua.edu.cn/simple jieba wordcloud库安装失败 pip instal ...
- go语言学习笔记----模拟实现文件拷贝函数
实例1 //main package main import ( "bufio" "flag" "fmt" "io" & ...
- asp.net mvc 使用bootstrap的模态框插件modal
编译器:vs2012 jquery版本:jquery-1.10.2.js bootstrap:bootstrap.js v3.0.0,包含modal插件 我们要实现一个使用模态框展示从服务器获取的数据 ...
- nginx在Windows环境安装
nginx介绍 nginx是一款自由的.开源的.高性能的HTTP服务器和反向代理服务器:同时也是一个IMAP.POP3.SMTP代理服务器:nginx可以作为一个HTTP服务器进行网站的发布处理,另外 ...