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/11/2 23:48:07 阅读更多 →
Ryujinx模拟器终极技术指南:从架构解析到性能优化的完整实现方案

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

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

2026/10/30 15:47:39 阅读更多 →
Ubuntu原生安装Dify:生产环境部署与优化指南

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

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

2026/11/1 5:40:27 阅读更多 →

最新新闻

Electron桌面应用开发实战:从环境搭建到打包发布全流程

Electron桌面应用开发实战:从环境搭建到打包发布全流程

做前端这些年,我大部分时间都在跟浏览器标签页打交道,直到第一次把桌面应用跑起来,才发现原来自己一直被限制在地址栏和刷新按钮围起来的框框里。Electron这个词,最开始是在某段时间频繁出现在同事的讨论里,一个用HTML…

2026/11/2 0:25:10 阅读更多 →
滑盖智能锁T109深度解析:结构原理、安装调试与故障排查

滑盖智能锁T109深度解析:结构原理、安装调试与故障排查

简介:亚太天能T109滑盖智能锁产品说明书是一份PDF格式的官方技术文档,主要面向智能锁安装人员、终端用户及售后维护者,帮助快速掌握产品安装、配置与常见故障处理。全包仅1个PDF文件,大小4.37MB,内容结构清晰&#xff…

2026/11/2 10:46:11 阅读更多 →
PMSM弱磁控制原理与Simulink建模:高速AGV驱动系统设计指南

PMSM弱磁控制原理与Simulink建模:高速AGV驱动系统设计指南

上个月我在调试一台高速AGV的驱动系统,整车要求空载跑到8m/s,电机转速已经拉到额定点,驱动器的输出电压也顶到了母线电压极限附近。再往上踩速度指令,转速纹丝不动,三相电流反而开始震荡。那会儿我的第一反应就是&…

2026/11/2 10:47:40 阅读更多 →
C++核心知识点:从内存管理到STL的实战指南

C++核心知识点:从内存管理到STL的实战指南

C 这门语言我前前后后折腾了十几年,用它写过嵌入式驱动、做过游戏服务端,也搭过基础组件库。每次看到新人一头扎进"C 核心知识点"这个搜索词,我其实挺感慨的——这门语言的难点从来不是语法多,而是知识点之间的耦合太深…

2026/11/2 1:16:51 阅读更多 →
T109滑盖智能锁怎么装?安装调试与故障排查全攻略

T109滑盖智能锁怎么装?安装调试与故障排查全攻略

简介:亚太天能T109滑盖智能锁产品说明书以PDF格式发布,适合智能锁用户、安装人员与售后维修人员阅读。内容围绕T109系列指纹密码刷卡锁展开,先介绍前面板、后面板、锁体、机械钥匙、电池盒盖等部件名称与功能,再给出完整安装步骤&…

2026/11/2 10:46:31 阅读更多 →
LLM知识降熵:从信息垄断到理解权下放

LLM知识降熵:从信息垄断到理解权下放

你有没有过这种经历:翻开源码注释、论文摘要或者一份专业报告,每个字都认识,连在一起却像天书。想找人聊聊,身边要么没人懂,要么懂的懒得跟你解释。后来我试着把同一段内容丢给一个大语言模型,几秒钟之后&a…

2026/11/2 10:46:26 阅读更多 →

日新闻

周新闻

月新闻