四川第十届省赛 A.Angel Beats bitset
四川第十届省赛 A.Angel Beats bitset
题解参考:http://www.cnblogs.com/Aragaki/p/9142250.html
考虑用bitset来维护对于所有的\(x\),需要翻转的位置。但是这样来搞的话,很难处理题目的要求。
所以换个角度,考虑翻转哪些位置会影响这一位。我们会发现,如果位置编号为某些数的公倍数,那么就会受到那些位置的影响。进一步深入想,其实会发现可以考虑只翻转某一位需要翻转哪些位置,这样的方案是唯一的。
设\(s[i]\)为只翻转第\(i\)位需要翻转哪些位置,那么\(s[i]=s[i]\) ^ \(s[2*i]\) ^ ... ^ \(s[k*i]\),因为翻转第\(i\)位会影响后面的位置,我们消去影响即可得只翻转第\(i\)位的位置。
之后就按照题意搞下就行了。
代码如下:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <bitset>
using namespace std;
typedef long long ll;
const int N = 1e4 + 5, M = 1e5 + 5;
int T;
int n, m;
bitset <N> s[N], pre[N], ans;
int main() {
scanf("%d", &T);
while(T--) {
scanf("%d%d", &n, &m) ;
for(int i = 1; i <= n; i++) s[i].reset() ;
for(int i = n; i >= 1; i--) {
s[i].set(i) ;
for(int j = 2 * i; j <= n; j += i) s[i] ^= s[j] ;
}
for(int i = 1; i <= n; i++) pre[i] = pre[i - 1] ^ s[i] ;
ans.reset() ;
for(int i = 1; i <= m; i++) {
int x, y;
scanf("%d%d", &x, &y) ;
ans ^= pre[x - 1] ^ pre[y] ;
printf("%d\n", ans.count()) ;
}
}
return 0;
}
四川第十届省赛 A.Angel Beats bitset的更多相关文章
- 河南省第十届省赛 Plumbing the depth of lake (模拟)
title: Plumbing the depth of lake 河南省第十届省赛 题目描述: There is a mysterious lake in the north of Tibet. A ...
- 河南省第十届省赛 Intelligent Parking Building
title: Intelligent Parking Building 河南省第十届省赛 tags: [模拟,省赛] 题目描述: There is a new revolution in the pa ...
- CSU 1511 残缺的棋盘 第十届湖南省赛题
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1511 题目大意:在一个8*8的棋盘中,给你一个起点位置和一个终点位置,同时也给你一个陷阱 ...
- CSU 1507 超大型LED显示屏 第十届湖南省赛题
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1507 解题思路:这是一道模拟题,看了那么多人的代码,我觉得我的代码是最简的,哈哈,其实就 ...
- 福州大学第十届校赛 & fzu 2128最长子串
思路: 对于每个子串,求出 母串中 所有该子串 的 开始和结束位置,保存在 mark数组中,求完所有子串后,对mark数组按 结束位置排序,然后 用后一个的结束位置 减去 前一个的 开始 位置 再 减 ...
- 【河南第十届省赛-D】年终奖金
题目描述 ***公司承接了N个项目需要年底完成,每个项目有一定的难度系数.由于项目太多了,需要招聘大量的技术人员.要求每个技术人员至少完成K个项目. 考虑到有些项目之间相似性以及项目的难易程度,为了避 ...
- 【河南第十届省赛-B】情报传递
题目描述 抗日战争时期,在国共合作的大背景下,中共不断发展壮大,其情报工作也开始由获取警报性.保卫性信息,向获取军政战略性情报转变.各系统情报组织遵循"荫蔽精干,长期埋伏,积蓄力量,以待时机 ...
- 河南省第十届省赛 Binary to Prime
题目描述: To facilitate the analysis of a DNA sequence, a DNA sequence is represented by a binary num ...
- 第十届山东省赛L题Median(floyd传递闭包)+ poj1975 (昨晚的课程总结错了,什么就出度出度,那应该是叫讨论一个元素与其余的关系)
Median Time Limit: 1 Second Memory Limit: 65536 KB Recall the definition of the median of elements w ...
随机推荐
- 搭建Hadoop+Python的大数据开发环境
实验环境 CentOS镜像为CentOS-7-x86_64-Everything-1804.iso 虚机配置 节点名称 IP地址 子网掩码 CPU/内存 磁盘 安装方式 master 192.168. ...
- postgresql小计
1. postgresql执行结束后,判断结果是否成功,有几种结果 typedef enum { PGRES_EMPTY_QUERY = 0, /* empty query string was ex ...
- FreeSql 访问 Oracle 解决大小写问题
方法一 new FreeSqlBuilder() .UseSyncStructureToUpper(true) .Build() 方法二 全局转换实体属性名方法,这种只能转属性. 其实是通过Aop方法 ...
- magic模块 :Exception Value:failed to find libmagic. Check your installation
原因 缺少安装依赖: magic 安装依赖: https://github.com/ahupp/python-magic#dependencies windows下解决方法: https://gith ...
- NamedParameterJdbcTemplate举例使用
原文地址https://www.iteye.com/blog/cosmicbugs-1190279 NamedParameterJdbcTemplate内部包含了一个JdbcTemplate,所以Jd ...
- Python【每日一问】21
问: [基础题]输入某年某月某日,判断这一天是这一年的第几天? [提高题]用 *号输出字母 C的图案 答: [基础题]输入某年某月某日,判断这一天是这一年的第几天? 方法1: import time ...
- centos上nginx转发tcp请求
下载最新版nginx > wget http://nginx.org/download/nginx-1.17.1.tar.gz 解压缩 > tar zxvf nginx-1.17.1.ta ...
- KB,MB,GB,TB,PB,EB,ZB,YB,BB
1 Bit = Binary Digit 8 Bits = 1 Byte 1024 Bytes = 1 Kilobyte 1024 Kilobytes = 1 Megabyte 1024 Megaby ...
- Centos 使用kubeadm安装Kubernetes 1.15.3
本来没打算搞这个文章的,第一里面有瑕疵(没搞定的地方),第二在我的Ubuntu 18 Kubernetes集群的安装和部署 以及Helm的安装 也有安装,第三 和社区的问文章比较雷同 https:// ...
- k8s-Annotation(注解)
k8s-Annotation(注解) Annotation与Label类似,也使用key/value键值对的形式进行定义. Label具有严格的命名规则,它定义的是Kubernetes对象的元数据(M ...