cf----2019-09-01( Appending Mex,Changing Array,Candies Distribution)
人群淹没你我不及诉说。一声雁过往事如昨。只望离别不多再赏盛世烟火。Initially Ildar has an empty array. He performs nn steps. On each step he takes a subset of integers already added to the array and appends the mex of this subset to the array.The mex of an multiset of integers is the smallest non-negative integer not presented in the multiset. For example, the mex of the multiset [0,2,3][0,2,3] is 11, while the mex of the multiset [1,2,1][1,2,1] is 00.More formally, on the step mm, when Ildar already has an array a1,a2,…,am−1a1,a2,…,am−1, he chooses some subset of indices 1≤i1i2…ikm1≤i1i2…ikm (possibly, empty), where 0≤km0≤km, and appends the mex(ai1,ai2,…aik)mex(ai1,ai2,…aik) to the end of the array.After performing all the steps Ildar thinks that he might have made a mistake somewhere. He asks you to determine for a given array a1,a2,…,ana1,a2,…,an the minimum step tt such that he has definitely made a mistake on at least one of the steps 1,2,…,t1,2,…,t, or determine that he could have obtained this array without mistakes.InputThe first line contains a single integer nn (1≤n≤1000001≤n≤100000) — the number of steps Ildar made.The second line contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤1090≤ai≤109) — the array Ildar obtained.OutputIf Ildar could have chosen the subsets on each step in such a way that the resulting array is a1,a2,…,ana1,a2,…,an, print −1−1.Otherwise print a single integer tt — the smallest index of a step such that a mistake was made on at least one step among steps 1,2,…,t1,2,…,t.ExamplesinputCopy4 0 1 2 1outputCopy-1inputCopy3 1 0 1outputCopy1inputCopy4 0 1 2 239outputCopy4NoteIn the first example it is possible that Ildar made no mistakes. Here is the process he could have followed.11-st step. The initial array is empty. He can choose an empty subset and obtain 00, because the mex of an empty set is 00. Appending this value to the end he gets the array [0][0].22-nd step. The current array is [0][0]. He can choose a subset [0][0] and obtain an integer 11, because mex(0)1mex(0)1. Appending this value to the end he gets the array [0,1][0,1].33-rd step. The current array is [0,1][0,1]. He can choose a subset [0,1][0,1] and obtain an integer 22, because mex(0,1)2mex(0,1)2. Appending this value to the end he gets the array [0,1,2][0,1,2].44-th step. The current array is [0,1,2][0,1,2]. He can choose a subset [0][0] and obtain an integer 11, because mex(0)1mex(0)1. Appending this value to the end he gets the array [0,1,2,1][0,1,2,1].Thus, he can get the array without mistakes, so the answer is −1−1.In the second example he has definitely made a mistake on the very first step, because he could not have obtained anything different from 00.In the third example he could have obtained [0,1,2][0,1,2] without mistakes, but 239239 is definitely wrong.#include iostream #include cstdio #include algorithm #include string #include cstring #include cstdlib #include cmath #include stack #include queue #include set #include map #include vector #include ctime #include cctype #include bitset #include utility #include sstream #include complex #include iomanip #define inf 0x3f3f3f3f typedef long long ll; using namespace std; int s[100010]; int N,X,mx-1; int main() { scanf(%d,N); for(int i1; iN; i) { scanf(%d,X); if(Xmx1) { printf(%d\n,i); return 0; } mxmax(mx,X); } printf(-1\n); return 0; }At a break Vanya came to the class and saw an array of nn kk-bit integers a1,a2,…,ana1,a2,…,an on the board. An integer xx is called a kk-bit integer if 0≤x≤2k−10≤x≤2k−1.Of course, Vanya was not able to resist and started changing the numbers written on the board. To ensure that no one will note anything, Vanya allowed himself to make only one type of changes: choose an index of the array ii (1≤i≤n1≤i≤n) and replace the number aiai with the number ai¯¯¯¯ai¯. We define x¯¯¯x¯ for a kk-bit integer xx as the kk-bit integer such that all its kk bits differ from the corresponding bits of xx.Vanya does not like the number 00. Therefore, he likes such segments [l,r][l,r] (1≤l≤r≤n1≤l≤r≤n) such that al⊕al1⊕…⊕ar≠0al⊕al1⊕…⊕ar≠0, where ⊕⊕ denotes the bitwise XOR operation. Determine the maximum number of segments he likes Vanya can get applying zero or more operations described above.InputThe first line of the input contains two integers nn and kk (1≤n≤2000001≤n≤200000, 1≤k≤301≤k≤30).The next line contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤2k−10≤ai≤2k−1), separated by spaces — the array of kk-bit integers.OutputPrint one integer — the maximum possible number of segments with XOR not equal to 00 that can be obtained by making several (possibly 00) operations described in the statement.ExamplesinputCopy3 2 1 3 0outputCopy5inputCopy6 3 1 4 4 7 3 4outputCopy19NoteIn the first example if Vasya does not perform any operations, he gets an array that has 55 segments that Vanya likes. If he performs the operation with i2i2, he gets an array [1,0,0][1,0,0], because 3¯¯¯03¯0 when k2k2. This array has 33 segments that Vanya likes. Also, to get an array with 55 segments that Vanya likes, he can perform two operations with i3i3 and with i2i2. He then gets an array [1,0,3][1,0,3]. It can be proven that he cant obtain 66 or more segments that he likes.In the second example, to get 1919 segments that Vanya likes, he can perform 44 operations with i3i3, i4i4, i5i5, i6i6 and get an array [1,4,3,0,4,3][1,4,3,0,4,3].给出n个数字他们可以被替换为自身按位取反的数给出区间[ l , r ]询问在这段区间内异或和不为零的区间的个数。#include iostream #include cstdio #include algorithm #include string #include cstring #include cstdlib #include cmath #include stack #include queue #include set #include map #include vector #include ctime #include cctype #include bitset #include utility #include sstream #include complex #include iomanip #define inf 0x3f3f3f3f typedef long long ll; using namespace std; ll N,K,sum[200010],jg; mapll,llmp; int main() { ll x,d1,d2; scanf(%lld%lld,N,K); ll ls(1K)-1;//2^k for(int i1; iN; i) { scanf(%lld,sum[i]); sum[i]^sum[i-1]; mp[min(sum[i],sum[i]^ls)]; } mp[0]; jgN*(N1)/2; mapll,ll::iterator it; for(itmp.begin(); it!mp.end(); it) { xit-second; d1x/2; d2x-d1; jg-d1*(d1-1)/2; jg-d2*(d2-1)/2; } printf(%lld\n,jg); return 0; }There are nn children numbered from 11 to nn in a kindergarten. Kindergarten teacher gave aiai (1≤ai≤n1≤ai≤n) candies to the ii-th child. Children were seated in a row in order from 11 to nn from left to right and started eating candies.While the ii-th child was eating candies, he calculated two numbers lili and riri — the number of children seating to the left of him that got more candies than he and the number of children seating to the right of him that got more candies than he, respectively.Formally, lili is the number of indices jj (1≤ji1≤ji), such that aiajaiaj and riri is the number of indices jj (ij≤nij≤n), such that aiajaiaj.Each child told to the kindergarten teacher the numbers lili and riri that he calculated. Unfortunately, she forgot how many candies she has given to each child. So, she asks you for help: given the arrays ll and rr determine whether she could have given the candies to the children such that all children correctly calculated their values lili and riri, or some of them have definitely made a mistake. If it was possible, find any way how she could have done it.InputOn the first line there is a single integer nn (1≤n≤10001≤n≤1000) — the number of children in the kindergarten.On the next line there are nn integers l1,l2,…,lnl1,l2,…,ln (0≤li≤n0≤li≤n), separated by spaces.On the next line, there are nn integer numbers r1,r2,…,rnr1,r2,…,rn (0≤ri≤n0≤ri≤n), separated by spaces.OutputIf there is no way to distribute the candies to the children so that all of them calculated their numbers correctly, print «NO» (without quotes).Otherwise, print «YES» (without quotes) on the first line. On the next line, print nn integers a1,a2,…,ana1,a2,…,an, separated by spaces — the numbers of candies the children 1,2,…,n1,2,…,n received, respectively. Note that some of these numbers can be equal, but all numbers should satisfy the condition 1≤ai≤n1≤ai≤n. The number of children seating to the left of the ii-th child that got more candies than he should be equal to lili and the number of children seating to the right of the ii-th child that got more candies than he should be equal to riri. If there is more than one solution, find any of them.ExamplesinputCopy5 0 0 1 1 2 2 0 1 0 0outputCopyYES 1 3 1 2 1inputCopy4 0 0 2 0 1 1 1 1outputCopyNOinputCopy3 0 0 0 0 0 0outputCopyYES 1 1 1NoteIn the first example, if the teacher distributed 11, 33, 11, 22, 11 candies to 11-st, 22-nd, 33-rd, 44-th, 55-th child, respectively, then all the values calculated by the children are correct. For example, the 55-th child was given 11 candy, to the left of him 22 children were given 11 candy, 11child was given 22 candies and 11 child — 33 candies, so there are 22 children to the left of him that were given more candies than him.In the second example it is impossible to distribute the candies, because the 44-th child made a mistake in calculating the value of r4r4, because there are no children to the right of him, so r4r4 should be equal to 00.In the last example all children may have got the same number of candies, thats why all the numbers are 00. Note that each child should receive at least one candy.n个小朋友排排坐吃糖小朋友从左到右编号1到n。每个小朋友手上有一定数量的糖。对于第i个小朋友来说编号比他小的小朋友中有li个小朋友拥有的糖比他多编号比他大的小朋友中有ri个小朋友拥有的糖比他多。已知每个小朋友手上至少有1颗糖、最多有n颗糖求一种可能的每个小朋友手上的糖的数量的情形输出YES和一种情形如果不存在这样的可能则输出NO。#include iostream #include cstdio #include algorithm #include string #include cstring #include cstdlib #include cmath #include stack #include queue #include set #include map #include vector #include ctime #include cctype #include bitset #include utility #include sstream #include complex #include iomanip #define inf 0x3f3f3f3f typedef long long ll; using namespace std; int N,ri,li; struct node { int l; int r; int jg; } p[1010]; int main() { scanf(%d,N); for(int i1; iN; i) scanf(%d,p[i].l); for(int i1; iN; i) scanf(%d,p[i].r); for(int i1; iN; i) p[i].jgN-(p[i].lp[i].r); for(int i1; iN; i) { li0; for(int j1; ji; j) if(p[j].jgp[i].jg) li; ri0; for(int ji1; jN; j) if(p[j].jgp[i].jg) ri; if(li!p[i].l||ri!p[i].r) { printf(NO\n); return 0; } } printf(YES\n); for(int i 1; i N; i) printf(%d , p[i].jg); return 0; }

