题1:
求最长不重复子序列
check(i,j)是j往左移动到最远,
i往后走的时候,j也只能往后走
#include<iostream>
using namespace std;
const int N = 100010;
int a[N], s[N];//s个数
int main() {
int n;
int res = 0;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0, j = 0; i < n; i++)
{
s[a[i]] ++;
while ( s[a[i]] > 1) {
s[a[j]] --;
j ++;
}
res = max(res, i - j + 1);
}
cout << res << endl;
return 0;
}