#include "teatr.h" #include "message.h" #include <iostream> using namespace std; const int MAXN = 1000000; int LastNode() { int n = GetN() - 1; return (int)(n / MAXN); } int tab[6]; int tabb[6]; long long int result = 0; int main() { int node = MyNodeId(); if (node > LastNode()) return 0; int start = node * MAXN; int end = start + min(MAXN, GetN()); for (int i = start; i < end; i++) { int element = GetElement(i); for (int j = element + 1; j <= 5; j++) { result += tab[j]; } tab[element]++; } if (node > 0) { Receive(node - 1); tabb[0] = GetLL(node - 1); tabb[1] = GetLL(node - 1); tabb[2] = GetLL(node - 1); tabb[3] = GetLL(node - 1); tabb[4] = GetLL(node - 1); tabb[5] = GetLL(node - 1); result += GetLL(node - 1); result += (tab[0] * (tabb[1] + tabb[2] + tabb[3] + tabb[4] + tabb[5])); result += (tab[1] * (tabb[2] + tabb[3] + tabb[4] + tabb[5])); result += (tab[2] * (tabb[3] + tabb[4] + tabb[5])); result += (tab[3] * (tabb[4] + tabb[5])); result += (tab[4] * (tabb[5])); tab[0] += tabb[0]; tab[1] += tabb[1]; tab[2] += tabb[2]; tab[3] += tabb[3]; tab[4] += tabb[4]; tab[5] += tabb[5]; } if (node != LastNode()) { PutLL(node + 1, tab[0]); PutLL(node + 1, tab[1]); PutLL(node + 1, tab[2]); PutLL(node + 1, tab[3]); PutLL(node + 1, tab[4]); PutLL(node + 1, tab[5]); PutLL(node + 1, result); Send(node + 1); } else { cout << result; } return 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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | #include "teatr.h" #include "message.h" #include <iostream> using namespace std; const int MAXN = 1000000; int LastNode() { int n = GetN() - 1; return (int)(n / MAXN); } int tab[6]; int tabb[6]; long long int result = 0; int main() { int node = MyNodeId(); if (node > LastNode()) return 0; int start = node * MAXN; int end = start + min(MAXN, GetN()); for (int i = start; i < end; i++) { int element = GetElement(i); for (int j = element + 1; j <= 5; j++) { result += tab[j]; } tab[element]++; } if (node > 0) { Receive(node - 1); tabb[0] = GetLL(node - 1); tabb[1] = GetLL(node - 1); tabb[2] = GetLL(node - 1); tabb[3] = GetLL(node - 1); tabb[4] = GetLL(node - 1); tabb[5] = GetLL(node - 1); result += GetLL(node - 1); result += (tab[0] * (tabb[1] + tabb[2] + tabb[3] + tabb[4] + tabb[5])); result += (tab[1] * (tabb[2] + tabb[3] + tabb[4] + tabb[5])); result += (tab[2] * (tabb[3] + tabb[4] + tabb[5])); result += (tab[3] * (tabb[4] + tabb[5])); result += (tab[4] * (tabb[5])); tab[0] += tabb[0]; tab[1] += tabb[1]; tab[2] += tabb[2]; tab[3] += tabb[3]; tab[4] += tabb[4]; tab[5] += tabb[5]; } if (node != LastNode()) { PutLL(node + 1, tab[0]); PutLL(node + 1, tab[1]); PutLL(node + 1, tab[2]); PutLL(node + 1, tab[3]); PutLL(node + 1, tab[4]); PutLL(node + 1, tab[5]); PutLL(node + 1, result); Send(node + 1); } else { cout << result; } return 0; } |