# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
528251 | rainboy | Izbori (COCI22_izbori) | C11 | 13 ms | 2420 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 && 0) {
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[k] * (cc[k] - 1) / 2;
}
printf("%lld\n", cnt);
return 0;
}
Compilation message (stderr)
# | 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... |