当前位置:网站首页>#775 Div.1 B. Integral Array 数学
#775 Div.1 B. Integral Array 数学
2022-07-05 04:43:00 【Strezia】
B
1800
题意
给出一个含 n n n 个数的序列 a 1 , a 2 , . . . , a n a_1,a_2,...,a_n a1,a2,...,an,并给出 c c c ,表示序列中所有数大小都不超过 c c c。我们称序列是整的当且仅当对于序列中任意两个(或同一个)数 x , y ( x ≤ y ) x,y(x\leq y) x,y(x≤y) , 满足 ⌊ y x ⌋ \lfloor \frac yx\rfloor ⌊xy⌋ 也在序列中。问这个序列是否是整的。 ( n ≤ 1 e 6 ) (n\leq1e6) (n≤1e6)
思路
这种题第一反应就是用类似素数筛的方法去优化,把对 r = ⌊ y x ⌋ r=\lfloor \frac yx\rfloor r=⌊xy⌋ 的判断改成对 y y y 的判断,不能拆成 x 和 r x和r x和r ”,所以可以枚举所有的 x x x,并枚举所有 r ∉ a r\notin a r∈/a , 如果在 x × r x\times r x×r 对应的范围内存在 y y y,则 r = ⌊ y x ⌋ ∉ a r=\lfloor \frac yx\rfloor\notin a r=⌊xy⌋∈/a ,不是整的。对应的范围即为 [ r × x , r × x + x − 1 ] [r\times x,r\times x + x - 1] [r×x,r×x+x−1],是否存在 y y y 只要预处理前缀和就可以了。
由调和级数,时间复杂度 O ( c log c ) O(c\log c) O(clogc) 。
代码
int cnt[maxn], sum[maxn];
void solve() {
int n, c;
cin >> n >> c;
for(int i = 1; i <= c; i++) cnt[i] = 0;
for(int i = 1; i <= n; i++) {
int x;
cin >> x;
cnt[x]++;
}
sum[0] = 0;
for(int i = 1; i <= c; i++) {
sum[i] = sum[i-1] + cnt[i];
}
for(int x = 1; x <= c; x++) {
if(!cnt[y]) {
continue;
}
for(int i = 1; i * x <= c; i++) {
if(cnt[i]) continue;
int l = i * x - 1;
int r = min((i+1)*x-1, c);
if(sum[r] - sum[l]) {
cout << "No\n";
return;
}
}
}
cout << "Yes\n";
}
边栏推荐
- mxnet导入报各种libcudart*.so、 libcuda*.so找不到
- [ideas] 2021 may day mathematical modeling competition / May Day mathematical modeling ideas + references + codes
- Basic analysis of IIC SPI protocol
- 函數(易錯)
- Practice | mobile end practice
- Sword finger offer 07 Rebuild binary tree
- 2021 higher education social cup mathematical modeling national tournament ABCD questions - problem solving ideas - Mathematical Modeling
- Group counting notes (1) - check code, original complement multiplication and division calculation, floating point calculation
- Leetcode hot topic Hot 100 day 33: "subset"
- Neural networks and deep learning Chapter 4: feedforward neural networks reading questions
猜你喜欢

Matplotlib draws three-dimensional scatter and surface graphs

Thematic information | carbon, carbon neutrality, low carbon, carbon emissions - 22.1.9

计组笔记(1)——校验码、原补码乘除计算、浮点数计算

File upload bypass summary (upload labs 21 customs clearance tutorial attached)

Moco is not suitable for target detection? MsrA proposes object level comparative learning target detection pre training method SOCO! Performance SOTA! (NeurIPS 2021)...

Function (error prone)

电源管理总线 (PMBus)

Fonction (sujette aux erreurs)

2021 higher education social cup mathematical modeling national tournament ABCD questions - problem solving ideas - Mathematical Modeling

2022-2028 global and Chinese FPGA prototype system Market Research Report
随机推荐
[AI bulletin 20220211] the hard core up owner has built a lidar and detailed AI accelerator
Flink集群配置
【acwing】837. Number of connected block points
[illusory engine UE] method to realize close-range rotation of operating objects under fuzzy background and pit recording
Looking at Chinese science and technology from the Winter Olympics: what is the mystery of the high-speed camera that the whole people thank?
函数(基本:参数,返回值)
Solution of circular dependency
Wan broadband access technology V EPON Technology
[groovy] closure (Introduction to closure class closure | this, owner, delegate member assignment and source code analysis)
[phantom engine UE] the difference between running and starting, and the analysis of common problems
Solutions and answers for the 2021 Shenzhen cup
[crampon programming] lintcode decoding Encyclopedia - 1100 strange printer
Scope of package class package
JVM 原理和流程简介
Special information | real estate and office buildings - 22.1.9
2022-2028 global and Chinese FPGA prototype system Market Research Report
About the prompt loading after appscan is opened: guilogic, it keeps loading and gets stuck. My personal solution. (it may be the first solution available in the whole network at present)
Introduction to RT thread kernel (4) -- clock management
Web开发人员应该养成的10个编程习惯
[crampon game] MC tutorial - first day of survival