Codeforces Round #136 (Div. 2)

时间:2023-12-25 14:32:43

A. Little Elephant and Function

  • 逆推。

B. Little Elephant and Numbers

  • \(O(\sqrt n)\)枚举约数。

C. Little Elephant and Problem

  • 排序后对应不相等的位置为2,且两数交换。

D. Little Elephant and Array

  • 离线+分块。

E. Little Elephant and Shifts

  • 每个数单独考虑。
  • 假设\(x\)在数组\(a\)的位置\(i\),在数组\(b\)的位置\(j\),且\(i \le j\),则从\(p_1\)到\(p_n\)对应的距离为\[j - i, j - i - 1, \cdots,1, 0, 1,\cdots, i-1, n-i, \cdots, j-i+1\]分成两个递减,一个递增区间。
  • 考虑\(p_1\)到\(p_{j-i+1}\)这个区间,第\(k\)个位置的值可以表示成\[d_k=d_1-(k-1)=(d_1+1)-k\]根据题意,要在所有方案中取\[\min{d_k}=\min{(d_1+1)}-k,d_1+1-k\ge 0\]这个可以用优先队列维护。
  • 其余两个单调区间也是类似做法。