Submission #64426136
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 | 500 |
| Code Size | 1389 Byte |
| Status | AC |
| Exec Time | 66 ms |
| Memory | 12892 KB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 500 / 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 | 1 ms | 1764 KB |
| 00_sample_01.txt | AC | 1 ms | 1772 KB |
| 00_sample_02.txt | AC | 0 ms | 1664 KB |
| 01_handmade_00.txt | AC | 1 ms | 1700 KB |
| 01_handmade_01.txt | AC | 9 ms | 1636 KB |
| 01_handmade_02.txt | AC | 36 ms | 12636 KB |
| 01_handmade_03.txt | AC | 35 ms | 12892 KB |
| 01_handmade_04.txt | AC | 65 ms | 12716 KB |
| 01_handmade_05.txt | AC | 65 ms | 12756 KB |
| 01_handmade_06.txt | AC | 66 ms | 12836 KB |
| 02_random_00.txt | AC | 44 ms | 9080 KB |
| 02_random_01.txt | AC | 27 ms | 7244 KB |
| 02_random_02.txt | AC | 15 ms | 5228 KB |
| 02_random_03.txt | AC | 14 ms | 5080 KB |
| 02_random_04.txt | AC | 16 ms | 5700 KB |
| 02_random_05.txt | AC | 63 ms | 10456 KB |
| 02_random_06.txt | AC | 61 ms | 10380 KB |
| 02_random_07.txt | AC | 63 ms | 10476 KB |
| 02_random_08.txt | AC | 62 ms | 10472 KB |
| 02_random_09.txt | AC | 62 ms | 10428 KB |
| 02_random_10.txt | AC | 34 ms | 4852 KB |
| 02_random_11.txt | AC | 31 ms | 4504 KB |
| 02_random_12.txt | AC | 31 ms | 4464 KB |
| 02_random_13.txt | AC | 36 ms | 5184 KB |
| 02_random_14.txt | AC | 35 ms | 5196 KB |
| 02_random_15.txt | AC | 31 ms | 4520 KB |
| 02_random_16.txt | AC | 36 ms | 4764 KB |
| 02_random_17.txt | AC | 31 ms | 4592 KB |
| 02_random_18.txt | AC | 34 ms | 4884 KB |
| 02_random_19.txt | AC | 34 ms | 4944 KB |
| 02_random_20.txt | AC | 36 ms | 10408 KB |