#include "message.h" #include "teatr.h" #include <iostream> using namespace std; const int CHUNK = 1000000; int count[CHUNK] = { 0 }; int main() { int n = GetN(); int id = MyNodeId(); long long issues = 0; if (id * CHUNK < n) { int start = id * CHUNK; for (int i = start; i < start + CHUNK && i < n; i++) { int element = GetElement(i); count[element - 1]++; for (int j = element; j < 5; j++) { issues += count[j]; } } } if (id != 0) { PutLL(0, issues); PutInt(0, count[0]); PutInt(0, count[1]); PutInt(0, count[2]); PutInt(0, count[3]); PutInt(0, count[4]); Send(0); } else { for (int i = 1; i < NumberOfNodes(); i++) { Receive(i); issues += GetLL(i); int c0 = GetInt(i); issues += c0 * (count[1] + count[2] + count[3] + count[4]); count[0] += c0; int c1 = GetInt(i); issues += c1 * (count[2] + count[3] + count[4]); count[1] += c1; int c2 = GetInt(i); issues += c2 * (count[3] + count[4]); count[2] += c2; int c3 = GetInt(i); issues += c3 * count[4]; count[3] += c3; int c4 = GetInt(i); count[4] += c4; } cout << issues; } 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 | #include "message.h" #include "teatr.h" #include <iostream> using namespace std; const int CHUNK = 1000000; int count[CHUNK] = { 0 }; int main() { int n = GetN(); int id = MyNodeId(); long long issues = 0; if (id * CHUNK < n) { int start = id * CHUNK; for (int i = start; i < start + CHUNK && i < n; i++) { int element = GetElement(i); count[element - 1]++; for (int j = element; j < 5; j++) { issues += count[j]; } } } if (id != 0) { PutLL(0, issues); PutInt(0, count[0]); PutInt(0, count[1]); PutInt(0, count[2]); PutInt(0, count[3]); PutInt(0, count[4]); Send(0); } else { for (int i = 1; i < NumberOfNodes(); i++) { Receive(i); issues += GetLL(i); int c0 = GetInt(i); issues += c0 * (count[1] + count[2] + count[3] + count[4]); count[0] += c0; int c1 = GetInt(i); issues += c1 * (count[2] + count[3] + count[4]); count[1] += c1; int c2 = GetInt(i); issues += c2 * (count[3] + count[4]); count[2] += c2; int c3 = GetInt(i); issues += c3 * count[4]; count[3] += c3; int c4 = GetInt(i); count[4] += c4; } cout << issues; } return 0; } |