# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
528259 |
2022-02-19T18:30:35 Z |
rainboy |
Izbori (COCI22_izbori) |
C |
|
1034 ms |
2604 KB |
#include <stdio.h>
#define N 200000
#define SMALL 2000
int main() {
static int aa[N], kk[N + 1], cc[N * 2 + 1];
int n, i, l, r, a, k, k_;
long long cnt;
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d", &aa[i]);
if (n <= SMALL) {
cnt = 0;
for (l = 0; l < n; l++) {
a = 0, k = 0;
for (r = l; r < n; r++) {
if (k == 0)
a = aa[r], k++;
else if (a == aa[r])
k++;
else
k--;
k_ = 0;
for (i = l; i <= r; i++)
if (aa[i] == a)
k_++;
else
k_--;
if (k_ > 0)
cnt++;
}
}
} else {
k = 0;
for (i = 0; i < n; i++)
kk[i + 1] = kk[i] + (aa[i] == 1 ? 1 : -1);
for (i = 0; i <= n; i++)
cc[n + kk[i]]++;
cnt = (long long) n * (n + 1) / 2;
for (k = -n; k <= n; k++)
cnt -= (long long) cc[n + k] * (cc[n + k] - 1) / 2;
}
printf("%lld\n", cnt);
return 0;
}
Compilation message
Main.c: In function 'main':
Main.c:11:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
11 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
Main.c:13:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | scanf("%d", &aa[i]);
| ^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
4 ms |
284 KB |
Output is correct |
4 |
Correct |
4 ms |
204 KB |
Output is correct |
5 |
Correct |
4 ms |
204 KB |
Output is correct |
6 |
Correct |
4 ms |
284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
4 ms |
284 KB |
Output is correct |
4 |
Correct |
4 ms |
204 KB |
Output is correct |
5 |
Correct |
4 ms |
204 KB |
Output is correct |
6 |
Correct |
4 ms |
284 KB |
Output is correct |
7 |
Correct |
102 ms |
272 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1012 ms |
272 KB |
Output is correct |
10 |
Correct |
1034 ms |
280 KB |
Output is correct |
11 |
Correct |
988 ms |
292 KB |
Output is correct |
12 |
Correct |
1012 ms |
276 KB |
Output is correct |
13 |
Correct |
1014 ms |
280 KB |
Output is correct |
14 |
Correct |
990 ms |
272 KB |
Output is correct |
15 |
Correct |
975 ms |
204 KB |
Output is correct |
16 |
Correct |
969 ms |
280 KB |
Output is correct |
17 |
Correct |
965 ms |
280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
1228 KB |
Output is correct |
2 |
Correct |
15 ms |
1624 KB |
Output is correct |
3 |
Correct |
10 ms |
1100 KB |
Output is correct |
4 |
Correct |
16 ms |
1700 KB |
Output is correct |
5 |
Correct |
17 ms |
1636 KB |
Output is correct |
6 |
Correct |
21 ms |
1764 KB |
Output is correct |
7 |
Correct |
17 ms |
1824 KB |
Output is correct |
8 |
Correct |
19 ms |
1740 KB |
Output is correct |
9 |
Correct |
18 ms |
1868 KB |
Output is correct |
10 |
Correct |
18 ms |
1744 KB |
Output is correct |
11 |
Correct |
18 ms |
2596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
4 ms |
284 KB |
Output is correct |
4 |
Correct |
4 ms |
204 KB |
Output is correct |
5 |
Correct |
4 ms |
204 KB |
Output is correct |
6 |
Correct |
4 ms |
284 KB |
Output is correct |
7 |
Correct |
102 ms |
272 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1012 ms |
272 KB |
Output is correct |
10 |
Correct |
1034 ms |
280 KB |
Output is correct |
11 |
Correct |
988 ms |
292 KB |
Output is correct |
12 |
Correct |
1012 ms |
276 KB |
Output is correct |
13 |
Correct |
1014 ms |
280 KB |
Output is correct |
14 |
Correct |
990 ms |
272 KB |
Output is correct |
15 |
Correct |
975 ms |
204 KB |
Output is correct |
16 |
Correct |
969 ms |
280 KB |
Output is correct |
17 |
Correct |
965 ms |
280 KB |
Output is correct |
18 |
Correct |
11 ms |
1228 KB |
Output is correct |
19 |
Correct |
15 ms |
1624 KB |
Output is correct |
20 |
Correct |
10 ms |
1100 KB |
Output is correct |
21 |
Correct |
16 ms |
1700 KB |
Output is correct |
22 |
Correct |
17 ms |
1636 KB |
Output is correct |
23 |
Correct |
21 ms |
1764 KB |
Output is correct |
24 |
Correct |
17 ms |
1824 KB |
Output is correct |
25 |
Correct |
19 ms |
1740 KB |
Output is correct |
26 |
Correct |
18 ms |
1868 KB |
Output is correct |
27 |
Correct |
18 ms |
1744 KB |
Output is correct |
28 |
Correct |
18 ms |
2596 KB |
Output is correct |
29 |
Correct |
26 ms |
2604 KB |
Output is correct |
30 |
Incorrect |
5 ms |
912 KB |
Output isn't correct |
31 |
Halted |
0 ms |
0 KB |
- |