#include <algorithm> #include <cstdio> #include <vector> #include <set> using namespace std; //#define __TEST #ifndef __TEST #include "message.h" #include "teatr.h" #endif #ifdef __TEST int GetN() { return int(1e8); } int GetElement(int i) { return (i * 1ll * i) % int(1e6) + 1; } long long mq[101] = {}; int ps = 0; int pr = 0; int NumberOfNodes() { return 4; } int MyNodeId() { return 0; } void Send(int target) { } int Receive(int source) { return source; } void PutLL(int target, long long value) { mq[ps++] = value; } long long GetLL(int source) { return mq[pr++]; } #endif #ifdef __TEST #define BASE 1048576 #define PAGE 10102 * 33 #else #define BASE 16384 #define PAGE 10102 #endif #define BASE2 1048576 int main() { static int dl[BASE * 2] = {}; static int dl2[BASE2 * 2] = {}; long long result = 0; int x = 0; int n = GetN(); int id = MyNodeId(); if (n <= 15000000) { if (id > 0) return 0; for (int i = 0; i < n; i++) { x = BASE2 + 1000001 - GetElement(i); while (x > 1) { if (x & 1) result += dl2[x - 1]; ++dl2[x]; x >>= 1; } } printf("%lld", result); return 0; } #ifdef __TEST for (id = 3; id >= 0; --id) { std::fill(std::begin(dl), std::end(dl), 0); result = 0; #endif long c2 = 0; long c3 = 0; long c4 = 0; long c5 = 0; long c6 = 0; if (id == 0) { for (int i = 0; i < n; i++) { switch (GetElement(i)) { case 1: result += c2 + c3 + c4 + c5 + c6; break; case 2: ++c2; result += c3 + c4 + c5 + c6; break; case 3: ++c3; result += c4 + c5 + c6; break; case 4: ++c4; result += c5 + c6; break; case 5: ++c5; result += c6; break; default: ++c6; break; } } } else { int low = (id == 1) ? 5 : (id - 1) * PAGE; int high = id * PAGE; for (int i = 0; i < n; i++) { x = GetElement(i); if (x > high) ++c6; else if (x > low) { result += c6; x = BASE + PAGE + low + - x; while (x > 1) { if (x & 1) result += dl[x - 1]; ++dl[x]; x >>= 1; } } } } if (id > 0) { } if (id == 0) { int non = NumberOfNodes(); for (int i = 1; i < non; i++) { Receive(i); result += GetLL(i); } printf("%lld", result); } else { PutLL(0, result); Send(0); } #ifdef __TEST } #endif 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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | #include <algorithm> #include <cstdio> #include <vector> #include <set> using namespace std; //#define __TEST #ifndef __TEST #include "message.h" #include "teatr.h" #endif #ifdef __TEST int GetN() { return int(1e8); } int GetElement(int i) { return (i * 1ll * i) % int(1e6) + 1; } long long mq[101] = {}; int ps = 0; int pr = 0; int NumberOfNodes() { return 4; } int MyNodeId() { return 0; } void Send(int target) { } int Receive(int source) { return source; } void PutLL(int target, long long value) { mq[ps++] = value; } long long GetLL(int source) { return mq[pr++]; } #endif #ifdef __TEST #define BASE 1048576 #define PAGE 10102 * 33 #else #define BASE 16384 #define PAGE 10102 #endif #define BASE2 1048576 int main() { static int dl[BASE * 2] = {}; static int dl2[BASE2 * 2] = {}; long long result = 0; int x = 0; int n = GetN(); int id = MyNodeId(); if (n <= 15000000) { if (id > 0) return 0; for (int i = 0; i < n; i++) { x = BASE2 + 1000001 - GetElement(i); while (x > 1) { if (x & 1) result += dl2[x - 1]; ++dl2[x]; x >>= 1; } } printf("%lld", result); return 0; } #ifdef __TEST for (id = 3; id >= 0; --id) { std::fill(std::begin(dl), std::end(dl), 0); result = 0; #endif long c2 = 0; long c3 = 0; long c4 = 0; long c5 = 0; long c6 = 0; if (id == 0) { for (int i = 0; i < n; i++) { switch (GetElement(i)) { case 1: result += c2 + c3 + c4 + c5 + c6; break; case 2: ++c2; result += c3 + c4 + c5 + c6; break; case 3: ++c3; result += c4 + c5 + c6; break; case 4: ++c4; result += c5 + c6; break; case 5: ++c5; result += c6; break; default: ++c6; break; } } } else { int low = (id == 1) ? 5 : (id - 1) * PAGE; int high = id * PAGE; for (int i = 0; i < n; i++) { x = GetElement(i); if (x > high) ++c6; else if (x > low) { result += c6; x = BASE + PAGE + low + - x; while (x > 1) { if (x & 1) result += dl[x - 1]; ++dl[x]; x >>= 1; } } } } if (id > 0) { } if (id == 0) { int non = NumberOfNodes(); for (int i = 1; i < non; i++) { Receive(i); result += GetLL(i); } printf("%lld", result); } else { PutLL(0, result); Send(0); } #ifdef __TEST } #endif return 0; } |