当前位置:网站首页>#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";
}
边栏推荐
- 次小生成树
- 电源管理总线 (PMBus)
- Error statuslogger log4j2 could not find a logging implementation
- Flink集群配置
- Variable category (automatic, static, register, external)
- Mode in BST (binary tree & Notes on question brushing)
- 线上故障突突突?如何紧急诊断、排查与恢复
- [ideas] 2021 may day mathematical modeling competition / May Day mathematical modeling ideas + references + codes
- The difference between bundle, chunk and module
- How can CIOs use business analysis to build business value?
猜你喜欢
Is there a sudden failure on the line? How to make emergency diagnosis, troubleshooting and recovery
Wan broadband access technology V EPON Technology
【acwing】528. cheese
Thematic information | carbon, carbon neutrality, low carbon, carbon emissions - 22.1.9
【acwing】836. Merge sets
Fonction (sujette aux erreurs)
CSDN正文自动生成目录
Web开发人员应该养成的10个编程习惯
【acwing】837. Number of connected block points
函数(基本:参数,返回值)
随机推荐
包 类 包的作用域
Power management bus (pmbus)
Introduce Hamming distance and calculation examples
[popular science] basic knowledge of thermal design: heat dissipation analysis of 5g optical devices
Private collection project practice sharing [Yugong series] February 2022 U3D full stack class 006 unity toolbar
[illusory engine UE] method to realize close-range rotation of operating objects under fuzzy background and pit recording
Components in protective circuit
防护电路中的元器件
【acwing】837. Number of connected block points
【acwing】240. food chain
Advanced length of redis -- deletion strategy, master-slave replication, sentinel mode
Raki's notes on reading paper: soft gazetteers for low resource named entity recognition
[crampon programming] lintcode decoding Encyclopedia - 1100 strange printer
English topic assignment (26)
Leetcode 222 number of nodes of complete binary tree
Variable category (automatic, static, register, external)
Interface joint commissioning test script optimization V5.0 (end)
Inline built-in function
Neural networks and deep learning Chapter 2: machine learning overview reading questions
电源管理总线 (PMBus)