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 100000
#define T 3
#define S 6
int min(int a, int b) { return a < b ? a : b; }
int pref[S][T] = {
{ 0, 1, 2 },
{ 0, 2, 1 },
{ 1, 0, 2 },
{ 1, 2, 0 },
{ 2, 0, 1 },
{ 2, 1, 0 }
};
int main() {
static int ii[N][T], ii_[N], ep[N][T], eo[N], ll[N], mm[S];
static long long kk[T];
int n, g, h, i, j, j_, p, q, s, t, t_;
scanf("%d", &n);
for (t = 0; t < T; t++)
for (i = 0; i < n; i++) {
scanf("%d", &p), p--;
ii[p][t] = i;
}
for (p = 0; p < n; p++) {
ii_[p] = n;
for (t = 0; t < T; t++)
ii_[p] = min(ii_[p], ii[p][t]);
}
for (p = 0; p < n; p++) {
i = ii_[p];
ep[i][eo[i]++] = p;
}
for (i = 0; i < n; i++)
for (g = 0; g < eo[i]; g++)
for (h = g + 1; h < eo[i]; h++) {
p = ep[i][g], q = ep[i][h], j_ = n, t_ = -1;
for (t = 0; t < T; t++)
if (ii[p][t] == i || ii[q][t] == i) {
j = i ^ ii[p][t] ^ ii[q][t];
if (j_ > j)
j_ = j, t_ = t;
}
kk[t_]++;
if (ii[p][t_] < ii[q][t_])
ll[p]++;
else
ll[q]++;
}
for (i = n - 1; i >= 0; i--) {
for (g = 0; g < eo[i]; g++) {
p = ep[i][g];
for (s = 0; s < S; s++) {
for (t = 0; t < T; t++)
if (ii[p][pref[s][t]] == i)
break;
kk[pref[s][t]] += mm[s], ll[p] += mm[s];
}
}
for (g = 0; g < eo[i]; g++) {
p = ep[i][g];
for (s = 0; s < S; s++) {
int congruent = 1;
for (t = 1; t < T; t++)
if (ii[p][pref[s][t - 1]] > ii[p][pref[s][t]] || ii[p][pref[s][t - 1]] == ii[p][pref[s][t]] && pref[s][t - 1] > pref[s][t]) {
congruent = 0;
break;
}
if (congruent)
mm[s]++;
}
}
}
for (t = 0; t < T; t++)
printf("%lld ", kk[t]);
printf("\n");
for (p = 0; p < n; p++)
printf("%d ", ll[p]);
printf("\n");
return 0;
}
Compilation message (stderr)
tenis.c: In function 'main':
tenis.c:70:98: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
70 | if (ii[p][pref[s][t - 1]] > ii[p][pref[s][t]] || ii[p][pref[s][t - 1]] == ii[p][pref[s][t]] && pref[s][t - 1] > pref[s][t]) {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tenis.c:23:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
tenis.c:26:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | scanf("%d", &p), p--;
| ^~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |