Last active
May 30, 2021 04:12
-
-
Save KiJeong-Lim/95643433ab02056200fe9bddfa62e1f3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#define VM 30000 | |
void solve13558(void) | |
{ typedef long long unsigned int llu_t; | |
typedef short int val_t; | |
int count_vi[VM], count_vk[VM]; | |
val_t ary[100000]; | |
llu_t res = 0; | |
size_t len; | |
memset(count_vi, 0x0, sizeof(count_vi)); | |
memset(count_vk, 0x0, sizeof(count_vk)); | |
scanf("%zd", &len); | |
for (size_t n = 0; n < len; n++) | |
{ int input; | |
scanf("%d", &input); | |
ary[n] = input - 1; | |
} | |
for (size_t k = 0; k < len; k++) | |
{ const val_t vk = ary[k]; | |
count_vk[vk]++; | |
} | |
for (size_t j = 0; j < len; j++) | |
{ const val_t vj = ary[j]; | |
count_vk[vj]--; | |
if (2 * vj < VM) | |
{ for (val_t vi = 0; vi <= 2 * vj; vi++) | |
{ const val_t vk = 2 * vj - vi; | |
res += (llu_t)count_vi[vi] * (llu_t)count_vk[vk]; | |
} | |
} | |
else | |
{ for (val_t vk = 2 * vj - VM + 1; vk <= VM - 1; vk++) | |
{ const val_t vi = 2 * vj - vk; | |
res += (llu_t)count_vi[vi] * (llu_t)count_vk[vk]; | |
} | |
} | |
count_vi[vj]++; | |
} | |
printf("%llu\n", res); | |
} | |
int main(void) | |
{ solve13558(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment