#include<bits/stdc++.h>
#define int long long
#define ll long long
#define pii pair<int,int>
#define fi first
#define se second
#define L LLONG_MAX
#define FOR(i,j,k) for(int i=j;i<=k;i++)
#define REP(i,k,j) for(int i=k;i>=j;i--)
#define FORD(i,a) for(auto i:a)
#define sz(a) (int)a.size()
using namespace std;
const int nmax=2e5+69;
int n,crr=0;
int a[nmax];
void compress()
{
set<int> s;
map<int,int> mp;
FOR(i,1,n) s.insert(a[i]);
FORD(i,s) mp[i]=++crr;
FOR(i,1,n) a[i]=mp[a[i]];
}
void input()
{
cin >> n;
FOR(i,1,n) cin >> a[i];
compress();
}
namespace sub2
{
int cnt[nmax];
bool check()
{
return n<=2000;
}
void solve()
{
int ans=0;
FOR(l,1,n)
{
int mx=0;
FOR(r,l,n)
{
mx=max(mx,++cnt[a[r]]);
if(mx>(r-l+1)/2) ans++;
}
FOR(i,l,n) cnt[a[i]]--;
}
cout << ans;
}
}
signed main()
{
//freopen(".inp", "r", stdin);
//freopen(".out", "w", stdout);
//ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
input();
if(sub2::check()) return sub2::solve(),0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |