C. Alyona and mex--思维水题

安路科技FPSoC开发实战:从芯片特性到边缘计算应用 本文深入解析安路科技FPSoC芯片在边缘计算领域的开发实战,重点介绍SALDRAGON系列芯片的异构计算架构优势,包括RISC-V/ARM处理器与FPGA的协同工作。通过工业控制和智能视觉应用案例,展示硬件加速实现与低功耗设计技巧,帮助开发者高效利用FPSoC进行边缘计算应用开发。 阅读详情

C. Alyona and mex
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special.

Alyona is a capricious girl so after she gets the array, she inspects m of its subarrays. Subarray is a set of some subsequent elements of the array. The i-th subarray is described with two integers li and ri, and its elements are a[li], a[li + 1], ..., a[ri].

Alyona is going to find mex for each of the chosen subarrays. Among these m mexes the girl is going to find the smallest. She wants this minimum mex to be as large as possible.

You are to find an array a of n elements so that the minimum mex among those chosen by Alyona subarrays is as large as possible.

The mex of a set S is a minimum possible non-negative integer that is not in S.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 105).

The next m lines contain information about the subarrays chosen by Alyona. The i-th of these lines contains two integers li and ri(1 ≤ li ≤ ri ≤ n), that describe the subarray a[li], a[li + 1], ..., a[ri].

Output

In the first line print single integer — the maximum possible minimum mex.

In the second line print n integers — the array a. All the elements in a should be between 0 and 109.

It is guaranteed that there is an optimal answer in which all the elements in a are between 0 and 109.

If there are multiple solutions, print any of them.

Examples
input
5 3
1 3
2 5
4 5
output
2
1 0 2 1 0
input
4 2
1 4
2 4
output
3
5 2 0 1
Note

The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray(4, 5) is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2.


题目链接:http://codeforces.com/contest/740/problem/C


啊啊啊!!!好不容易才读懂的题意,发现应该可以过,然后输出最大的最小mex出来了,那个队列怎么也出不来了,然后看了下别人的代码。

取余!!!取余!!!取余!!!取余!!!取余!!!取余!!!取余!!!取余!!!取余!!!取余!!!取余!!!取余!!!取余!!!取余!!!取余!!!取余!!!取余!!!取余!!!取余!!!取余!!!取余!!!取余!!!取余!!!取余!!!


果然我还是太渣了!!!

我的wa代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int a[20000];
int vis[20000];
struct node{
    int x,y;
}xin[20000];
bool cmp(struct node a,struct node b){
    return a.y-a.x<b.y-b.x;
}
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    memset(vis,0,sizeof(vis));
    for(int i=0;i<m;i++){
        scanf("%d%d",&xin[i].x,&xin[i].y);
    }
    sort(xin,xin+m,cmp);
    printf("%d\n",xin[0].y-xin[0].x+1);
    int k=xin[0].y-xin[0].x+1;
    for(int i=0;i<=n;i++){
        a[i]=k;
    }
    for(int i=0;i<m;i++){//亏我想了半天!!!各种姿势,想哭Q^Q
        int top=0;
        for(int j=xin[i].x;j<=xin[i].y;j++){
            if(!vis[j]){
                if(top==k)
                    break;
                vis[j]=1;
                a[j]=top++;
            }
        }
    }
    for(int i=1;i<=n;i++){
        printf(i==1?"%d":" %d",a[i]);
    }
    cout<<endl;
    return 0;
}
渣渣的正确代码(未交,赛后看题解打的)

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int a[20000];
int vis[20000];
struct node{
    int x,y;
}xin[20000];
bool cmp(struct node a,struct node b){
    return a.y-a.x<b.y-b.x;
}
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    memset(vis,0,sizeof(vis));
    for(int i=0;i<m;i++){
        scanf("%d%d",&xin[i].x,&xin[i].y);
    }
    sort(xin,xin+m,cmp);
    printf("%d\n",xin[0].y-xin[0].x+1);
    int k=xin[0].y-xin[0].x+1;
    for(int i=0;i<=n;i++){
        a[i]=k;
    }
    for(int i=1;i<=n;i++){//只需要一个简单的取余!!!Q^Q
        printf(i==1?"%d":" %d",i%k);
    }
    cout<<endl;
    return 0;
}



llama2-7b下载并转llama-2-7b-hf ④输入https://github.com/huggingface/transformers/blob/main/src/transformers/models/llama/convert_llama_weights_to_hf.py会下载 convert_llama_weights_to_hf.py 文件,我们需要用到这个文件将llama2-7b转成llama-2-7b-hf。③下载完之后是这四个文件,这里我是在windows操作系统中安装的WSL,没有linux操作系统,没办法。 阅读详情

