# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
533584 |
2022-03-06T10:55:53 Z |
topovik |
Izbori (COCI22_izbori) |
C++14 |
|
1628 ms |
32852 KB |
#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 = 1e6 + 10;
const ll N1 = 2e5 + 10;
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;
void upd(int x, int y)
{
x += N1;
if (key[x] != t)
{
key[x] = t;
val[x] = 0;
}
val[x] += y;
}
int value(int x)
{
x += N1;
if (key[x] != t)
{
key[x] = t;
val[x] = 0;
}
return val[x];
}
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 = N1;
for (int j = i; j < min(n, i + M); j++)
{
upd(a[j], 1);
if (value(a[j]) > value(nom_mx)) nom_mx = a[j];
if (value(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;
t++;
ll sum1 = 0;
ll kol = 0;
for (ll j = 0; j < n; j++)
{
sum1 += b[j];
upd(sum1 * 2 - (j + 1), 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];
upd(sum1 * 2 - (j + 1), -1);
if (sum1 * 2 - (j + 1) >= c) kol--;
if (b[j] == 0)
{
c--;
kol += value(c);
}
else
{
kol -= value(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 |
1 |
Correct |
13 ms |
23720 KB |
Output is correct |
2 |
Correct |
12 ms |
23824 KB |
Output is correct |
3 |
Correct |
12 ms |
23756 KB |
Output is correct |
4 |
Correct |
14 ms |
23844 KB |
Output is correct |
5 |
Correct |
12 ms |
23780 KB |
Output is correct |
6 |
Correct |
12 ms |
23812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23720 KB |
Output is correct |
2 |
Correct |
12 ms |
23824 KB |
Output is correct |
3 |
Correct |
12 ms |
23756 KB |
Output is correct |
4 |
Correct |
14 ms |
23844 KB |
Output is correct |
5 |
Correct |
12 ms |
23780 KB |
Output is correct |
6 |
Correct |
12 ms |
23812 KB |
Output is correct |
7 |
Correct |
13 ms |
23884 KB |
Output is correct |
8 |
Correct |
11 ms |
23836 KB |
Output is correct |
9 |
Correct |
20 ms |
23872 KB |
Output is correct |
10 |
Correct |
19 ms |
23844 KB |
Output is correct |
11 |
Correct |
19 ms |
23912 KB |
Output is correct |
12 |
Correct |
18 ms |
23912 KB |
Output is correct |
13 |
Correct |
18 ms |
23900 KB |
Output is correct |
14 |
Correct |
19 ms |
23836 KB |
Output is correct |
15 |
Correct |
21 ms |
23804 KB |
Output is correct |
16 |
Correct |
18 ms |
23884 KB |
Output is correct |
17 |
Correct |
18 ms |
23828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
672 ms |
29184 KB |
Output is correct |
2 |
Correct |
870 ms |
30608 KB |
Output is correct |
3 |
Correct |
542 ms |
27832 KB |
Output is correct |
4 |
Correct |
918 ms |
30724 KB |
Output is correct |
5 |
Correct |
946 ms |
30652 KB |
Output is correct |
6 |
Correct |
1022 ms |
31436 KB |
Output is correct |
7 |
Correct |
985 ms |
31440 KB |
Output is correct |
8 |
Correct |
1041 ms |
31496 KB |
Output is correct |
9 |
Correct |
1000 ms |
31004 KB |
Output is correct |
10 |
Correct |
1022 ms |
31040 KB |
Output is correct |
11 |
Correct |
910 ms |
31728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23720 KB |
Output is correct |
2 |
Correct |
12 ms |
23824 KB |
Output is correct |
3 |
Correct |
12 ms |
23756 KB |
Output is correct |
4 |
Correct |
14 ms |
23844 KB |
Output is correct |
5 |
Correct |
12 ms |
23780 KB |
Output is correct |
6 |
Correct |
12 ms |
23812 KB |
Output is correct |
7 |
Correct |
13 ms |
23884 KB |
Output is correct |
8 |
Correct |
11 ms |
23836 KB |
Output is correct |
9 |
Correct |
20 ms |
23872 KB |
Output is correct |
10 |
Correct |
19 ms |
23844 KB |
Output is correct |
11 |
Correct |
19 ms |
23912 KB |
Output is correct |
12 |
Correct |
18 ms |
23912 KB |
Output is correct |
13 |
Correct |
18 ms |
23900 KB |
Output is correct |
14 |
Correct |
19 ms |
23836 KB |
Output is correct |
15 |
Correct |
21 ms |
23804 KB |
Output is correct |
16 |
Correct |
18 ms |
23884 KB |
Output is correct |
17 |
Correct |
18 ms |
23828 KB |
Output is correct |
18 |
Correct |
672 ms |
29184 KB |
Output is correct |
19 |
Correct |
870 ms |
30608 KB |
Output is correct |
20 |
Correct |
542 ms |
27832 KB |
Output is correct |
21 |
Correct |
918 ms |
30724 KB |
Output is correct |
22 |
Correct |
946 ms |
30652 KB |
Output is correct |
23 |
Correct |
1022 ms |
31436 KB |
Output is correct |
24 |
Correct |
985 ms |
31440 KB |
Output is correct |
25 |
Correct |
1041 ms |
31496 KB |
Output is correct |
26 |
Correct |
1000 ms |
31004 KB |
Output is correct |
27 |
Correct |
1022 ms |
31040 KB |
Output is correct |
28 |
Correct |
910 ms |
31728 KB |
Output is correct |
29 |
Correct |
995 ms |
31732 KB |
Output is correct |
30 |
Correct |
178 ms |
25676 KB |
Output is correct |
31 |
Correct |
403 ms |
27456 KB |
Output is correct |
32 |
Correct |
869 ms |
31744 KB |
Output is correct |
33 |
Correct |
393 ms |
27668 KB |
Output is correct |
34 |
Correct |
410 ms |
27840 KB |
Output is correct |
35 |
Correct |
267 ms |
26572 KB |
Output is correct |
36 |
Correct |
153 ms |
25548 KB |
Output is correct |
37 |
Correct |
234 ms |
25864 KB |
Output is correct |
38 |
Correct |
911 ms |
32476 KB |
Output is correct |
39 |
Correct |
923 ms |
31904 KB |
Output is correct |
40 |
Correct |
929 ms |
32232 KB |
Output is correct |
41 |
Correct |
919 ms |
32160 KB |
Output is correct |
42 |
Correct |
919 ms |
31996 KB |
Output is correct |
43 |
Correct |
943 ms |
32384 KB |
Output is correct |
44 |
Correct |
961 ms |
32332 KB |
Output is correct |
45 |
Correct |
971 ms |
32272 KB |
Output is correct |
46 |
Correct |
944 ms |
32228 KB |
Output is correct |
47 |
Correct |
946 ms |
32352 KB |
Output is correct |
48 |
Correct |
1628 ms |
32120 KB |
Output is correct |
49 |
Correct |
1552 ms |
32108 KB |
Output is correct |
50 |
Correct |
1179 ms |
32688 KB |
Output is correct |
51 |
Correct |
1214 ms |
32852 KB |
Output is correct |
52 |
Correct |
893 ms |
28976 KB |
Output is correct |
53 |
Correct |
895 ms |
28732 KB |
Output is correct |
54 |
Correct |
1305 ms |
32148 KB |
Output is correct |