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 ...
随机推荐
- VC++ 非托管代码 & 托管代码
#pragma managed #pragma unmanaged 看了好多好多非托管代码和托管代码之间相互调用,感觉都没有说在重点上,到底怎么用才是关键,理论的东西我们到微软官网上就可以找到,毕竟这 ...
- Android 实现的EditText响应drawableRight的点击事件
1.自定义Edittext 实现右侧图标点击清空 package com.dxw.live.view; import android.content.Context; import android.g ...
- LeetCode 017 4Sum
[题目] Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d ...
- centos下安装nodejs及websocket
软件环境: VMware Workstation CentOS 6.5 NodeJS v0.12.5 安装过程: Step 1.确认服务器有nodejs编译及依赖相关软件,如果没有可通过运行以下命令安 ...
- P4298 [CTSC2008]祭祀
P4298 [CTSC2008]祭祀 传递闭包跑一遍按联通建图 $(1)$最长反链长度=最小链覆盖=n-最大匹配 $(2)$定义作为最大匹配出现在左端点的集合为$S$,作为最大匹配出现在右端点的集合为 ...
- git 生成patch和应用patch【转】
本文转载自:http://www.jianshu.com/p/814fb6606734 1.在git源码目录下执行 1.1.两个commit间的修改(包含两个commit) git format-pa ...
- POJ2278 DNA Sequence —— AC自动机 + 矩阵优化
题目链接:https://vjudge.net/problem/POJ-2778 DNA Sequence Time Limit: 1000MS Memory Limit: 65536K Tota ...
- Spring Boot2.0之热部署原理
所谓的热部署:比如项目的热部署,就是在应用程序在不停止的情况下,实现新的部署 原理: 实用类加载器(classloader重新读取字节码文件到jvm内存) 如何纯手写一个热部署功能: 1.监听 cla ...
- 无法远程连接阿里云的Mysql
问题描述:昨天使用阿里云安装了Mysql,无法远程连接,排除端口号错误.防火墙.Mysql权限问题后,最后发现是阿里云安全组规则限制问题: 解决方式: 1.访问阿里云控制台,实例-->管理 2. ...
- Cocos2d-x中定时器的使用
CCTimer:轻量级的计时器 CCTimer (void) ccTime getInterval (void) void setInterval (ccTime fInterval) bool ...