# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
961100 |
2024-04-11T13:48:50 Z |
Pety |
Izbori (COCI22_izbori) |
C++14 |
|
593 ms |
8016 KB |
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
int n, a[250002];
ll sol;
int idk[500005];
void divide (int st, int dr) {
if (st == dr) {
sol += 1;
return;
}
int mid = (st + dr) / 2;
divide(st, mid);
divide(mid + 1, dr);
map<int, int>fr;
set<int>Maj;
for (int i = mid; i >= st; i--) {
fr[a[i]]++;
if (fr[a[i]] >= (mid - i + 1) / 2 + 1)
Maj.insert(a[i]);
}
fr.clear();
for (int i = mid + 1; i <= dr; i++) {
fr[a[i]]++;
if (fr[a[i]] >= (i - mid) / 2 + 1)
Maj.insert(a[i]);
}
int lim = (dr - st + 1);
for (auto val : Maj) {
int nr = 0;
for (int i = mid; i >= st; i--) {
if (a[i] == val)
nr++;
else
nr--;
idk[nr + lim]++;
}
for (int i = 2*lim; i >= 0; i--)
idk[i] += idk[i + 1];
nr = 0;
for (int i = mid + 1; i <= dr; i++) {
if (a[i] == val)
nr++;
else
nr--;
sol += idk[-nr + lim + 1];
}
for (int i = 2*lim; i >= 0; i--)
idk[i] = 0;
}
}
int main ()
{
//ios_base::sync_with_stdio(false);
//cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
divide(1, n);
cout << sol;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2492 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2492 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
2 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
3 ms |
2396 KB |
Output is correct |
10 |
Correct |
3 ms |
2396 KB |
Output is correct |
11 |
Correct |
2 ms |
2396 KB |
Output is correct |
12 |
Correct |
3 ms |
2396 KB |
Output is correct |
13 |
Correct |
3 ms |
2396 KB |
Output is correct |
14 |
Correct |
3 ms |
2392 KB |
Output is correct |
15 |
Correct |
2 ms |
2396 KB |
Output is correct |
16 |
Correct |
3 ms |
2396 KB |
Output is correct |
17 |
Correct |
2 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
91 ms |
3060 KB |
Output is correct |
2 |
Correct |
125 ms |
3408 KB |
Output is correct |
3 |
Correct |
76 ms |
2840 KB |
Output is correct |
4 |
Correct |
124 ms |
3412 KB |
Output is correct |
5 |
Correct |
124 ms |
3488 KB |
Output is correct |
6 |
Correct |
148 ms |
3552 KB |
Output is correct |
7 |
Correct |
130 ms |
3552 KB |
Output is correct |
8 |
Correct |
132 ms |
3412 KB |
Output is correct |
9 |
Correct |
132 ms |
3412 KB |
Output is correct |
10 |
Correct |
150 ms |
3552 KB |
Output is correct |
11 |
Correct |
81 ms |
3408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2492 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
2 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
3 ms |
2396 KB |
Output is correct |
10 |
Correct |
3 ms |
2396 KB |
Output is correct |
11 |
Correct |
2 ms |
2396 KB |
Output is correct |
12 |
Correct |
3 ms |
2396 KB |
Output is correct |
13 |
Correct |
3 ms |
2396 KB |
Output is correct |
14 |
Correct |
3 ms |
2392 KB |
Output is correct |
15 |
Correct |
2 ms |
2396 KB |
Output is correct |
16 |
Correct |
3 ms |
2396 KB |
Output is correct |
17 |
Correct |
2 ms |
2396 KB |
Output is correct |
18 |
Correct |
91 ms |
3060 KB |
Output is correct |
19 |
Correct |
125 ms |
3408 KB |
Output is correct |
20 |
Correct |
76 ms |
2840 KB |
Output is correct |
21 |
Correct |
124 ms |
3412 KB |
Output is correct |
22 |
Correct |
124 ms |
3488 KB |
Output is correct |
23 |
Correct |
148 ms |
3552 KB |
Output is correct |
24 |
Correct |
130 ms |
3552 KB |
Output is correct |
25 |
Correct |
132 ms |
3412 KB |
Output is correct |
26 |
Correct |
132 ms |
3412 KB |
Output is correct |
27 |
Correct |
150 ms |
3552 KB |
Output is correct |
28 |
Correct |
81 ms |
3408 KB |
Output is correct |
29 |
Correct |
116 ms |
5120 KB |
Output is correct |
30 |
Correct |
98 ms |
3552 KB |
Output is correct |
31 |
Correct |
204 ms |
4792 KB |
Output is correct |
32 |
Correct |
593 ms |
8016 KB |
Output is correct |
33 |
Correct |
218 ms |
4932 KB |
Output is correct |
34 |
Correct |
233 ms |
4980 KB |
Output is correct |
35 |
Correct |
144 ms |
4144 KB |
Output is correct |
36 |
Correct |
77 ms |
3444 KB |
Output is correct |
37 |
Correct |
101 ms |
3600 KB |
Output is correct |
38 |
Correct |
163 ms |
3552 KB |
Output is correct |
39 |
Correct |
159 ms |
3712 KB |
Output is correct |
40 |
Correct |
157 ms |
3556 KB |
Output is correct |
41 |
Correct |
155 ms |
3484 KB |
Output is correct |
42 |
Correct |
157 ms |
3788 KB |
Output is correct |
43 |
Correct |
219 ms |
4948 KB |
Output is correct |
44 |
Correct |
230 ms |
5032 KB |
Output is correct |
45 |
Correct |
233 ms |
5016 KB |
Output is correct |
46 |
Correct |
219 ms |
5040 KB |
Output is correct |
47 |
Correct |
224 ms |
5132 KB |
Output is correct |
48 |
Correct |
334 ms |
3664 KB |
Output is correct |
49 |
Correct |
340 ms |
3920 KB |
Output is correct |
50 |
Correct |
277 ms |
3664 KB |
Output is correct |
51 |
Correct |
278 ms |
3740 KB |
Output is correct |
52 |
Correct |
256 ms |
3916 KB |
Output is correct |
53 |
Correct |
269 ms |
3812 KB |
Output is correct |
54 |
Correct |
233 ms |
3860 KB |
Output is correct |