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 组成的字符串,然后没两个不同的字符碰到一起都可以变成另外一个字符,然后变到最后,求最短的 ...
随机推荐
- Nodejs·网络服务
本章是从NodeJS拥有的模块角度,讲述了网络服务中的应用: net ----- > TCP dgram --> UDP http -----> HTTP https ----> ...
- salesforce 零基础学习(三十四)动态的Custom Label
custom label在项目中经常用到,常用在apex class或者VF里面用来显示help text或者error message.有的时候我们需要用到的信息是动态变化的,那样就需要动态来显示信 ...
- 使用swoole和websocket结合来制造弹幕
在知乎上无意中看到了一篇有关这个的话题https://zhuanlan.zhihu.com/p/23992890,刚好没事也好久没弄swoole了就自己按照知乎上的那篇文站实操了一下 那个试验中有几个 ...
- andriod adt和andriod sdk
今天搭建appium的环境,没有太明白andriod adt和andriod sdk分别是什么东西,经过与开发沟通,大致了解如下,这里记录一下,免得过几天就搞忘了. andriod adt是一个插件, ...
- sublime简要笔记
选中单词 [1]选中当前单词 ctrl+d [2]跳过当前单词 ctrl+k ctrl+d [3]选中相同的所有单词 alt+f3 [4]多行游标 按住shift,然后按住鼠标右键向下拖动 行操作 [ ...
- 高拍仪拍照SDK开发(良田影像S300L|S500L)
高拍仪拍照SDK开发下载地址:点击下载 本SDK适用于:良田影像S300L|S500L 高拍仪如图: SDN开发包安装之后找到安装目录,如图: 大家找到各自需要的版本即可,需要注意的是如果需要上传图片 ...
- 编译Linux内核
下面的实验以 debian7.5 64bit 为例. 获取源码 获取 debian7.5 本身的源码非常简单: sudo apt-get install linux-source https://ww ...
- window、document、html、body、element的事件属性比较
在分析jQuery的事件的时候有提到绑定事件的方式: Dean Edwards的跨浏览器事件绑定使用的方式是 element["on" + type] = handleEvent; ...
- php版本历史
php最初就是为了快速构建一个web页面而迅速被大家广为接受的.它的好处是在代码中能内嵌html的代码,从而让程序员能再一个页面中同时写html代码和php代码就能生成一个web页面. 这篇文章用时间 ...
- 【Swift学习】Swift编程之旅(四)基本运算符
Swift支持大部分标准C语言的运算符, 且改进许多特性来减少常规编码错误.如赋值符 = 不返回值, 以防止错把等号 == 写成赋值号 = 而导致Bug. 数值运算符( + , -, *, /, %等 ...