题目链接

http://codeforces.com/gym/101102/problem/J

Description

standard input/output

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

Input
1
4 2
2 5 3 8
1 3 2
2 4 355
Output
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(反推技巧题)的更多相关文章

  1. 1day漏洞反推技巧实战(1)

    学习笔记里的存货(1) 以前看了一篇推特老外做赏金猎人的文章,感触有点深,作者没有写相关漏洞分析,只是说了自己挖了多少个漏洞,这里简单的分析下: 1day漏洞在很多时候至关重要,不管是在红蓝对抗,还是 ...

  2. 1day漏洞反推技巧实战(2)

    学习存货(2) CVE-2018-11784简单分析之反推的魅力 看着挺有趣的,简单分析下: 通过搜索tomcat漏洞找到: http://tomcat.apache.org/security-7.h ...

  3. 1day漏洞反推技巧实战(3)

    代码审计必备技能,github代码对比,写一笔: 搜索某开源组建漏洞,搜索出来某个版本rce: 通过消息得出:存在漏洞版本:1.10.10 ,修复漏洞版本1.10.11 去github寻找apache ...

  4. poj 2155:Matrix(二维线段树,矩阵取反,好题)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 17880   Accepted: 6709 Descripti ...

  5. dwr2反推

    package services; import org.directwebremoting.Browser; import org.directwebremoting.ScriptSessions; ...

  6. Anipang2反推文档

    此文档主要用于一个开发同学尝试学习描述一个产品的基本设计.也许工程师都应该有类似能力. 反推的基础,目前是自己玩过的一些关卡和youtube上的一些关卡通关视频,主要是前120关.(120关后面应该是 ...

  7. base64随机字符混淆加密、解密-美拍视频地址解密,反推加密算法

    用火车头测试采集美拍的数据时无意中发现美拍的视频地址是一段加了混淆字符串的base64代码.如下图 于是好奇之下研究了下解密算法.具体过程省略800字.发现美拍的视频解密是通过js完成,于是找到了具体 ...

  8. JavaScript反调试技巧

    一.函数重定义 这是一种最基本也是最常用的代码反调试技术了.在JavaScript中,我们可以对用于收集信息的函数进行重定义.比如说,console.log()函数可以用来收集函数和变量等信息,并将其 ...

  9. HackerRank - string-reduction【反推】【规律】

    HackerRank - string-reduction[反推] 题意 给出一串 只有 字母 a, b, c 组成的字符串,然后没两个不同的字符碰到一起都可以变成另外一个字符,然后变到最后,求最短的 ...

随机推荐

  1. struts2学习笔记之八:Action中方法的动态调用

    方法一:action名称+!+方法名称+后缀 Action类中增加addUser()和delUser()方法, package com.djoker.struts2; import org.apach ...

  2. salesforce 零基础学习(二十六)自定义图表chart简单介绍(使用apex和VF实现)

    chart在报表中经常使用到,他可以使报表结果更加直观的展现给用户.salesforce支持VF和apex代码来更好的展示chart. chart分类:常用的图表样式有饼状图,柱状图,折线图,条形图, ...

  3. vuejs - the component is a fragment instance

    vuejs - the component is a fragment instance http://vuejs.org/guide/components.html#Fragment-Instanc ...

  4. mac下网页中文字体优化

    最近某人吐槽某门户网站在mac下chrome字体超丑,然后发现虽然现在mac用户越来越多,但是大家依然无视mac下的字体差异,于是研究了下mac下网页中的中文字体,和大家分享. 看了一遍国内各大门户和 ...

  5. windows phone Datepicker Timepicker

    选择程序包管理器控制台 在PM后输入Install-Package WPtoolkit可自动下载 PM> Install-Package WPtoolkit 在xaml中添加引用 xmlns:t ...

  6. App乱世,3721离我们有多远

    [总结]根据众多网友的评论,看来还是WP比较给力,IOS太贵...会对手机进行优化,安卓还行,如果给中老年人用WP比较好 声明:合理讨论,禁止骂人言论,本人也不是5毛党,发表下个人看法而已. 快过年了 ...

  7. (转)Shell函数

    Shell函数类似于Shell脚本,里面存放了一系列的指令,不过Shell的函数存在于内存,而不是硬盘文件,所以速度很快,另外,Shell还能对函数进行预处理,所以函数的启动比脚本更快. 1.  函数 ...

  8. [OpenCV] Samples 05: convexhull

    得到了复杂轮廓往往不适合特征的检测,这里再介绍一个点集凸包络的提取函数convexHull,输入参数就可以是contours组中的一个轮廓,返回外凸包络的点集 ---- 如此就能去掉凹进去的边. 对于 ...

  9. How do annotations work internally--转

    原文地址:http://stackoverflow.com/questions/18189980/how-do-annotations-work-internally The first main d ...

  10. Spark入门实战系列--6.SparkSQL(上)--SparkSQL简介

    [注]该系列文章以及使用到安装包/测试数据 可以在<倾情大奉送--Spark入门实战系列>获取 .SparkSQL的发展历程 1.1 Hive and Shark SparkSQL的前身是 ...