相关新闻

3步轻松备份:GetQzonehistory帮你完整导出QQ空间全部历史说说

3步轻松备份:GetQzonehistory帮你完整导出QQ空间全部历史说说

3步轻松备份:GetQzonehistory帮你完整导出QQ空间全部历史说说 【免费下载链接】GetQzonehistory 获取QQ空间发布的历史说说 项目地址: https://gitcode.com/GitHub_Trending/ge/GetQzonehistory 你是否曾为QQ空间里那些珍贵的青春回忆无法完整保存而烦恼&…

2026/7/28 18:46:17 阅读更多 →
Ryujinx模拟器终极技术指南:从架构解析到性能优化的完整实现方案

Ryujinx模拟器终极技术指南:从架构解析到性能优化的完整实现方案

Ryujinx模拟器终极技术指南:从架构解析到性能优化的完整实现方案 【免费下载链接】Ryujinx 用 C# 编写的实验性 Nintendo Switch 模拟器 项目地址: https://gitcode.com/GitHub_Trending/ry/Ryujinx 在PC平台上运行Nintendo Switch游戏面临诸多技术挑战&…

2026/7/28 18:46:17 阅读更多 →
Ubuntu原生安装Dify:生产环境部署与优化指南

Ubuntu原生安装Dify:生产环境部署与优化指南