相关推荐

VSCode搭配Keil开发STM32:从环境配置到代码跳转全流程(避坑指南)

本文详细介绍了如何使用VSCode搭配Keil进行STM32开发,从环境配置到代码跳转的全流程指南。通过安装必备插件和正确配置项目文件,开发者可以在VSCode中享受现代编辑器的便捷功能,同时保留Keil的编译调试能力,提升嵌入式开发效率。

weixin_28832121的博客 260

Codeforces Round #381 (Div. 2) C. Alyona and mex

题目大意:要构造一个长度为n的序列,从而使得在由给出的m个区间得到的m个mex值中的最小值 尽可能的大;一个区间的mex值代表不存在于这个区间中的最小的非负整数(有点绕...) 题解思路:解这题有两个突破口;第一个:只从题目给的那两个简单样例也可以发现最终结果的规律,就是结果只跟最短的区间长度有关(或者自己画多几个例子也都会发现的,,虽然我给不出严谨的证明=_=...)。 知道...

weixin_30466953的博客 147

STM32开发者必看:如何在正点原子探索者开发板上快速移植CANopenNode协议栈

本文为STM32开发者提供了在正点原子探索者开发板上快速移植CANopenNode协议栈的实战指南。文章详细介绍了从环境准备、硬件抽象层适配到协议栈初始化与测试的全过程,并分享了PDO配置与性能优化等关键技巧,帮助开发者高效实现CANopen标准化通信。

weixin_29173777的博客 475

740C.Alyona and mex codeforces

题意:找的每个子数组中的未出现的最小非负整数,即mex,然后在这些mex中找到最小的那个,并且使那个mex尽可能大。求出一个符合这些条件的数组。 思路:最小mex的值即所有区间里长度的最小值。求数组中每个元素的值即为他们的下标(0到n-1)对mex取余后的值,因为这样每mex个长度的数据,元素值都是从0到mex-1,这样在所有区间中所求的未出现的最小非负整数都是mex,题目上说找出符合题意的数组

ScorpioN___的博客 705

手把手教你用示波器测试DDR5 DRAM信号完整性(附眼图分析技巧)

本文详细介绍了如何使用示波器测试DDR5 DRAM信号完整性,包括眼图分析技巧。从DDR5的核心挑战、测试设备选型到实测工作流程,提供了全面的指导。特别强调了DFE功能验证和系统级协同测试,帮助工程师解决信号完整性问题,提升测试效率。

g2h3i4j5的博客 1186

CKA-题库-简洁参考答案-反复练习20遍-必过!!!

新版CKA考试已于2020年9月1日正式上线! 考试模式:线上考试 考试时间:2小时 认证有效期:3年 软件版本:Kubernetes v1.19 重考政策:可接受1次重考 经验水平:中級 题目数量:17题 题库量小:随机的题目重复率极高 考试时可打开两个浏览器Tab,一个是考试窗口,一个用来查阅官方文档](https://kubernetes.io/docs/) 01 Task - 英文 Create a new ClusterRole named deployment-clusterrole tha.

随笔记录-分享&记忆 7329

codeforces 构造 Alyona and mex

codeforces 构造 Alyona and mex

m0_62031207的博客 271

SAP CAP core data service 里 association 和 composition 的区别

我们进行 SAP CAP 开发时,在schema.cds里进行数据建模,可以使用 association 和 composition,来描述两个 entity 之间的关联关系。在 SAP BTP 的 Cloud Application Programming Model (CAP) 中,cds文件定义了数据模型,而和是用于建立实体关系的两种关键机制。理解它们的区别对于构建高效、清晰的 CAP 数据模型至关重要。下面,我们将通过严谨的逻辑推理,结合代码示例,深入分析和之间的核心差异。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 328

CodeForces 740C - Alyona and mex(思维)

C. Alyona and mex time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Alyona’s mother wants to present an array of n non-negative integers to

Snakeflute的博客 653

解决RabbitMq登录时报出Not management user(Login failed)错误以及rabbitmqctl(RabbitMq)新增用户和用户角色权限

解决RabbitMq登录时报出Not management user(Login failed)错误以及rabbitmqctl(RabbitMq)查看用户权限、新增用户和用户角色权限。

念兮为美 7484

硅电容的工艺结构原理及选型参数总结

硅电容,也称为硅质电容或硅二极管电容,是一种特殊的电容器。它利用硅二极管的结构来实现电容的功能。本文对硅电容的工作原理,结构特点,选型参数及设计注意事项进行总结。

fydar的博客 2348

A. Alyona and mex(取mod构造)

https://codeforces.com/problemset/problem/739/A 思路: 大的区间的mex要满足,里面其他小的区间mex要先满足,于是答案取决于最小的区间长度。 至于怎么输出方案,如果暴力n^2超时,其他结合数据结构感觉也不是很好处理。 但是可以构造。每次输出i%最小长度,这样可以保证每个[li​,ri​]的区间都包含[0,ri​−li​] #include<iostream> #include<vector> #include<...

代码笔记本 286

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

#381 Div2 Problem C Alyona and mex (思维 && 构造)

题意 : 题目的要求是构造出一个长度为 n 的数列, 构造条件是在接下来给出的 m 个子区间中, 要求每一个子区间的mex值最大, 然后在这 m 个子区间产生的mex值中取最小的输出, 并且输出构造出来的序列, 一个mex值的定义是这个区间没有出现过的最小的正整数, 例如(0, 2, 3)的mex = 1 (0, 1, 2)的mex=3 分析 : 发现在这m个mex值中, ...

113

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

C. Alyona and mex

http://codeforces.com/contest/740/problem/C 构造思维题。 第一直觉就是区间长度+1的最小值就是答案。 然而不知道怎么去构造这个序列、 其实就是每个区间,都要包含0、1、2、3、...ans - 1即可。 所以,只要不断0、1、2、3、4、...ans - 1、0、1、2、3、....这样放即可。 因为最小的区间长度是ans - 1,那么...

weixin_30511107的博客 109

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

Codeforces#381(Div. 2) C. Alyona and mex【思维】好题~

C. Alyona and mex time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Alyona's mother wants to present an array of n non-

mengxiang000000 691

Codeforces Round #381 (Div. 2)C. Alyona and mex(思维)

C. Alyona and mex Problem Description: Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special. Alyona is a capricious girl so after she ge...

weixin_30765505的博客 115

Codeforces Round #381 (Div. 2) C. Alyona and mex(思维)

C. Alyona and mex time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Alyona's mother wants to present an array

Marcus-Bao的个人主页 684

Codeforces Round #381 Div.2

A:Alyona and copybooks 题目大意:已经给了你n本书,你可以选择花a元买一本书,花b元买两本书(严格两本),花c元买三本书(严格三本),让你花最少的钱买x本书使得n+x为4的倍数。 思路:枚举一下买一本书,两本书,三本书的次数,然后统计答案即可。 #include<cmath> #include<cstdio> #include&...

V469584691的博客 296

Alyona and Mex(思路)

点击打开链接 题意分析:读懂题意后其实是很水很水的一道题。给定一串数字,每个数字都可以任意变小,再经过任意次变化(也可以不做改变)求在这串数字中缺少的最小的数字的最大值。 错因:题意理解错了 #include #include #include #include #include #include #include #include #include #include #inclu

smwqd_yehua_cx的博客 549

B. Alyona and Mex

http://codeforces.com/contest/682/problem/B 1 //超时 2 int[]a=new int[n]; 3 for (int i = 0; i < n; i++) a[i]=io.nextInt(); 4 Arrays.sort(a); 5 ...

ao9795的博客 245

Codeforces #381 C. Alyona and mex

C. Alyona and mex time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Alyona's mother wants to present an array

Tsaryu的博客 591

Codeforces Round #358 (Div. 2) B. Alyona and Mex

原题链接 B. Alyona and Mex time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Someone gave Alyona an array con

L. 503

Alyona and mex

Alyona and mex time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Alyona's mother wants to present an array ofnnon-n...

weixin_30296405的博客 158

CodeForces - 739A Alyona and mex ( 思维 且题意难理解 值得重做 )

/* 这题是属于值得重做,且题意比较难理解的类型 简单解释下我理解的题意: 输入数据: n(需要输出的序列的元素个数)、m ( subarray 的个数 ) 后面的 m 行分别表示 m 个 subarray的起止元素下标 (且下标从1开始) subarray:子序列,给出的 l 和 r 表示 1 个区间,从 a[l], a[l+1] .... a[r-1]

怕什么真理无穷?进一寸有一寸的欢喜~ 532

Codeforces Round #381 (Div. 2) C. Alyona and mex(模拟)

C. Alyona and mex time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Alyona’s mother wants to present an array of n non-negative integers to

Prim 947

Codeforces - 682C Alyona and the Tree

Description Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted tree with root in the vertex1, every vertex and every edge of which ...

JKdd123456的博客 344
上一篇: A. Alyona and copybooks--思维水题
下一篇: Rebuilding Roads--树形DP
bless295
博客等级 码龄11年 79粉丝 342原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值