题意:50000个5维向量,50000次询问每一维都不大于某一向量的向量个数,强制在线。

思路:做完这题才知道bitset效率这么高,自己本地测试了下1s可以操作1010个bit,orz简单粗暴

  • 令S(i)表示第i维比当前向量的i维小的向量集,则答案为count(∩S(i)),0≤i‹5
  • 每个向量都可以和一个id绑定(取下标就行了),绑定后就可以考虑bitset了。分别按每一维排序,每隔√N个位置预处理下当前位置之前的id的bitset
  • 查询时,对每一维二分得到最大位置,然后用1个预处理的结果+最多√N次暴力单bit插入就能得到S(i)。然后就是and和count了。
#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#include "local.h"
#endif
#define X first
#define Y second
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define all(a) (a).begin(), (a).end()
#define mset(a, x) memset(a, x, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
typedef long long ll;
template<typename T>bool umax(T&a, const T&b){return b<=a?false:(a=b,true);}
template<typename T>bool umin(T&a, const T&b){return b>=a?false:(a=b,true);} int k;
struct Node {
int a[5];
int id;
void read() {
for (int i = 0; i < 5; i ++) {
scanf("%d", a + i);
}
}
bool operator < (const Node &that) const {
return a[k] < that.a[k];
}
};
Node stu[1 << 16];
int r[5][1 << 16], id[5][1 << 16];
bitset<1 << 16> bs[5][1 << 8]; int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // ONLINE_JUDGE
int T, n, q, m;
cin >> T;
while (T --) {
cin >> n >> m;
for (int i = 0; i < n; i ++) {
stu[i].read();
stu[i].id = i;
}
int L = sqrt(n + 0.5);
for (int i = 0; i < 5; i ++) {
k = i;
sort(stu, stu + n);
bitset<1 << 16> bbs;
for (int j = 0; j < n; j ++) {
r[i][j] = stu[j].a[i];
id[i][j] = stu[j].id;
bbs[stu[j].id] = 1;
if (j % L == L - 1 || j == n - 1) {
bs[i][j / L] = bbs;
}
}
}
int lastans = 0;
cin >> q;
while (q --) {
Node qry;
qry.read();
bitset<1 << 16> ans;
for (int i = 0; i < 5; i ++) {
qry.a[i] ^= lastans;
bitset<1 << 16> buf;
int pos = upper_bound(r[i], r[i] + n, qry.a[i]) - r[i];
if (pos / L) buf = bs[i][pos / L - 1];
while (pos % L) buf[id[i][-- pos]] = 1;
if (i) ans &= buf;
else ans = buf;
}
printf("%d\n", lastans = ans.count());
}
}
return 0;
}

  

[hihoCoder1236 Scores 2015BeijingOnline]简单粗暴的分块+简单粗暴的bitset的更多相关文章

  1. 要多简单就有多简单的H5拍照加水印

    来一个简单粗暴的gif演示图 先来html 内容 <video id="video" width="320" height="240" ...

  2. 【转】C#类的分类(静态类、实例类、嵌套类、结构、简单的抽象类、简单的密封类)

    静态类 -------------------------------------------------------------------------------- 静态类就是在class关键字前 ...

  3. CORS跨域请求之简单请求与非简单请求

    先来看一个例子 定义server01的项目,在路由表中添加一条路由记录 url(r'^getData.html$',views.get_data) 对应的视图函数 from django.shortc ...

  4. Python入门一:简单得不能再简单了##

    从python的语法上看,简单得不能再简单了. 想学它,请移步廖雪峰python2.7教程以及python3.这实在是最好的入门教程.参考资料太多: 外国的教程 Python 入门指南 Python ...

  5. 学python2.7简单还是python3.0简单,两者区别

    学python2.7简单还是python3.0简单,谈谈两者区别 1. 使用__future__模块 Python 3.X 引入了一些与Python 2 不兼容的关键字和特性.在Python 2中,可 ...

  6. 对 cloudwu 简单的 cstring 进行简单解析

    题外话 以前也用C写过字符串,主要应用的领域是,大字符串,文件读取方面.写的很粗暴,用的凑合着.那时候看见云风前辈的一个开源的 cstring 串. 当时简单观摩了一下,觉得挺好的.也没细看.过了较长 ...

  7. 简单搜索dfs, 简单的修剪搜索

    选择最合适的语言做一个项目是非常重要的.但,熟练的掌握自己的武器,这也是非常重要的. ========================================================= ...

  8. socket.io简单入门(一.实现简单的图表推送)

    引子:随着nodejs蓬勃发展,虽然主要业务系统因为架构健壮性不会选择nodejs座位应用服务器.但是大量的内部系统却可以使用nodejs试水,大量的前端开发人员转入全堆开发也是一个因素. 研究本例主 ...

  9. kettle教程(1) 简单入门、kettle简单插入与更新。打开kettle

    本文要点:Kettle的建立数据库连接.使用kettle进行简单的全量对比插入更新:kettle会自动对比用户设置的对比字段,若目标表不存在该字段,则新插入该条记录.若存在,则更新.   Kettle ...

随机推荐

  1. codeforces Equalizing by Division (easy version)

    output standard output The only difference between easy and hard versions is the number of elements ...

  2. 算法笔记刷题4(PAT B1009)

    这一题本来不应该有什么问题的,我很快写出来了,在dev c++里面运行也正常.但是放到pat以后出现了问题.更换了c/c++都不行通过编译. #include <cstdio> #incl ...

  3. htaccess 一般配置

    一.Apache服务器 <IfModule mod_rewrite.c> Options +FollowSymlinks -Multiviews RewriteEngine on Rewr ...

  4. 2019-2020-1 20199329《Linux内核原理与分析》第二周作业

    <Linux内核原理与分析>第二周作业 一.上周问题总结: 未能及时整理笔记 Linux还需要多用 markdown格式不熟练 发布博客时间超过规定期限 二.本周学习内容: <庖丁解 ...

  5. 如何在没有安装 Python 的机器上运行 Python 程序

    cmd 命令 1. pip install pyinstaller 2. pyinstaller <path to your prog.py> 3. 应用程序在prog.py同路径下的 d ...

  6. 终止过久没有返回的 Windows API 函数 ---- “CancelSynchronousIo”

    Marks pending synchronous I/O operations that are issued by the specified thread as canceled. BOOL W ...

  7. PHP的闭包和匿名函数

    闭包函数是创建时,封装周围状态的函数,而匿名函数是没有名称的函数,匿名函数可以被赋值给变量,也就是所谓的函数式编程,也可以传递参数,经常作为回调函数.(理论上讲:匿名函数和闭包不算是一个概念,php却 ...

  8. Shiro(二):Spring-boot如何集成Shiro(上)

    这篇文章主要介绍了spring-boot是如何集成shiro的authentication流程的. 从shiro-spring-boot-web-starter说起 shiro-spring-boot ...

  9. Mark一篇介绍Java垃圾回收和JVM参数设置的文章

    贴出原文连接:重磅!Java 内存管理白皮书,读完它,java 内存管理的问题完全 NO Problem! 读了一遍,对并行的垃圾回收还不是很理解,先mark,消化消化再学习. 文章说的一些JVM设置 ...

  10. Guzzle 一个PHP的HTTP客户端

    Guzzle是一个PHP的HTTP客户端,用来轻而易举地发送请求,并集成到我们的WEB服务上. https://github.com/guzzle/guzzle 接口简单:构建查询语句.POST请求. ...