D. Mahmoud and Ehab and another array construction task 因子分解模板

题意

给出一个原序列a 找出一个字典序大于a的序列b,使得任意 \(i!=j\),\(gcd(a[i],a[j])==1\),现在要你找出这样的序列b,并且满足所有合法序列中输出字典序最小的那个

思路

维护一个set,set里面装所有当前可以取的合法元素,先把所有的数字放进set里面,因为要求字典序最小的序列b,并且b的字典序要大于a,当构造的b到当前位置截止时和a相同时,每次在set里面二分找第一个大于等于当前位置a的值,当不相同时,直接每次取set的最小的元素也就是首元素以满足构造的b字典序最小

因子分界模板 (听说是nlog(n),有空证一下)

void init(){
for(int i=2;i<maxn;i++){
if(!vis[i]){
vis[i]=1;
for(int j=i;j<maxn;j+=i){
vis[j]=1;
v[j].pb(i);
}
}
}
}

AC代码

#include<bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define pii pair<int,int>
using namespace std;
const int maxn=2e6+200;
bool vis[maxn+5];
set<int>s;
vector<int>v[maxn];
void init(){
for(int i=2;i<maxn;i++){
if(!vis[i]){
vis[i]=1;
for(int j=i;j<maxn;j+=i){
vis[j]=1;
v[j].pb(i);
}
}
s.insert(i);
}
}
bool vis2[maxn];
int main(){
int n;
init();
scanf("%d",&n);
int tmp;
int flag=1;
for(int i=1;i<=n;i++){
scanf("%d",&tmp);
int now=*s.begin();
if(flag){
now=*s.lower_bound(tmp);
if(now!=tmp)flag=0;
}
//s.erase(now);
printf("%d ",now);
for(int &x:v[now]){
for(int j=x;j<maxn;j+=x){
if(!vis2[j]){
vis2[j]=1;
s.erase(j);
}
}
}
}
// for(int i=1;i<=n;i++)printf("%d ",ans[i]); return 0;
}

D. Mahmoud and Ehab and another array construction task 因子分界模板+贪心+数学的更多相关文章

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

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

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

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

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

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

  5. [CF959D]Mahmoud and Ehab and another array construction task题解

    解法 非常暴力的模拟. 一开始吧\(1 -> 2 \times 10^6\)全部扔进一个set里,如果之前取得数都是与原数组相同的,那么lower_bound一下找到set中大于等于它的数,否则 ...

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

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

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

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

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

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

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

随机推荐

  1. ubuntu set up 5 - VIM

    Edit ~/.vimrc source vimrc: :so ~/.vimrc 1. ctrl - left/right 切换tabs https://vim.fandom.com/wiki/Usi ...

  2. PAT (Advanced Level) Practice 1015 Reversible Primes (20 分)

    A reversible prime in any number system is a prime whose "reverse" in that number system i ...

  3. Cloud开发动态列的简单账表

    业务场景:客户需要根据过滤条件的不同显示不同的列.如下方式可以实现动态的列名. using System;using System.Collections.Generic;using System.L ...

  4. Oracle 12c 如何在 PDB 中添加 SCOTT 模式(手工方式)

    Oracle 12c 建库后,没有 scott 模式,本篇使用手工脚本方式,在12c版本中创建 scott 模式及相关表. 目录 1. PDB中创建用户 2. PDB中用户授权 3. PDB中创建表空 ...

  5. ES6实现图片切换特效

    效果图 demo.html <!DOCTYPE html> <html lang="en"> <head> <meta charset=& ...

  6. “公文流转系统 v1.0”

    1.项目需求: 河北金力集团是我省机械加工的龙头企业,主要从事矿山机械制造及各种机械零部件加工.企业有3个厂区,主厂区位于省高新技术开发区,3个分厂分别在保定.邢台和唐山.为增加企业的核心竞争力和加强 ...

  7. BZOJ-2424: [HAOI2010]订货【费用流】

    Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1487  Solved: 1002[Submit][Status][Discuss] Descript ...

  8. SVM-支持向量机(二)非线性SVM分类

    非线性SVM分类 尽管SVM分类器非常高效,并且在很多场景下都非常实用.但是很多数据集并不是可以线性可分的.一个处理非线性数据集的方法是增加更多的特征,例如多项式特征.在某些情况下,这样可以让数据集变 ...

  9. 记录 Docker 的学习过程 (日志篇)

    日志收集 elk 在node3上操作 docker pull sebp/elk:5610 node3# sysctl vm.max_map_count=262144 node3# docker run ...

  10. C++查看大端小端模式

    在学习计算机组成原理的时候,看到大端小端模式,便想实验一下,首先介绍一下 C 中的union,这个平时用得少,估计在单片机这种可能会运用,在平时写代码的时候几乎是用不着union的. union:联合 ...