Gym 101102J---Divisible Numbers(反推技巧题)
题目链接
http://codeforces.com/gym/101102/problem/J
Description
You are given an array A of integers of size N, and Q queries. For each query, you will be given a set of distinct integers S and two integers L and R that represent a range in the array. Your task is to count how many numbers in the given range are divisible by at least one number from the set.
Input
The first line of input contains a single integer T, the number of test cases.
The first line of each test case contains two integers, N and Q (1 ≤ N, Q ≤ 105), the size of the array and the number of queries, respectively.
The next line contains N space-separated integers, the values of the array A (1 ≤ Ai ≤ 109).
Each of the next Q lines contain the description of one query in the form:
LRS
Where L and R (1 ≤ L ≤ R ≤ N) represent the range, and S is an integer between 1 and 1023 (inclusive) and represents the set; consider the binary representation of the number S, if the ith bit (1-based) is 1, then the number i belongs to the set. Since S is less than1024, the values in the set are between 1 and 10.
For example: if S is equal to 6, the binary representation of 6 is 110, and this means the values in the set are 2 and 3.
The input was given in this way to reduce the size of the input file.
Output
Print the answer for each query on a single line.
Sample Input
1
4 2
2 5 3 8
1 3 2
2 4 355
1
3 题意:输入n,q表示由n个数构成的一个序列,q次询问,每次询问输入l r s s表示一个集合,s的二进制中的1的位置,如:6(10)=110(2) 对应集合{2,3} 现在求区间l~r中能被集合中的(任意一个)数整除的数的个数; 思路:因为s取值范围为1~1023 所以输入n个数时直接求出能被哪些s(对应的集合数)整除,然后用前缀和表示出来,那么每次查询时就是0(1)的了; 代码如下:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long LL;
const int MAXN = 1e5+;
int sum[][MAXN];
template <class T>
inline void Scan(T &ret)
{
char c=getchar();
while(c<''||c>'')
c=getchar();
ret=c-'';
while(c=getchar(),c>=''&&c<='')
ret=ret*+(c-'');
} int main()
{
int T;
Scan(T);
while(T--)
{
int n,q,x,s;
Scan(n); Scan(q);
///memset(sum,0,sizeof(sum)); 加上超时!!!
for(int i=;i<=n;i++)
{
s=;
Scan(x);
for(int j=;j<=;j++)
if(x%j==) s=s|(<<(j-)); for(int j=;j<;j++)
sum[j][i]=sum[j][i-]+((s&j)?:);
}
while(q--)
{
int l,r;
Scan(l); Scan(r); Scan(x);
if(x&) printf("%d\n",r-l+);
else printf("%d\n",sum[x>>][r]-sum[x>>][l-]);
}
}
return ;
}
Gym 101102J---Divisible Numbers(反推技巧题)的更多相关文章
- 1day漏洞反推技巧实战(1)
学习笔记里的存货(1) 以前看了一篇推特老外做赏金猎人的文章,感触有点深,作者没有写相关漏洞分析,只是说了自己挖了多少个漏洞,这里简单的分析下: 1day漏洞在很多时候至关重要,不管是在红蓝对抗,还是 ...
- 1day漏洞反推技巧实战(2)
学习存货(2) CVE-2018-11784简单分析之反推的魅力 看着挺有趣的,简单分析下: 通过搜索tomcat漏洞找到: http://tomcat.apache.org/security-7.h ...
- 1day漏洞反推技巧实战(3)
代码审计必备技能,github代码对比,写一笔: 搜索某开源组建漏洞,搜索出来某个版本rce: 通过消息得出:存在漏洞版本:1.10.10 ,修复漏洞版本1.10.11 去github寻找apache ...
- poj 2155:Matrix(二维线段树,矩阵取反,好题)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 17880 Accepted: 6709 Descripti ...
- dwr2反推
package services; import org.directwebremoting.Browser; import org.directwebremoting.ScriptSessions; ...
- Anipang2反推文档
此文档主要用于一个开发同学尝试学习描述一个产品的基本设计.也许工程师都应该有类似能力. 反推的基础,目前是自己玩过的一些关卡和youtube上的一些关卡通关视频,主要是前120关.(120关后面应该是 ...
- base64随机字符混淆加密、解密-美拍视频地址解密,反推加密算法
用火车头测试采集美拍的数据时无意中发现美拍的视频地址是一段加了混淆字符串的base64代码.如下图 于是好奇之下研究了下解密算法.具体过程省略800字.发现美拍的视频解密是通过js完成,于是找到了具体 ...
- JavaScript反调试技巧
一.函数重定义 这是一种最基本也是最常用的代码反调试技术了.在JavaScript中,我们可以对用于收集信息的函数进行重定义.比如说,console.log()函数可以用来收集函数和变量等信息,并将其 ...
- HackerRank - string-reduction【反推】【规律】
HackerRank - string-reduction[反推] 题意 给出一串 只有 字母 a, b, c 组成的字符串,然后没两个不同的字符碰到一起都可以变成另外一个字符,然后变到最后,求最短的 ...
随机推荐
- Android开发学习之路-Service和Activity的通信
在很多时候,Service都不仅仅需要在后台运行,还需要和Activity进行通信,或者接受Activity的指挥,如何来实现,来看代码. 定义一个服务 // 创建一个服务,然后在onBind()中返 ...
- Atitit 项目管理(5)----------后勤管理与工具链支持管理
Atitit 项目管理(5)----------后勤管理与工具链支持管理 1.1. keyword1 1.2. 15个辅助软件1 1.3. 公共模块管理(100个即可)2 1.4. 第三方类库表2 1 ...
- Android TextView 常用技巧
Android ListView 常用技巧 Android TextView 常用技巧 TextView在Android中实现文字说明等功能,基本的使用都很简单,那么除了基本展示文字的使用,我们还能够 ...
- How Google TestsSoftware - Part Two
In order for the "you buildit, you break it" motto to be real, there are roles beyond the ...
- 【Discuz】关闭QQ互联插件提示信息:系统繁忙,请稍后再试
版本:X3.2.20160601 提示信息 系统繁忙,请稍后再试 解决方案 Step1.删除QQ互联插件目录 网站的根目录\source\plugin\qqconnect Step2.上传原始QQ互联 ...
- Android开发之广播
广播是Android开发中的一个重要的功能,在Android里面有各式各样的广播,比如:电池的状态变化.信号的强弱状态.电话的接听和短信的接收等等,现在给大家简单介绍一下系统发送.监听这些广播的机制. ...
- Apache+MySQL+PHP开发环境的搭建(一)
通过套件来安装和配置php开发环境. 1.所需软件:AppServ(因为是开源,任何网站都能下载) 安装本软件基本上就是下一步. 2.进行安装 选择一个盘安装该软件点击next继续: 根据自己的实际情 ...
- 如何解决Android SDK中离线文档打开慢的问题
原文:http://blog.csdn.net/hansel/article/details/39268511 Android SDK中的离线文档虽然都是本地文件,但是有很多Javascript, C ...
- 性能调优:理解Set Statistics IO输出
性能调优是DBA的重要工作之一.很多人会带着各种性能上的问题来问我们.我们需要通过SQL Server知识来处理这些问题.经常被问到的一个问题是:早上这个存储过程运行时间还是可以的,但到了晚上就很慢很 ...
- 12种JavaScript MVC框架之比较
Gordon L. Hempton是西雅图的一位黑客和设计师,他花费了几个月的时间研究和比较了12种流行的JavaScript MVC框架,并在博客中总结了每种框架的优缺点,最终的结果是,Ember. ...