LOJ10121 与众不同

last[i] remember the last place where i appeared last time
st[i] 记录以i结尾的最长完美序列的起点

  1. 处理\(last[i]\);
  2. 维护\(st[i]\)转移:$ st[i] = max(st[i-1],last[a[i]]+1) $
  3. 所以\(f[i][0]=i-st[i]+1\)
  4. 所以可以预处理\(RMQ\)
  5. 对每一次询问的\(L,R寻找其pos(pos的左侧所有的st[i]<l,右侧都 >=l)\)
  6. 所以 $ answer = max(pos-l,RMQ(pos,r))$
    p.s. 因为st是单调的,所以可以用BS找pos

猜你喜欢

转载自www.cnblogs.com/yangxuejian/p/11109297.html