正睿【普转提七联测 Day 1】序列
作者:互联网
正睿【普转提七联测 Day 1】序列
进不去不是我的错\(qwq\)
连这种题都要想半天,我菜得真实,还是从基础的东西搞起吧
思路
20pts
\(n^3\)暴力枚举
不解释
\(a_i\)范围不小,先离散化
然后枚举删掉\(i\sim j\)这个子串后剩下的部分中有没有相同数字,如果没有就可以更新答案
需要注意的是要特判不需要删的情况
代码太丑不给了
100pts
\(n^2\)暴力枚举
离散化之后用数组记录每个数字出现的次数,并记录出现次数大于\(1\)的数字的个数\(js\),两层循环枚举要删除的子串,如果当前数字在删除之后出现次数为\(1\),那么\(js\)就可以减一,当\(js\)为\(0\)时即可更新答案
代码太丑不给了
代码
/*
/*
Author:loceaner
*/
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int A = 5e5 + 11;
const int B = 1e6 + 11;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
inline int read() {
char c = getchar(); int x = 0, f = 1;
for( ; !isdigit(c); c = getchar()) if(c == '-') f = -1;
for( ; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
return x * f;
}
int n, a[A], b[A], vis[A], ans = inf;
int main() {
n = read();
for (int i = 1; i <= n; i++) b[i] = a[i] = read();
sort(b + 1, b + 1 + n);
int cnt = unique(b + 1, b + 1 + n) - b - 1;
for (int i = 1; i <= n; i++) a[i] = lower_bound(b + 1, b + cnt + 1, a[i]) - b;
for (int i = 1; i <= n; i++) {
memset(vis, 0, sizeof(vis));
if (js == 0) return puts("0"), 0;
for (int j = i; j <= n; j++) {
vis[a[j]]--;
if (vis[a[j]] == 1) js--;
if (js == 0) { ans = min(ans, j - i + 1); break; }
}
}
cout << ans << '\n';
return 0;
}
标签:普转,int,js,提七,枚举,正睿,const,include,getchar 来源: https://www.cnblogs.com/loceaner/p/12908923.html