当前位置:网站首页>#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";
}
边栏推荐
- 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)
- Leetcode hot topic Hot 100 day 33: "subset"
- 2021 electrician cup idea + code - photovoltaic building integration plate index development trend analysis and prediction: prediction planning issues
- Stage experience
- [phantom engine UE] the difference between running and starting, and the analysis of common problems
- [crampon programming] lintcode decoding Encyclopedia - 1100 strange printer
- The principle of attention mechanism and its application in seq2seq (bahadanau attention)
- Invalid bound statement (not found) in idea -- problem solving
- Mode in BST (binary tree & Notes on question brushing)
- Inline built-in function
猜你喜欢
Label exchange experiment
Function (basic: parameter, return value)
Download the details and sequence of the original data access from the ENA database in EBI
[groovy] closure (closure as function parameter | code example)
SQL set operation
托管式服务网络:云原生时代的应用体系架构进化
Function (error prone)
解密函数计算异步任务能力之「任务的状态及生命周期管理」
Power management bus (pmbus)
Special information | real estate and office buildings - 22.1.9
随机推荐
[groovy] closure (closure call | closure default parameter it | code example)
自动语音识别(ASR)研究综述
Error statuslogger log4j2 could not find a logging implementation
Mode in BST (binary tree & Notes on question brushing)
Special information | finance, accounting, audit - 22.1.23
Function (basic: parameter, return value)
[Chongqing Guangdong education] National Open University 2047t commercial bank operation and management reference test in autumn 2018
What are the building energy-saving software
[uniapp] system hot update implementation ideas
PHP读取ini文件并修改内容写入
Power management bus (pmbus)
SQL set operation
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)
JMeter -- distributed pressure measurement
Introduce Hamming distance and calculation examples
直播预告 | 容器服务 ACK 弹性预测最佳实践
Introduction to RT thread kernel (5) -- memory management
Download the details and sequence of the original data access from the ENA database in EBI
Official announcement! The third cloud native programming challenge is officially launched!
Invalid bound statement (not found) in idea -- problem solving