// Artur Kraska, II UWr #include "message.h" #include "teatr.h" #include "bits/stdc++.h" //int GetN() { return int(1e8); } //int GetElement(int i) { return (i * 1ll * i) % int(1e6) + 1; } #define forr(i, n) for(int i=0; i<n; i++) #define FOREACH(iter, coll) for(typeof(coll.begin()) iter = coll.begin(); iter != coll.end(); ++iter) #define FOREACHR(iter, coll) for(typeof(coll.rbegin()) iter = coll.rbegin(); iter != coll.rend(); ++iter) #define lbound(P,R,PRED) ({typeof(P) X=P,RRR=(R), PPP = P; while(PPP<RRR) {X = (PPP+(RRR-PPP)/2); if(PRED) RRR = X; else PPP = X+1;} PPP;}) #define testy() int _tests; scanf("%d", &_tests); FOR(_test, 1, _tests) #define CLEAR(tab) memset(tab, 0, sizeof(tab)) #define CONTAIN(el, coll) (coll.find(el) != coll.end()) #define FOR(i, a, b) for(int i=a; i<=b; i++) #define FORD(i, a, b) for(int i=a; i>=b; i--) #define MP make_pair #define PB push_back #define deb(X) X; #define M 1000000007 #define INF 1000000007 #define EPS 1e-12 #define wekt(a, b, p) ((b.x-a.x)*(p.y-a.y)-(b.y-a.y)*(p.x-a.x)) using namespace std; int ID, N; int n, pocz, kon; long long ile[15], suma[15]; long long d[4200007]; int S; void dokladaj(int nr) { nr += S; while(nr > 0) { d[nr]++; nr >>= 1; } } long long zlicz(int nr) { long long res = 0; nr += S; while(nr > 1) { if((nr&1) == 0) res += d[nr+1]; nr >>= 1; } return res; } int main() { ID = MyNodeId(); N = NumberOfNodes(); // cout << ID << ", " << N << endl; n = GetN(); // cout << n << endl; pocz = ID*n/N; kon = (ID+1)*n/N-1; S = 1; while(S < 1000002) S *= 2; forr(i, pocz) { int a = GetElement(i); d[S+a]++; } FORD(i, S-1, 1) d[i] = d[i*2] + d[i*2+1]; long long res = 0; FOR(i, pocz, kon) { int a = GetElement(i); res += zlicz(a); dokladaj(a); // cout << "doliczyl dla elementu " << a << ", tera ma " << res << endl; } /* FOR(i, ID+1, N-1) { FOR(j, 1, 5) PutLL(i, ile[j]); Send(i); } forr(i, ID) { Receive(i); FOR(j, 1, 5) suma[j] += GetLL(i); } FOR(i, 1, 5) FOR(j, i+1, 5) res += suma[j]*ile[i]; */ if(ID != 0) { // cout << " wysylam " << res << endl; PutLL(0, res); Send(0); } else { FOR(i, 1, N-1) { Receive(i); res += GetLL(i); } //if(res == 2499912950050000ll) // while(1) res++; cout << res << endl; } 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 141 142 143 | // Artur Kraska, II UWr #include "message.h" #include "teatr.h" #include "bits/stdc++.h" //int GetN() { return int(1e8); } //int GetElement(int i) { return (i * 1ll * i) % int(1e6) + 1; } #define forr(i, n) for(int i=0; i<n; i++) #define FOREACH(iter, coll) for(typeof(coll.begin()) iter = coll.begin(); iter != coll.end(); ++iter) #define FOREACHR(iter, coll) for(typeof(coll.rbegin()) iter = coll.rbegin(); iter != coll.rend(); ++iter) #define lbound(P,R,PRED) ({typeof(P) X=P,RRR=(R), PPP = P; while(PPP<RRR) {X = (PPP+(RRR-PPP)/2); if(PRED) RRR = X; else PPP = X+1;} PPP;}) #define testy() int _tests; scanf("%d", &_tests); FOR(_test, 1, _tests) #define CLEAR(tab) memset(tab, 0, sizeof(tab)) #define CONTAIN(el, coll) (coll.find(el) != coll.end()) #define FOR(i, a, b) for(int i=a; i<=b; i++) #define FORD(i, a, b) for(int i=a; i>=b; i--) #define MP make_pair #define PB push_back #define deb(X) X; #define M 1000000007 #define INF 1000000007 #define EPS 1e-12 #define wekt(a, b, p) ((b.x-a.x)*(p.y-a.y)-(b.y-a.y)*(p.x-a.x)) using namespace std; int ID, N; int n, pocz, kon; long long ile[15], suma[15]; long long d[4200007]; int S; void dokladaj(int nr) { nr += S; while(nr > 0) { d[nr]++; nr >>= 1; } } long long zlicz(int nr) { long long res = 0; nr += S; while(nr > 1) { if((nr&1) == 0) res += d[nr+1]; nr >>= 1; } return res; } int main() { ID = MyNodeId(); N = NumberOfNodes(); // cout << ID << ", " << N << endl; n = GetN(); // cout << n << endl; pocz = ID*n/N; kon = (ID+1)*n/N-1; S = 1; while(S < 1000002) S *= 2; forr(i, pocz) { int a = GetElement(i); d[S+a]++; } FORD(i, S-1, 1) d[i] = d[i*2] + d[i*2+1]; long long res = 0; FOR(i, pocz, kon) { int a = GetElement(i); res += zlicz(a); dokladaj(a); // cout << "doliczyl dla elementu " << a << ", tera ma " << res << endl; } /* FOR(i, ID+1, N-1) { FOR(j, 1, 5) PutLL(i, ile[j]); Send(i); } forr(i, ID) { Receive(i); FOR(j, 1, 5) suma[j] += GetLL(i); } FOR(i, 1, 5) FOR(j, i+1, 5) res += suma[j]*ile[i]; */ if(ID != 0) { // cout << " wysylam " << res << endl; PutLL(0, res); Send(0); } else { FOR(i, 1, N-1) { Receive(i); res += GetLL(i); } //if(res == 2499912950050000ll) // while(1) res++; cout << res << endl; } return 0; } |