1. 为什么选择Ubuntu本地安装Dify在技术选型时,我放弃了更简单的Docker方案而选择原生安装,主要基于三个实际考量。首先,生产环境中我们经常需要深度定制AI工作流的底层组件,Docker的隔离性反而会成为调试障碍。上周我就遇到一个案…

2026/7/28 18:46:17 阅读更多 →

最新新闻

Mac VS Code快捷键(外接键盘)

Mac VS Code快捷键(外接键盘)

1. 多行注释:Win /2. 格式化代码:Shift Alt F

2026/7/28 18:57:20 阅读更多 →
14自由度整车模型在汽车动力学仿真中的应用与实践

14自由度整车模型在汽车动力学仿真中的应用与实践

1. 为什么需要14自由度整车模型在汽车工程领域,整车动力学建模一直是研发过程中的核心环节。14自由度整车模型之所以成为行业标准配置,是因为它完美平衡了计算精度与仿真效率这对矛盾体。传统简化模型(如4自由度或7自由度)虽然计算…

2026/7/28 18:57:20 阅读更多 →
CSRF攻击原理深度解析与全方位防御实战指南

CSRF攻击原理深度解析与全方位防御实战指南

1. 项目概述:为什么CSRF攻击至今仍是Web安全的“隐形杀手”? 在Web安全领域,XSS(跨站脚本攻击)和SQL注入的名声如雷贯耳,相比之下,CSRF(跨站请求伪造)攻击显得有些“低调…

2026/7/28 18:57:20 阅读更多 →
imgproxy安全加固实战:CORS配置、请求限制与漏洞防范

