经典题,记录每个位置对应数下次出现的位置next[i] 每个位置维护当前左端点下到这个位置的和 随着左端点的右移一位到i+1,对[i+1,next[i]-1] 的影响是-a[i], [next[i],next[next[i]]-1]的影响是a[i] 线段树维护,pascal过不去系列 UPD:现在时限开大能过去了 ..*] of int64; s:..] of int64; next,last,w,a:..] of longint; i,n,m:longint; ans:int64; funct…