正文
增加 3 行删除 1 行
250 行未改动全部展开25125225325425525625725825926026126226326425 行未改动250 行未改动全部展开# G这题,800 吧。考虑简单 dp,每个值 $v$ 出现位置放到 $\text{pos}_v$ 中。则当前转移形如$$f_i \gets \sum\limits_{L \le j < R}f_j$$其中 $j$ 由 $i$ 确定。我们令 $L$ 为 $a_i$ 倒数第 $a_i+1$ 个出现的位置,令 $R$ 为 $a_i$ 倒数第 $a_i$ 个出现的位置即可。时间复杂度 $\mathcal O(n)$。```cpp#include<bits/stdc++.h>#define int long longusing namespace std;25 行未改动250 行未改动全部展开25125225325425525625725825926026126226326426526625 行未改动250 行未改动全部展开# G这题,800 吧。考虑简单 dp,$f_i$ 表示 $[1,i]$ 的答案。每个值 $v$ 出现位置放到 $\text{pos}_v$ 中。则当前转移形如$$f_i \gets \sum\limits_{L \le j < R}f_j$$其中 $j$ 由 $i$ 确定。我们令 $L$ 为 $a_i$ 倒数第 $a_i+1$ 个出现的位置,令 $R$ 为 $a_i$ 倒数第 $a_i$ 个出现的位置即可。时间复杂度 $\mathcal O(n)$。答案为 $\sum f_i-1$ 减去空子序列。```cpp#include<bits/stdc++.h>#define int long longusing namespace std;25 行未改动