Submission #64426090
Source Code Expand
Copy
#include <stdio.h>#include <stdlib.h>#include <inttypes.h>#define MAX 212345int bit_table[MAX];void bit_add(int pos, int value) {pos++;while (pos <= MAX) {bit_table[pos - 1] += value;pos += pos & (-pos);}}int bit_sum(int pos) {int sum = 0;pos++;while (pos > 0) {sum += bit_table[pos - 1];
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#define MAX 212345
int bit_table[MAX];
void bit_add(int pos, int value) {
pos++;
while (pos <= MAX) {
bit_table[pos - 1] += value;
pos += pos & (-pos);
}
}
int bit_sum(int pos) {
int sum = 0;
pos++;
while (pos > 0) {
sum += bit_table[pos - 1];
pos -= pos & (-pos);
}
return sum;
}
int N, M;
int A[MAX];
int ec[MAX], *es[MAX]; /* element count, elements */
int main(void) {
int i;
uint64_t ans = 0;
if (scanf("%d%d", &N, &M) != 2) return 1;
for (i = 0; i < N; i++) {
if (scanf("%d", &A[i]) != 1) return 1;
es[A[i]] = realloc(es[A[i]], sizeof(*es[A[i]]) + (ec[A[i]] + 1));
if (es[A[i]] == NULL) return 2;
es[A[i]][ec[A[i]]++] = i;
}
for (i = N - 1; i >= 0; i--) {
ans += bit_sum(A[i] - 1);
bit_add(A[i], 1);
}
printf("%" PRIu64 "\n", ans);
for (i = M - 1; i > 0; i--) {
int j;
for (j = 0; j < ec[i]; j++) {
ans += es[i][j] - j;
ans -= (N - 1 - es[i][j]) - (ec[i] - 1 - j);
}
printf("%" PRIu64 "\n", ans);
}
return 0;
}
/*
k = 0 : 普通に求める
k = n + 1 : k = n のときから、
・最強だった B_i = M - 1 が最弱になる
・ほかの大小関係は変わらない
ので、A_i = M - 1 - n の右側にあるそれ以外の数を引いて、左側にあるそれ以外の数を足す
*/
Submission Info
| Submission Time | |
|---|---|
| Task | F - Rotated Inversions |
| User | mikecat |
| Language | C (gcc 12.2.0) |
| Score | 0 |
| Code Size | 1389 Byte |
| Status | RE |
| Exec Time | 95 ms |
| Memory | 12912 KB |
Judge Result
| Set Name | Sample | All | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 0 / 500 | ||||||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 01_handmade_05.txt, 01_handmade_06.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt, 02_random_19.txt, 02_random_20.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | AC | 0 ms | 1744 KB |
| 00_sample_01.txt | AC | 0 ms | 1732 KB |
| 00_sample_02.txt | AC | 0 ms | 1632 KB |
| 01_handmade_00.txt | AC | 0 ms | 1748 KB |
| 01_handmade_01.txt | AC | 9 ms | 1740 KB |
| 01_handmade_02.txt | AC | 33 ms | 12672 KB |
| 01_handmade_03.txt | AC | 33 ms | 12912 KB |
| 01_handmade_04.txt | AC | 49 ms | 12804 KB |
| 01_handmade_05.txt | AC | 48 ms | 12808 KB |
| 01_handmade_06.txt | AC | 48 ms | 12832 KB |
| 02_random_00.txt | AC | 34 ms | 9100 KB |
| 02_random_01.txt | AC | 24 ms | 7148 KB |
| 02_random_02.txt | AC | 14 ms | 5196 KB |
| 02_random_03.txt | AC | 13 ms | 5180 KB |
| 02_random_04.txt | AC | 16 ms | 5668 KB |
| 02_random_05.txt | WA | 48 ms | 10476 KB |
| 02_random_06.txt | RE | 88 ms | 6832 KB |
| 02_random_07.txt | RE | 91 ms | 7448 KB |
| 02_random_08.txt | RE | 93 ms | 7736 KB |
| 02_random_09.txt | RE | 95 ms | 8056 KB |
| 02_random_10.txt | RE | 74 ms | 1704 KB |
| 02_random_11.txt | RE | 72 ms | 1556 KB |
| 02_random_12.txt | RE | 74 ms | 1588 KB |
| 02_random_13.txt | RE | 73 ms | 1620 KB |
| 02_random_14.txt | RE | 75 ms | 1716 KB |
| 02_random_15.txt | RE | 74 ms | 1680 KB |
| 02_random_16.txt | RE | 74 ms | 1724 KB |
| 02_random_17.txt | RE | 74 ms | 1600 KB |
| 02_random_18.txt | RE | 73 ms | 1700 KB |
| 02_random_19.txt | RE | 74 ms | 1704 KB |
| 02_random_20.txt | RE | 76 ms | 2420 KB |