解法

非常暴力的模拟。

一开始吧\(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题解的更多相关文章

  1. 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 ...

  2. codeforces-473D Mahmoud and Ehab and another array construction task (素数筛法+贪心)

    题目传送门 题目大意:先提供一个数组,让你造一个数组,这个数组的要求是 1 各元素之间都互质  2  字典序大于等于原数组  3 每一个元素都大于2 思路: 1.两个数互质的意思就是没有公因子.所以每 ...

  3. Codeforces 959D. Mahmoud and Ehab and another array construction task(构造, 简单数论)

    Codeforces 959D. Mahmoud and Ehab and another array construction task 题意 构造一个任意两个数都互质的序列,使其字典序大等于a序列 ...

  4. D. Mahmoud and Ehab and another array construction task 因子分界模板+贪心+数学

    D. Mahmoud and Ehab and another array construction task 因子分解模板 题意 给出一个原序列a 找出一个字典序大于a的序列b,使得任意 \(i!= ...

  5. 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 ...

  6. [CF959F]Mahmoud and Ehab and yet another xor task题解

    搞n个线性基,然后每次在上一次的基础上插入读入的数,前缀和线性基,或者说珂持久化线性基. 然后一个num数组记录当时线性基里有多少数 然后每次前缀操作一下就珂以了 代码 #include <cs ...

  7. Codeforces 959F Mahmoud and Ehab and yet another xor task 线性基 (看题解)

    Mahmoud and Ehab and yet another xor task 存在的元素的方案数都是一样的, 啊, 我好菜啊. 离线之后用线性基取check存不存在,然后计算答案. #inclu ...

  8. Codeforces 959 F. Mahmoud and Ehab and yet another xor task

    \(>Codeforces\space959 F. Mahmoud\ and\ Ehab\ and\ yet\ another\ xor\ task<\) 题目大意 : 给出一个长度为 \ ...

  9. 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的子序列 ...

随机推荐

  1. linux上搭建nginx+ftp,实现文件的上传与访问

    ftp服务器搭建 1.新建用户ftpuser并指定主目录为/home/ftpuser (注意:这个目录是后面存储和读取文件的目录) <!--创建用户并指定主目录--> useradd -d ...

  2. maximize_window()最大化浏览器和刷新当前页面refresh()

    from selenium import webdriverdriver = webdriver.Firefox()driver.get("https://www.baidu.com&quo ...

  3. Git016--Work

    GIT常用命令 git常用命令: //初始化git目录: $ git init //把当前目录变成git可以管理的仓库 //添加文件到暂存区 $ git add file //把文件添加到仓库 $ g ...

  4. Smashing Nodejs 读书笔记(二)

    了不起的Node.js:将JavaScript进行到底 书名:SMASHING Node.js : JavaScript Everywhere 原作者:(美)劳奇 Rauch.G 译者:赵静 出版日期 ...

  5. Java容器框架总结(一)

    本篇根据<Java编程思想> 第11章 持有对象 整理,总结Java容器框架中常用集合类及接口的特点及使用场景. (一)总结 1)数组将数字与对象联系起来:可以保存基本类型的数据:一旦生成 ...

  6. Node.js实战14:一个简单的TCP服务器。

    本文,将会展示如何用Nodejs内置的net模块开发一个TCP服务器,同时模拟一个客户端,并实现客户端和服务端交互. net模块是nodejs内置的基础网络模块,通过使用net,可以创建一个简单的tc ...

  7. 用jmeter监控服务器资源

    jmeter可以监控服务器CPU.内存等性能参数,只需要安装一些插件,比其他方法更简单  1.下载需要的jmeter插件 如图上面两个是jmeter插件,可以再下面的链接中下载: https://jm ...

  8. Redis 21问,你接得住不?

    作者:菜鸟小于 cnblogs.com/Young111/p/11518346.html 1.什么是redis? Redis 是一个基于内存的高性能key-value数据库. 2.Reids的特点 R ...

  9. [CCPC-Wannafly & Comet OJ 夏季欢乐赛(2019)]飞行棋

    题目链接:https://www.cometoj.com/contest/59/problem/E?problem_id=2714 求期望并且一堆转移基本上就是期望dp了(叉腰 照常的设dp[i]表示 ...

  10. 初识STM8S105K心得!

    最近由于公司项目需要STM8S105K这颗芯片,这两天我也捣鼓了下,正好现在开通了博客,以此记录下自己的工作. 开发环境:         window10操作系统:         IAR for ...