LOJ10121 与众不同
## \[ 本题要求: 求 [l,r] 内最长连续无重子序列(下称LCRS) \] 如何解决 st[i] 记录 以i结尾的LCRS 的起点)last[i] 记录 i 在 a[] 中 上次出现的位置 p.s. st[]在任何一个序列中都是 单调不上升 的,有兴趣的读者可以自己推推看 怎么做 处理 \(last[i]\) ; 维护 \(st[i]\) 转移:$ st[i] = max(st[i-1],last[a[i]]+1) $ 所以 \(f[i][0]=i-st[i]+1\) 所以可以预处理 \(RMQ\) 对每一次询问的 \(L,R寻找其pos(pos的左侧所有的st[i]<l,右侧都 >=l)\) 所以 $ answer = max(pos-l,RMQ(pos,r))$ p.s. 因为st是单调的,所以可以用二分找pos #include <bits/stdc++.h> using namespace std; const int maxn = 2 * 1e6 + 5; const int adnu = 1e6 + 5; const int logn = 50; int n, m; int last[maxn], st[maxn], a[maxn], len[maxn]; int f[maxn][logn], lg[maxn]; void RMQ() { lg[0] = -1;