#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 = 1e3 + 10;
vector <ll> ps[N];
ll b[N];
map <ll, ll> mp;
ll ans = 0;
int val[N];
int key[N];
int t;
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++)
{
t++;
int nom_mx = N - 1;
for (int j = i; j < min(n, i + M); j++)
{
if (key[a[j]] != t)
{
key[a[j]] = t;
val[a[j]] = 0;
}
val[a[j]]++;
if (val[a[j]] > val[nom_mx]) nom_mx = a[j];
if (val[nom_mx] * 2 > (j - i + 1))
{
if (ps[nom_mx].size() <= M / 2) ans++;
}
}
}
for (ll i = 0; i < n; i++)
if (ps[i].size() > M / 2)
{
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
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11980 KB |
Output is correct |
2 |
Correct |
9 ms |
11980 KB |
Output is correct |
3 |
Correct |
7 ms |
11980 KB |
Output is correct |
4 |
Correct |
7 ms |
11980 KB |
Output is correct |
5 |
Correct |
7 ms |
11980 KB |
Output is correct |
6 |
Correct |
7 ms |
11980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11980 KB |
Output is correct |
2 |
Correct |
9 ms |
11980 KB |
Output is correct |
3 |
Correct |
7 ms |
11980 KB |
Output is correct |
4 |
Correct |
7 ms |
11980 KB |
Output is correct |
5 |
Correct |
7 ms |
11980 KB |
Output is correct |
6 |
Correct |
7 ms |
11980 KB |
Output is correct |
7 |
Correct |
8 ms |
12108 KB |
Output is correct |
8 |
Correct |
6 ms |
11980 KB |
Output is correct |
9 |
Correct |
11 ms |
12108 KB |
Output is correct |
10 |
Correct |
11 ms |
12108 KB |
Output is correct |
11 |
Correct |
11 ms |
12128 KB |
Output is correct |
12 |
Correct |
11 ms |
12108 KB |
Output is correct |
13 |
Correct |
12 ms |
12108 KB |
Output is correct |
14 |
Correct |
11 ms |
12144 KB |
Output is correct |
15 |
Correct |
11 ms |
12108 KB |
Output is correct |
16 |
Correct |
10 ms |
12108 KB |
Output is correct |
17 |
Correct |
11 ms |
12236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
546 ms |
17424 KB |
Output is correct |
2 |
Correct |
687 ms |
18852 KB |
Output is correct |
3 |
Correct |
396 ms |
16092 KB |
Output is correct |
4 |
Correct |
715 ms |
18976 KB |
Output is correct |
5 |
Correct |
757 ms |
18900 KB |
Output is correct |
6 |
Correct |
789 ms |
19768 KB |
Output is correct |
7 |
Correct |
798 ms |
19684 KB |
Output is correct |
8 |
Correct |
757 ms |
19768 KB |
Output is correct |
9 |
Correct |
770 ms |
19240 KB |
Output is correct |
10 |
Correct |
788 ms |
19280 KB |
Output is correct |
11 |
Correct |
794 ms |
30764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11980 KB |
Output is correct |
2 |
Correct |
9 ms |
11980 KB |
Output is correct |
3 |
Correct |
7 ms |
11980 KB |
Output is correct |
4 |
Correct |
7 ms |
11980 KB |
Output is correct |
5 |
Correct |
7 ms |
11980 KB |
Output is correct |
6 |
Correct |
7 ms |
11980 KB |
Output is correct |
7 |
Correct |
8 ms |
12108 KB |
Output is correct |
8 |
Correct |
6 ms |
11980 KB |
Output is correct |
9 |
Correct |
11 ms |
12108 KB |
Output is correct |
10 |
Correct |
11 ms |
12108 KB |
Output is correct |
11 |
Correct |
11 ms |
12128 KB |
Output is correct |
12 |
Correct |
11 ms |
12108 KB |
Output is correct |
13 |
Correct |
12 ms |
12108 KB |
Output is correct |
14 |
Correct |
11 ms |
12144 KB |
Output is correct |
15 |
Correct |
11 ms |
12108 KB |
Output is correct |
16 |
Correct |
10 ms |
12108 KB |
Output is correct |
17 |
Correct |
11 ms |
12236 KB |
Output is correct |
18 |
Correct |
546 ms |
17424 KB |
Output is correct |
19 |
Correct |
687 ms |
18852 KB |
Output is correct |
20 |
Correct |
396 ms |
16092 KB |
Output is correct |
21 |
Correct |
715 ms |
18976 KB |
Output is correct |
22 |
Correct |
757 ms |
18900 KB |
Output is correct |
23 |
Correct |
789 ms |
19768 KB |
Output is correct |
24 |
Correct |
798 ms |
19684 KB |
Output is correct |
25 |
Correct |
757 ms |
19768 KB |
Output is correct |
26 |
Correct |
770 ms |
19240 KB |
Output is correct |
27 |
Correct |
788 ms |
19280 KB |
Output is correct |
28 |
Correct |
794 ms |
30764 KB |
Output is correct |
29 |
Correct |
794 ms |
30856 KB |
Output is correct |
30 |
Correct |
154 ms |
14028 KB |
Output is correct |
31 |
Correct |
332 ms |
15704 KB |
Output is correct |
32 |
Correct |
812 ms |
20024 KB |
Output is correct |
33 |
Correct |
331 ms |
15948 KB |
Output is correct |
34 |
Correct |
412 ms |
16216 KB |
Output is correct |
35 |
Correct |
224 ms |
14796 KB |
Output is correct |
36 |
Correct |
144 ms |
13760 KB |
Output is correct |
37 |
Correct |
176 ms |
14124 KB |
Output is correct |
38 |
Correct |
954 ms |
26092 KB |
Output is correct |
39 |
Correct |
986 ms |
26292 KB |
Output is correct |
40 |
Correct |
922 ms |
26160 KB |
Output is correct |
41 |
Correct |
997 ms |
26312 KB |
Output is correct |
42 |
Correct |
971 ms |
26260 KB |
Output is correct |
43 |
Correct |
1477 ms |
29212 KB |
Output is correct |
44 |
Correct |
1443 ms |
29408 KB |
Output is correct |
45 |
Correct |
1471 ms |
29216 KB |
Output is correct |
46 |
Correct |
1445 ms |
29308 KB |
Output is correct |
47 |
Correct |
1494 ms |
29168 KB |
Output is correct |
48 |
Execution timed out |
3081 ms |
31000 KB |
Time limit exceeded |
49 |
Halted |
0 ms |
0 KB |
- |