const int maxn = 1e6 + 10; const int inf = 0x3f3f3f3f; int a[maxn], n;
int solve() { set<int> st; int ans = 0; for (int j = 0, i = 0; j < n; j++) { while (i < n && !st.count(a[i])) st.insert(a[i]), i++; chmax(ans, i-j); st.erase(a[j]); } return ans; }
void init() { // }
int main() { freopen("input.txt", "r", stdin); int kase; while (scanf("%d", &kase) != EOF) { while (kase--) { init();
// get data scanf("%d", &n); _for(i, 0, n) scanf("%d", &a[i]);
// then solve int res = solve(); printf("%d\n", res); } } }
const int maxn = 100000 + 10; int a[maxn<<1], n, s; bool ok[maxn<<1];
int solve() { int tot = 0, cnt[maxn]; memset(cnt, 0, sizeof(cnt)); for (int i = 0; i < n+s; i++) { if (i < n && ++cnt[ a[i] ] == 1) tot++; if (i-s >= 0 && --cnt[ a[i-s] ] == 0) tot--;
int r = min(i, n-1), l = max(0, i-s+1); if (r-l+1 != tot) ok[i%s] = 0; }
int ans = 0; for (int i = 0; i < s; i++) if (ok[i]) ans++; return ans; }
void init() { memset(ok, 1, sizeof(ok)); }
int main() { freopen("input.txt", "r", stdin); int kase; scanf("%d", &kase);
while (kase--) { init();
// get data scanf("%d%d", &s, &n); _for(i, 0, n) scanf("%d", &a[i]);
// then solve int ans = solve(); printf("%d\n", ans); } }
LIS模型
1 2 3 4 5 6
for (int i = 1; i <= n; i++) g[i] = inf; for (int i = 0; i < n; i++) { int k = lower_bound(g+1, g+1+n, A[i]) - g; d[i] = k; ans = max(ans, k); g[k] = A[i]; }
LCS 问题转换成 LIS 问题
如果两个子序列中各个元素均不相同,求二者的公共子序列长度
将序列 A 中的元素做一个映射,重新编号成 [1,2,⋯,n]
AmapA′,按照同样的规则,将 B 映射成一个新序列 S
二者的 LCS 排列规则,也就是元素出现的先后顺序是一致的
所以实际上就是求 S 的 LIS
class A { public: int val, id; A() = default; A(int val, int id) : val(val), id(id) {} bool operator< (const A &rhs) const { return val < rhs.val || (val == rhs.val && id < rhs.id); } };
A vec[maxn]; int m = 0;
int la, lb, lc, d; ll cnt[maxn][3];
void prework() { sort(vec+1, vec+1+m);
for (int i = 1; i <= m; i++) { memcpy(cnt[i], cnt[i-1], sizeof(cnt[i])); cnt[i][vec[i].id]++; //printf("%d ", vec[i].val); }
}
void solve() { ll res = 0; int i = 1, j = 1; //debug(cnt[1][0]); //debug(vec[j].val); int last = -1; for (; i <= m; i++) { while (j <= m && vec[j].val - vec[i].val <= d) j++;