[CF959D]Mahmoud and Ehab and another array construction task题解
解法
非常暴力的模拟。
一开始吧\(1 -> 2 \times 10^6\)全部扔进一个set里,如果之前取得数都是与原数组相同的,那么lower_bound一下找到set中大于等于它的数,否则直接取set中最小的数,然后枚举该数的所有质因数及其倍数,类似埃拉托斯特尼筛法删掉它们(如果它们在集合中的话)。
P.S. 不要用STL algorithm的lower_bound,极慢,用STL内部自带的lower_bound,快很多!
代码
#include <cstdio>
#include <set>
#include <algorithm>
#define ll long long
using namespace std;
inline int read(){
int x = 0; int zf = 1; char ch = ' ';
while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') zf = -1, ch = getchar();
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * zf;
}
int a[100005];
set<int> st;
int main(){
int n = read();
for (int i = 1; i <= n; ++i)
a[i] = read();
for (int i = 2; i <= 2e6; ++i)
st.insert(i);
bool flg = 0; int val; set<int>::iterator it;
for (int i = 1; i <= n; ++i){
(!flg) ? it = st.lower_bound(a[i]) : it = st.begin();
val = *it;
if (val > a[i]) flg = 1;
if (i != 1) printf(" ");
printf("%d", val);
st.erase(val);
for (int j = 2; j * j <= val; ++j){
if (!(val % j)){
for (int k = j; k <= 2e6; k += j)
st.erase(k);
}
while (!(val % j))
val /= j;
}
if (val > 1)
for (int k = val; k <= 2e6; k += val)
st.erase(k);
}
return 0;
}
[CF959D]Mahmoud and Ehab and another array construction task题解的更多相关文章
- CF959D Mahmoud and Ehab and another array construction task 数学
Mahmoud has an array a consisting of n integers. He asked Ehab to find another array b of the same l ...
- codeforces-473D Mahmoud and Ehab and another array construction task (素数筛法+贪心)
题目传送门 题目大意:先提供一个数组,让你造一个数组,这个数组的要求是 1 各元素之间都互质 2 字典序大于等于原数组 3 每一个元素都大于2 思路: 1.两个数互质的意思就是没有公因子.所以每 ...
- Codeforces 959D. Mahmoud and Ehab and another array construction task(构造, 简单数论)
Codeforces 959D. Mahmoud and Ehab and another array construction task 题意 构造一个任意两个数都互质的序列,使其字典序大等于a序列 ...
- D. Mahmoud and Ehab and another array construction task 因子分界模板+贪心+数学
D. Mahmoud and Ehab and another array construction task 因子分解模板 题意 给出一个原序列a 找出一个字典序大于a的序列b,使得任意 \(i!= ...
- Codeforces 959 D Mahmoud and Ehab and another array construction task
Discription Mahmoud has an array a consisting of n integers. He asked Ehab to find another arrayb of ...
- [CF959F]Mahmoud and Ehab and yet another xor task题解
搞n个线性基,然后每次在上一次的基础上插入读入的数,前缀和线性基,或者说珂持久化线性基. 然后一个num数组记录当时线性基里有多少数 然后每次前缀操作一下就珂以了 代码 #include <cs ...
- Codeforces 959F Mahmoud and Ehab and yet another xor task 线性基 (看题解)
Mahmoud and Ehab and yet another xor task 存在的元素的方案数都是一样的, 啊, 我好菜啊. 离线之后用线性基取check存不存在,然后计算答案. #inclu ...
- Codeforces 959 F. Mahmoud and Ehab and yet another xor task
\(>Codeforces\space959 F. Mahmoud\ and\ Ehab\ and\ yet\ another\ xor\ task<\) 题目大意 : 给出一个长度为 \ ...
- 959F - Mahmoud and Ehab and yet another xor task xor+dp(递推形)+离线
959F - Mahmoud and Ehab and yet another xor task xor+dp+离线 题意 给出 n个值和q个询问,询问l,x,表示前l个数字子序列的异或和为x的子序列 ...
随机推荐
- Oracle-优化SQL语句
建议不使用(*)来代替所有列名 用truncate代替delete 在SQL*Plus环境中直接使用truncate table即可:要在PL/SQL中使用,如: 创建一个存储过程,实现使用trunc ...
- Oracle 11g客户端下载地址
Oracle 11g客户端下载地址: http://www.cr173.com/soft/36349.html
- python 每周作业
day2:python的简介与认识day2:# 1.写一个登录程序# username# passwd# 让用户输入账号和密码,输入用户和密码输入正确的话# 提示你 xxx,欢迎登录,今天的日期是xx ...
- Angular5 错误: ngModel cannot be used to register form controls with a parent formGroup directive
在创建一个表单时,出现了这样的错误: 原因是,在最外层的form中使用了 formGroup 指令,但在下面的某个input 元素中,使用了ngModel 指令,但没有加入formControl 指令 ...
- 洛谷 P1108 低价购买(LIS,统计方案数)
传送门 解题思路 看第一个要求,很显然是求最长下降子序列,和LIS几乎一样,很简单,再看第二个问号,求最长下降子序列的方案数??这怎么求? 注意:当二种方案“看起来一样”时(就是说它们构成的价格队列一 ...
- [LOJ2736] [JOISC 2016 Day 3] 回转寿司 (分块+堆)
[LOJ2736] [JOISC 2016 Day 3] 回转寿司 (分块+堆) 题面 给出一个有n 个点的环,环上各点有一个初始权值 \(a_i\) 给出 Q 个询问,每次询问给出一个区间 [l,r ...
- SCUT - 131 - 小P玩游戏II - 贪心 - 平衡树
https://scut.online/p/131 首先假如钦定了一群人去打怪兽,那么可以把主要的任务都丢给b最大的人去打,这样不会更差.然后考虑枚举这个b最大的人,其他人陪练.一开始就是ai+k*b ...
- .net easyui Tree树
原文:https://www.cnblogs.com/hantianwei/archive/2012/03/19/2407118.html Tree 树 用 $.fn.tree.defaults ...
- 【推荐系统】知乎live入门1.推荐概览与框架
参考链接 [推荐系统]知乎live入门 目录 1.推荐概览与框架 2. 推荐系统的架构和模块 3. 推荐召回 4. 排序 5. 用户画像 6. 特征工程 7. 回归到推荐算法 总结 参考文献 ==== ...
- 定时器,定时发邮件JavaMail
一.定时器用法: 1.1先导入jar包 <!--spring整合其他文件时要用的jar包--> <dependency> <groupId>org.springfr ...