牛客ioi18b
数颜色
https://ac.nowcoder.com/acm/contest/7226/B
B
暴力枚举下区间(1e3)^2,然后看里面有多少不同的数字,用无序set就可以了,普通做会暴,就用双指针优化下
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pll; typedef long double db; typedef unsigned long long ull; #define fi first #define se second #define pk push_back #define mk make_pair const ll N=1e3+10, M=(1<<20), mod=9901, inf=0x3f3f3f3f3f3f3f3f, Max=5e13; const db esp=1e-7; ll n, a[N], num[N]; void work(){ scanf("%lld",&n); for(ll i=0;i<n;i++) scanf("%lld",&a[i]); ll sum=0, cnt; for(ll i=0;i<n;i++){ unordered_set<ll> vis; for(ll j=i;j<n;j++){ vis.insert(a[j]); sum+=vis.size(); } } printf("%lld",sum); return ; } int main() { work(); return 0; }