gym101102J Divisible Numbers(预处理)

题意:

给你一个n(1e5)q(1e5)表示n个数的数列,q个询问,每次询问给你l(n),r(n),s(1023),

s表示一个二进制数列,当前位为1表示对应的这个位上的数出现,比如5表示101,即1和3出现,

l,r表示一段区间,这段区间中的每个数,只要能整除出现的数中的任意一个,就会对答案有1的贡献。

问每个询问的贡献。

思路:

由于出现了1就肯定每个数都有贡献(都是1的倍数),然后就可以少一位,用512表示9位出不出现的所有情况,

用n*512的复杂度预处理所有的情况,O(1)查询。

for(int j=2;j<=10;j++)
    if(x%j==0) s=s|(1<<(j-2));
for(int j=0;j<512;j++)
    sum[j][i]=sum[j][i-1]+((s&j)?1:0);
时间: 2024-12-07 18:37:34

gym101102J Divisible Numbers(预处理)的相关文章

Codeforces 385C Bear and Prime Numbers(素数预处理)

Codeforces 385C Bear and Prime Numbers 其实不是多值得记录的一道题,通过快速打素数表,再做前缀和的预处理,使查询的复杂度变为O(1). 但是,我在统计数组中元素出现个数时使用了map,以至于后面做前缀和的累加时,每次都要对map进行查询,以至于TLE.而自己一直没有发现,以为是欧拉筛对于这道题还不够优,于是上网搜题解,发现别人的做法几乎一样,但是却能跑过,挣扎了许久才想起是map的原因.map的内部实现是一颗红黑树,每次查询的复杂度为O(logN),在本来时

【Kata Daily 191012】Find numbers which are divisible by given number

题目: Complete the function which takes two arguments and returns all numbers which are divisible by the given divisor. First argument is an array of numbers and the second is the divisor. Example divisible_by([1, 2, 3, 4, 5, 6], 2) == [2, 4, 6] 解题方法:

C语言宏预处理帮助文档

GCC4.10预处理器帮助文档 The C Preprocessor Transformations Made Globally Most C preprocessor features are inactive unless you give specific commands to request their use. (Preprocessor commands are lines starting with `#'; see section Preprocessor Commands).

LightOJ1125 Divisible Group Sums

Divisible Group Sums Given a list of N numbers you will be allowed to choose any M of them. So you can choose in NCM ways. You will have to determine how many of these chosen groups have a sum, which is divisible by D. Input Input starts with an inte

SPOJ BALNUM Balanced Numbers(数位dp,状态压缩)

BALNUM - Balanced Numbers no tags 题目链接 Balanced numbers have been used by mathematicians for centuries. A positive integer is considered a balanced number if: 1)      Every even digit appears an odd number of times in its decimal representation 2)   

Codeforces Beta Round #51---D. Beautiful numbers(数位dp, 巧妙)

Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer number is beautiful if and only if it is divisible by each of its nonzero digits. We will not argue with this and just count the quantity of beautiful num

UVA - 12046 Great Numbers

Description Problem G - Great Numbers In this problem you have to count the number of great numbers of length n. Here a great number must have the following property: the number must be divisible by all of its decimal digits. it does not contain any

BZOJ 1662: [Usaco2006 Nov]Round Numbers 圆环数(数位DP+恶心细节)

BZOJ 1662: [Usaco2006 Nov]Round Numbers 圆环数 Time Limit: 5 Sec  Memory Limit: 64 MB Description 正如你所知,奶牛们没有手指以至于不能玩“石头剪刀布”来任意地决定例如谁先挤奶的顺序.她们甚至也不能通过仍硬币的方式. 所以她们通过"round number"竞赛的方式.第一头牛选取一个整数,小于20亿.第二头牛也这样选取一个整数.如果这两个数都是 "round numbers"

Beautiful numbers

Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer number is beautiful if and only if it is divisible by each of its nonzero digits. We will not argue with this and just count the quantity of beautiful num