이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
using namespace std;
typedef long long ll;
typedef long double ld;
const ll oo = 1e18 + 7;
const ll N = 5e5 + 10;
const ll N1 = 5e6;
const ll M = 2e3 + 10;
vector <ll> ps[N];
ll b[N];
map <ll, ll> mp;
ll ans = 0;
int main()
{
ios_base::sync_with_stdio(0);
iostream::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n;
cin >> n;
ll a[n];
vector <ll> cmp;
for (ll i = 0; i < n; i++) cin >> a[i], cmp.pb(a[i]);
sort(cmp.begin(), cmp.end());
cmp.resize(unique(cmp.begin(), cmp.end()) - cmp.begin());
for (ll i = 0; i < n; i++) a[i] = lower_bound(cmp.begin(), cmp.end(), a[i]) - cmp.begin();
for (ll i = 0; i < n; i++) ps[a[i]].pb(i);
for (ll i = 0; i < n; i++)
if (ps[i].size() > 0)
{
for (ll j = 0; j < n; j++) b[j] = 0;
for (auto j : ps[i]) b[j] = 1;
mp.clear();
ll sum1 = 0;
ll kol = 0;
for (ll j = 0; j < n; j++)
{
sum1 += b[j];
mp[sum1 * 2 - (j + 1)]++;
if (sum1 * 2 - (j + 1) > 0) kol++;
}
ans += kol;
ll c = 1;
sum1 = 0;
for (ll j = 0; j < n; j++)
{
sum1 += b[j];
mp[sum1 * 2 - (j + 1)]--;
if (sum1 * 2 - (j + 1) >= c) kol--;
if (b[j] == 0)
{
c--;
kol += mp[c];
}
else
{
kol -= mp[c];
c++;
}
ans += kol;
}
cout << endl;
}
cout << ans;
}
/*
5 3
2 1 1 2 2 3
2 3 3 4 4 5
4 1 1 2 2 3 3 4 4 5
*/
# | 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... |