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的更多相关文章

  1. [hihoCoder1236 Scores 2015BeijingOnline]简单粗暴的分块+简单粗暴的bitset

    题意:50000个5维向量,50000次询问每一维都不大于某一向量的向量个数,强制在线. 思路:做完这题才知道bitset效率这么高,自己本地测试了下1s可以操作1010个bit,orz简单粗暴 令S ...

  2. hihocoder1236(北京网络赛J):scores 分块+bitset

    北京网络赛的题- -.当时没思路,听大神们说是分块+bitset,想了一下发现确实可做,就试了一下,T了好多次终于过了 题意: 初始有n个人,每个人有五种能力值,现在有q个查询,每次查询给五个数代表查 ...

  3. 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 ...

  4. [LeetCode] Rank Scores 分数排行

    Write a SQL query to rank scores. If there is a tie between two scores, both should have the same ra ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. LeetCode:Rank Scores

    做到这题时卡了不少时间,参考了别人的解法,觉得挺不错的,还挺巧妙. SELECT s2.Score,s1.Rank From ( SELECT S1.Score, COUNT(*) as Rank F ...

  9. (Problem 22)Names scores

    Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-tho ...

随机推荐

  1. vscode添加vue文件模板

    文件->首选项->用户代码片段->输入vue,打开vue.json 添加模板json "Print to console": { "prefix&quo ...

  2. mysql慢查询日记

    mysql慢查询日记 <pre>#必须写到mysqld 注意给/tmp/showslowmysql.log 775权限 要写入权限[mysqld]#开启慢查询日记slow_query_lo ...

  3. Qt5 QtQuick系列----QtQuick的Secne Graph剖析(1)

    教是言词, 实不是道,道本无言, 言说是妄.------- 达摩 Qt 5提出了一个新的渲染底层,以替代Qt4时期的Graphics View,这个渲染底层就是Scene Graph.Scene Gr ...

  4. TCP/IP学习笔记12-- IP协议基础

    IP(internet protocol, 网际协议) IP相当于OSI参考模型中的第三层 -- 网络层. --网络层的下一层--数据链路层的主要作用是在 同一种数据链路 的节点之间进行包传递,而一旦 ...

  5. Windows中使用 Python 调用 Matlab 程序

    https://ww2.mathworks.cn/help/matlab/matlab_external/system-and-configuration-requirements.html http ...

  6. Django连接多个数据库并实现读写分离

    当一个项目当中有大量的数据的时候,你所有的IO操作都在一个数据库中操作,会造成项目的性能的降低.如果你能对项目中的数据进行读写分离的话,那么将大大提高你项目的性能.而Django自带的机制也对此提供了 ...

  7. Java线程的等待与唤醒完整示例代码

    项目结构: 资源类: 输入线程:  输出线程: 测试: 人妖问题发生: 线程安全问题的解决方法: 调用Object的wait()和notify()方法时需注意:必须是锁对象方可调用,否则将抛出无效的监 ...

  8. 【洛谷 P2444】 [POI2000]病毒(AC自动机)

    题目链接 这么多字符串,肯定是自动机啦. 先建出AC自动机,然后怎么表示一个安全代码没有病毒代码呢? 就是存在一条路径不经过有病毒代码段结尾的节点呗. 所以呢?有环啊!dfs一下救星了. #inclu ...

  9. es5中变量提升的问题

    <script> //变量提升的问题 var tem=new Date(); //函数f 输出tem var命令会发生“变量提升”现象 //局部变量优先高于全局变量 var tem=&qu ...

  10. LAMP环境搭建之编译安装指南(php-5.3.27.tar.gz)

    测试环境:CentOS release 6.5 (Final) 软件安装:httpd-2.2.27.tar.gz   mysql-5.1.72.tar.gz   php-5.3.27.tar.gz 1 ...