跳到正文

题解

题解:CF2268C KiaKio and Energy Intervals

TrueGod约 2 分钟
原文
文章信息与版本

文章信息

发布
2026年9月28日
收录
2026年10月8日
更新
2026年11月3日
篇幅
约 2 分钟
获赞
5
题目
CF2268C

版本

  1. v1当前

记 w(l,r)=(aland⁡m)⊕(al+1and⁡m)⊕⋯⊕(arand⁡m)w(l,r)=(a_l \operatorname{and} m) \oplus (a_{l+1} \operatorname{and} m) \oplus\dots \oplus (a_r \operatorname{and} m)。有

w(l,r)=mand⁡⨁i=lrai=mand⁡(sr⊕sl−1)\begin{aligned} & w(l,r)=m\operatorname{and} \bigoplus_{i=l}^r a_i\\ & =m\operatorname{and} (s_r\oplus s_{l-1}) \end{aligned}

其中 si=⨁j=1iajs_i=\bigoplus_{j=1}^i a_j。求最大值不太好做,从高位往低位贪心,可以用一只 log⁡\log 的代价把问题转化为判断是否存在 w(l,r)=xw(l,r)=x。

w(l,r)w(l,r) 有三个量也不好做,考虑枚举 mm。直接枚举 ii,以 aia_i 作为最大值。合法的 l,rl,r 满足 si<l≤i,i≤r<tis_i\lt l\le i,i\le r\lt t_i。sis_i 表示最大的 jj 满足 j<i,aj>aij\lt i,a_j\gt a_i,不存在则 si=0s_i=0;tit_i 表示最小的 jj 满足 j>i,aj>aij\gt i,a_j\gt a_i,不存在则 ti=n+1t_i=n+1。但是中间的运算是 and⁡\operatorname{and} 还是不好做。把其拆开。w(l,r)=xw(l,r)=x 的充要条件为:

  • mand⁡x=xm\operatorname{and}x=x。
  • (sr⊕sl−1)and⁡x=(srand⁡x)⊕(sl−1and⁡x)=x(s_r\oplus s_{l-1})\operatorname{and} x=(s_r\operatorname{and} x)\oplus (s_{l-1}\operatorname{and}x)=x。

问题转为判断是否存在 si≤l<i≤r<ti,r−l≥2s_i\le l\lt i\le r\lt t_i,r-l\ge 2 使得 sr′⊕sl′=xs_r^{\prime}\oplus s_{l}^{\prime}=x。

如果可以枚举 l,rl,r 其中一个就是好做的,发现直接取 i−sii-s_i 和 ti−it_i-i 更短的一边枚举复杂度就是正确的 O(nlog⁡n)O(n\log n),因为这就是笛卡尔树上启发式合并。一次 check 的复杂度为 O(nlog⁡n)\mathcal O(n\log n),总时间复杂度为 O(nlog⁡nlog⁡V)\mathcal O(n\log n\log V)。

原文