当前位置:网站首页>#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";
}
边栏推荐
- Download the details and sequence of the original data access from the ENA database in EBI
- Flutter 小技巧之 ListView 和 PageView 的各种花式嵌套
- 线上故障突突突?如何紧急诊断、排查与恢复
- 次小生成树
- PR video clip (project packaging)
- Fluent objects and lists
- What are the building energy-saving software
- Raki's notes on reading paper: code and named entity recognition in stackoverflow
- Is $20billion a little less? Cisco is interested in Splunk?
- Decryption function calculates "task state and lifecycle management" of asynchronous task capability
猜你喜欢
Aperçu en direct | Services de conteneurs ACK flexible Prediction Best Practices
[phantom engine UE] the difference between running and starting, and the analysis of common problems
Qt蓝牙:搜索蓝牙设备的类——QBluetoothDeviceDiscoveryAgent
【acwing】837. Number of connected block points
介绍汉明距离及计算示例
Special information | real estate and office buildings - 22.1.9
Flutter 小技巧之 ListView 和 PageView 的各种花式嵌套
The 22nd Spring Festival Gala, an immersive stage for the yuan universe to shine into reality
首席信息官如何利用业务分析构建业务价值?
[Business Research Report] Research Report on male consumption trends in other economic times -- with download link
随机推荐
2021 electrician cup idea + code - photovoltaic building integration plate index development trend analysis and prediction: prediction planning issues
[uniapp] system hot update implementation ideas
Download the details and sequence of the original data access from the ENA database in EBI
取余操作是一个哈希函数
Private collection project practice sharing [Yugong series] February 2022 U3D full stack class 006 unity toolbar
[groovy] closure (closure call | closure default parameter it | code example)
[phantom engine UE] the difference between running and starting, and the analysis of common problems
直播預告 | 容器服務 ACK 彈性預測最佳實踐
[PCL self study: feature9] global aligned spatial distribution (GASD) descriptor (continuously updated)
指针函数(基础)
揭秘技术 Leader 必备的七大清奇脑回路
[crampon programming] lintcode decoding Encyclopedia - 872 termination process
Sword finger offer 04 Search in two-dimensional array
托管式服务网络:云原生时代的应用体系架构进化
Function template
Pointer function (basic)
2021 huashubei mathematical modeling idea + reference + paper
函數(易錯)
Function (error prone)
Basic analysis of IIC SPI protocol