Submission #67458763


Source Code Expand

Copy
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#define MAX 8192
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];
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>

#define MAX 8192

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;
int A[MAX];

struct youso_s {
	int value, idx;
};

int cmp(const void* x, const void* y) {
	struct youso_s a = *(const struct youso_s*)x, b = *(const struct youso_s*)y;
	return a.value < b.value ? -1 : a.value > b.value;
}

struct youso_s youso[MAX];

int main(void) {
	int i, j, k;
	int64_t ans = 0;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d", &A[i]) != 1) return 1;
		youso[i].value = A[i];
		youso[i].idx = i;
	}
	/* 下から処理する */
	qsort(youso, N, sizeof(*youso), cmp);
	for (i = 0; i < N; ) {
		/* 同じ高さのやつをまとめて処理する */
		for (j = i; j < N && youso[j].value == youso[i].value; j++) {
			/* これまでのやつ (すなわち、これより小さい) の数を前後に分けて求める */
			int pos = youso[j].idx;
			int mae = bit_sum(pos);
			int ato = bit_sum(N) - mae;
			ans += (int64_t)mae * ato;
		}
		/* この高さのやつを仲間に加える */
		for (k = i; k < j; k++) {
			bit_add(youso[k].idx, 1);
		}
		i = j;
	}
	printf("%" PRId64 "\n", ans);
	return 0;
}

Submission Info

Submission Time
Task A - Count Triplets
User mikecat
Language C (gcc 12.2.0)
Score 200
Code Size 1498 Byte
Status AC
Exec Time 2 ms
Memory 1824 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 200 / 200
Status
AC × 3
AC × 17
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt AC 1 ms 1664 KiB
02.txt AC 1 ms 1756 KiB
03.txt AC 1 ms 1656 KiB
04.txt AC 0 ms 1652 KiB
05.txt AC 2 ms 1736 KiB
06.txt AC 2 ms 1824 KiB
07.txt AC 1 ms 1744 KiB
08.txt AC 1 ms 1760 KiB
09.txt AC 2 ms 1752 KiB
10.txt AC 1 ms 1704 KiB
11.txt AC 1 ms 1740 KiB
12.txt AC 1 ms 1692 KiB
13.txt AC 1 ms 1716 KiB
14.txt AC 1 ms 1672 KiB
s1.txt AC 0 ms 1612 KiB
s2.txt AC 0 ms 1660 KiB
s3.txt AC 0 ms 1736 KiB


2025-07-10 (Thu)
07:12:38 +09:00