首页 > 其他分享 >CF1083F The Fair Nut and Amusing Xor

CF1083F The Fair Nut and Amusing Xor

时间:2024-06-21 16:54:48浏览次数:11  
标签:Xor Fair Nut CF1083F 异或 Amusing

题意

给定两个长度为 \(n\) 的数列 \(a, b\),规定每次操作为选取一段长度为 \(k\) 的子段异或上任意自然数。

对于每次查询,先单点修改 \(a\) 或 \(b\),你需要求出最小的操作次数,或无法使得 \(a\) 在若干次操作后变为 \(b\)。

\(n \le 2 \times 10 ^ 5\)

Sol

差个分先,区间异或变为 \(i\) 与 \(i + k\) 异或。

套路的,对于 \(mod k\) 分组,拉出来 \(k\) 条链,问题转化为对于每条链,相邻两个数同时异或 \(x\),使得数列全部变为 \(0\)。

然后你不难发现,无解情况就是每条链地前缀异或最后不为 \(0\)。

显然直接从前往后就是最优策略,而操作次数就是 \(n\) 减去前缀异或值为 \(0\) 的个数。

直接上个分块,\(O(n \sqrt n)\) 做完了。

标签:Xor,Fair,Nut,CF1083F,异或,Amusing
From: https://www.cnblogs.com/cxqghzj/p/18260884

相关文章

  • World Tour Finals 2022 Day2 E: Adjacent Xor Game
    考虑从高到低位做,不断贪心的一个过程。即假设把当前所有数\(a_i\)看成\(\lfloor\frac{a_i}{2^d}\rfloor\),有当前最优答案\(ans_d\);现在把所有数看成\(\lfloor\frac{a_i}{2^{d-1}}\rfloor\),推出下一步的答案\(ans_{d-1}\)。假设\(/2^d\)时,每一步xor完的序列是\(a_1......
  • WPF Path GeometryCombineMode Union, Exclude,Intersect,Xor
    union<Windowx:Class="WpfApp172.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.mi......
  • XOR的艺术
    #include<iostream>#include<cstdio>#include<cstring>#include<string>#include<cmath>#include<algorithm>#include<cstdlib>#include<set>#include<map>#include<vector>#include<qu......
  • 利用SpringBeanUtil 来获取 IOC 容器中的bean
    有时候在代码中,不希望使用自动注入,而是手动获取Spring容器以及Spring容器中的某个对象1、首先写一个class实现ApplicationContextAware#importorg.springframework.beans.BeansException;importorg.springframework.context.ApplicationContext;importorg.springframework......
  • Golang-编码加密-Xor(GG)
    go语言环境搭建Golang学习日志━━下载及安装_golang下载-CSDN博客  gorunxxx.go  gobuildxxx.go 首先,cs.msf生成比特流数据. 放入xor,py脚本中进行xor加密. xor.pydefxor(shellcode,key):new_shellcode=""key_len=len(key)......
  • [ABC126F] XOR Matching 题解
    很好的构造题。题意请构造一个长度为$2^{m+1}$的序列$a$,该序列满足:$\foralli\in[1,2^{m+1}],a_i\in[0,2^m-1]$且每个数都恰好出现两次。对于任意一对$(i,j)$满足$a_i=a_j$,$a_i\oplusa_{i+1}\oplus\cdots\oplusa_{j-1}\oplusa_j=k$。$\oplus$表......
  • Flutter 中的 PopupMenuTheme 小部件:全面指南
    Flutter中的PopupMenuTheme小部件:全面指南Flutter是一个由Google开发的跨平台UI框架,它允许开发者使用Dart语言构建美观、响应式的移动、Web和桌面应用。Flutter的Material组件库中包含了丰富的UI组件,其中PopupMenuButton是一个允许用户从下拉菜单中选择......
  • D. XORificator
    D.XORificatorYouaregivenabinary(consistingonlyof0sand1s)$n\timesm$matrix.YouarealsogivenaXORificator,usingwhichyoucaninvertallthevaluesinachosenrow(i.e.replace0with1and1with0).Acolumninthematrixisconsider......
  • Quanutm machine learning demos from pennylane
    QubitrotationUsingqubitrotationexampletounderstandbasicsyntaxofpennylane,gradientdescent.Seethislinkformoredetails.importpennylaneasqmlfromjaximportnumpyasnpimportjaximportjaxoptdev1=qml.device("lightning.qubit&qu......
  • CF 948 DIV.2 D. XORificator
    考虑对每个设置为1且唯一那么我们发现对于所有的状态都是确定且唯一的那么我们对于每个点假设它为1且为该列唯一对于除它之外的点的状态进行存储又由于这个值过于大我们考虑使用哈希存储那么出现次数最多的值即为答案点击查看代码map<ull,int>cnt;map<ull,pii>pos;void......