#define _CRT_SECURE_NO_WARNINGS 1
#define _WINSOCK_DEPRECATED_NO_WARNINGS 1
//
#include <cstdio>
#include "message.h"
#include "teatr.h"
using namespace std;
const int MAX = 1000001;
int level[MAX];
int main()
{
int node = MyNodeId();
if (node > 20)
{
return 0;
}
if (node == 0)
{
long long sum = 0;
for (int i = 0; i < 20; ++i)
{
int from = Receive(-1);
sum += GetLL(from);
}
printf("%llu", sum);
return 0;
}
int n = GetN();
long long result = 0;
while (--n > -1)
{
int height = GetElement(n);
int bucket = height >> (node - 1);
if (bucket & 1)
{
result += level[bucket - 1];
}
level[bucket]++;
}
PutLL(0, result);
Send(0);
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | #define _CRT_SECURE_NO_WARNINGS 1 #define _WINSOCK_DEPRECATED_NO_WARNINGS 1 // #include <cstdio> #include "message.h" #include "teatr.h" using namespace std; const int MAX = 1000001; int level[MAX]; int main() { int node = MyNodeId(); if (node > 20) { return 0; } if (node == 0) { long long sum = 0; for (int i = 0; i < 20; ++i) { int from = Receive(-1); sum += GetLL(from); } printf("%llu", sum); return 0; } int n = GetN(); long long result = 0; while (--n > -1) { int height = GetElement(n); int bucket = height >> (node - 1); if (bucket & 1) { result += level[bucket - 1]; } level[bucket]++; } PutLL(0, result); Send(0); } |
English