imgproxy安全加固实战:CORS配置、请求限制与漏洞防范

1. 项目概述:为什么你的imgproxy需要“终极”加固? 如果你正在用imgproxy处理图片,并且把它直接暴露在公网上,那这篇文章就是为你写的。我见过太多团队,把imgproxy部署起来,配个域名,就以为万事…

2026/7/28 18:57:20 阅读更多 →
多语种唇形对齐怎么选?跨境 AI 视频生成接口横向测评

多语种唇形对齐怎么选?跨境 AI 视频生成接口横向测评

跨境电商短视频、海外社交媒体数字人口播、多语言品牌宣传片持续放量,多语种音频驱动 AI 视频接口成为出海内容生产核心基础设施。该类接口接收多语种音频文件作为输入,驱动画面人物匹配语音生成自然唇形、面部表情,实现同一段素材快速适配多…

2026/7/28 18:57:20 阅读更多 →
计算机毕业设计之洗澡啦小程序

计算机毕业设计之洗澡啦小程序

由于移动应用技术的持续性的快速发展,现实生活中人们大多数都是通过移动手机、电脑等智能设备来完成生活中的事务。因此,许多的人工传统行业也开始与互联网结合,不再一味的依靠人工手动,努力打造半自动数字化甚至是全自动数字化模…

2026/7/28 18:56:20 阅读更多 →

日新闻

告别臃肿!3步让你的暗影精灵笔记本重获新生

告别臃肿!3步让你的暗影精灵笔记本重获新生

告别臃肿!3步让你的暗影精灵笔记本重获新生 【免费下载链接】OmenSuperHub Control Omen laptop performance, fan speeds, and keyboard lighting, and unlock power limits. 项目地址: https://gitcode.com/gh_mirrors/om/OmenSuperHub 你是否也曾为官方Om…

2026/7/28 0:00:43 阅读更多 →
RAG必踩坑!财报法规检索不准?这款开源工具让答案浮出水面,准确率飙升98.7%!

RAG必踩坑!财报法规检索不准?这款开源工具让答案浮出水面,准确率飙升98.7%!

做 RAG 的人应该都踩过这个致命的坑:把几百页的财报、法规、技术手册扔给向量库,问一个具体问题,搜出来的全是沾边但没用的内容 —— 关键信息要么被硬切块拆碎了,要么藏在几十条结果的最下面。语义相似≠真正相关,这个…

2026/7/28 0:00:43 阅读更多 →
抖音视频文案提取工具全指南:免费2026版、手机App、在线工具一网打尽

抖音视频文案提取工具全指南:免费2026版、手机App、在线工具一网打尽

2026年做短视频运营,从抖音上扒文案早就不是偷偷抄笔记的事了。我刚开始做内容的时候,每天刷半小时抖音,手动把爆款视频的口播敲进备忘录,一条2分钟的视频得花十来分钟,碰到语速快的还要反复回听。后来试了一圈工具&am…

2026/7/28 0:00:43 阅读更多 →

周新闻

深度学习道路桥梁裂缝检测系统 道路桥梁裂缝检测数据集 道路桥梁病害识别检测数据集

深度学习道路桥梁裂缝检测系统 道路桥梁裂缝检测数据集 道路桥梁病害识别检测数据集

深度学习道路桥梁裂缝检测系统 数据集6000张 完整源码已标注数据集训练好的模型环境配置教程程序运行说明文档,可以直接使用!系统支持图片、视频、摄像头等多种方式检测裂缝,功能强大实用。 1数据集6000张 8各类别

2026/7/28 12:04:22 阅读更多 →
深度学习YOLO模型如何训练 PUBG 绝地求生目标检测数据集

深度学习YOLO模型如何训练 PUBG 绝地求生目标检测数据集

pubg数据集 精选原图1.42万数据 1.49万标签 无任何重复、算法增强或冗余图像! pubg绝地求生目标检测数据集 1分类:e_body,14905个标签,txt格式 共计14244张图,99%为640*640尺寸图像 适合yolo目标检测、AI训练关键词&am…

2026/7/28 8:29:16 阅读更多 →
Apex英雄目标检测数据集 深度学习框架YOLO如何训练APEX数据集

Apex英雄目标检测数据集 深度学习框架YOLO如何训练APEX数据集

Apex检测数据集数据集详情检测类别: allies enemy tag图片总量:7247张训练集:5139张验证集:1425张测试集:683张标注状态:全部已标注,即拿即用数据格式:支持YOLO格式及其他格式&#…

2026/7/28 5:03:42 阅读更多 →

月新闻