scores
题意:
m维偏序问题。
解法:
考虑对每一维按照每一个元素在这一维的数值分块,对于每一个块维护一个大小为 n 的bitset,表示前缀/后缀满足条件的元素集合。
对于每一个询问,我们可以枚举找到相应的块,将剩余元素暴力插入,得到 m 个限制条件下分别的满足条件集合,最后和已插入元素求交即可。
$O(q \sqrt n m + \frac{nmq}{64})$
const int N = ,M = ; struct node
{
int x[];
void scan()
{
FOR(i,,) scanf("%d",&x[i]);
}
}a[N]; bitset<N> blc[][M],ans[];
vector<int> pos[][N];
int n,m,siz,tot,L[M],R[M]; int main()
{
int T;
cin >> T;
while(T--)
{
cin >> n >> m;
FOR(i,,) FOR(j,,m) pos[i][j].clear();
FOR(i,,n)
{
a[i].scan();
FOR(j,,) pos[j][a[i].x[j]].pb(i);
}
siz = sqrt(m);
tot = m/siz+;
FOR(i,,) ans[i].reset();
FOR(i,,tot)
{
L[i] = max((i-)*siz,);
R[i] = min(i*siz-, m);
FOR(j,L[i],R[i]) FOR(k,,) for(auto x:pos[k][j]) ans[k].set(x);
FOR(k,,) blc[k][i] = ans[k];
}
int q,lastans=;;
node tmp;
cin >> q;
while(q--)
{
tmp.scan();
FOR(i,,) tmp.x[i]^=lastans;
FOR(t,,)
{
ans[t].reset();
int tp;
FOR(i,,tot)
if(R[i]>=tmp.x[t])
{
tp=i;
ans[t]=blc[t][i-];
break;
}
FOR(i,L[tp],tmp.x[t]) for(auto x:pos[t][i]) ans[t].set(x);
}
FOR(i,,) ans[]&=ans[i];
printf("%d\n",lastans = ans[].count());
}
}
return ;
}
scores的更多相关文章
- [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 ...
- Memory and Scores
Memory and Scores 题目链接:http://codeforces.com/contest/712/problem/D dp 因为每轮Memory和Lexa能取的都在[-k,k],也就是 ...
- [SQL]LeetCode178. 分数排名 | 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 -- 数据库知识(mysql)
Write a SQL query to rank scores. If there is a tie between two scores, both should have the same ra ...
- sql -leetcode 178. Rank Scores
Score 很好得到: select Score from Scores order by Score desc; 要得到rank, 可以通过比较比当前Score 大的Score 的个数得到: sel ...
随机推荐
- Linux系统初始化流程
POST-->BIOS(Boot Sequence)-->MBR(bootloader)-->Kernel(initrd)-->/sbin/init(/etc/inittab) ...
- 【BZOJ4237】稻草人 cdq分治+单调栈+二分
[BZOJ4237]稻草人 Description JOI村有一片荒地,上面竖着N个稻草人,村民们每年多次在稻草人们的周围举行祭典. 有一次,JOI村的村长听到了稻草人们的启示,计划在荒地中开垦一片田 ...
- 借助nodejs解析加密字符串 node安装库较python方便
const node_modules_path = '../node_modules/' // crypto-js - npm https://www.npmjs.com/package/crypto ...
- 【题解】[JSOI2008]最大数
[题解][P1198 JSOI2008]最大数 正难则反,意想不到. 这道题是动态让你维护一个数列,已经在数列里面的数据不做改变,每次在最后加上一个数,强制在线. 既然正着做很难,考虑如果时间倒流,不 ...
- 开发笔记--java.lang.OutOfMemoryError: PermGen space异常处理
第一次到公司开发项目,比起之前的小项目来说这次的项目特别大,以至于运行之后出现了java.lang.OutOfMemoryError: PermGen space的异常,从字面意思上来看是内存溢出的原 ...
- 在win7下使用git和gitlab进行code review
1.安装 Git-2.6.3-64-bit.exe 下载地址:http://pan.baidu.com/s/1hqGvwnq 2.根据收到的邮件进入gitlab网站,并修改密码登陆 3.新建一个文件 ...
- linux 常用shell脚本语句
最近老大让写一个shell脚本,每天从一个固定IP中取到相应文件,所以想写一个简单的shell脚本命令,供大家学习交流.先做一个简单的例子,先看效果吧, 代码如下: #!/bin/sh #定义一个变量 ...
- 9.1 NOIP普及组试题精解(3)
9-6 seat.c #include <stdio.h> #define MAXN 1001 void swap(int *a, int *b) //交换数据 { int t; t = ...
- Linux学习之路(五)压缩命令
常用压缩格式: .zip .gz .bz2 常用压缩格式: .tar.gz .tar.bz2 .zip格式压缩 .zip 压缩文件名 源文件 #压缩文件 .zip -r 压缩文件名 源目录 #压缩目录 ...
- matlab之flipud()函数
此函数实现矩阵的上下翻转.fliplw()实现左右旋转. 举例: a =[1 2;3 4;5 6] flipud(a)的结果: 5 6 3 4 1 2 fliplr(a)的结果: 2 1 4 3 6 ...