Niestety, nie byliśmy w stanie w pełni poprawnie wyświetlić tego pliku, ponieważ nie jest zakodowany w UTF-8.
Możesz pobrać ten plik i spróbować otworzyć go samodzielnie.
#include <stdio.h> #include <time.h> #include <math.h> #include <stdlib.h> #include <string.h> #include <map> #include <string> #include <vector> #include <iostream> #include <sstream> #include <queue> #include <algorithm> #include <assert.h> #include "teatr.h" #include "message.h" using namespace std; #define ll long long #define PB push_back #define FOR(a,start,end) for(int a=int(start); a<int(end); a++) #define INF INT_MAX #define SORT(a) sort(a.begin(),a.end()) #define CL(a,x) memset(a,x,sizeof(a)) #define REP(a,x) for(int a=0;a<x;a++) #define REP1(a,x) for(int a=1;a<=x;a++) #define MP make_pair typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<string> vs; typedef vector<pii> vii; typedef vector<vector<int> > vvi; typedef vector<vector<string> > vvs; typedef vector<pair<string, string> > vss; typedef pair<string, string> pss; typedef pair<int, pii> ppii; typedef vector<ppii> vppii; typedef vector<vector<pii> > vvii; typedef vector<vvi> vvvi; int nz; int m, n, k, a, b, c, d,ib; ll z, z0; vi vk; vvi vvk; int bs(int a) { int k1 = 0; int k2 = vk.size() - 1; if (a < vk[k1]) { vk.insert(vk.begin(), a); return 0; } if (a > vk[k2]) { vk.push_back(a); return vk.size() - 1; } k = (k1 + k2) / 2; while (k2 - k1 > 1) { if (vk[k] < a) k1 = k; else k2 = k; } vk.insert(vk.begin() + k2, a); return k2; } int main() { //freopen( "c:\\wojtek\\uva\\pa\\debug\\t1.in", "rt", stdin); //pi=2*acos(0.0); m = MyNodeId(); nz = (ll)NumberOfNodes(); // if(m==4){ // cerr<<"m = "<<m<<" nz = "<<nz<<" w = "<<w<<" h = "<<h<<endl; // } n = GetN(); if (n <= 1000) { if (m == 0) { int kmax = 1; // cerr << "jestem 0" << endl; // cerr << "n = " << n << endl; vk.clear(); vvk.assign(1000001, vk); for (int i = 0; i < n; i++) { k = GetElement(i); kmax = max(kmax, k); vvk[k].push_back(i); } int i = 1; while (vvk[i].size() == 0) i++; vk = vvk[i]; z = 0; for (int j = 0; j < vk.size(); j++) { z += vk[j] - j; } i++; for (; i <= kmax; i++) { for (int j = 0; j < vvk[i].size(); j++) { z += vvk[i][j] - bs(vvk[i][j]); } } cout << z << endl; } } else { k = n / nz; //ile rz�d�w w ka�dej instancji //cerr << "instancja nr = "<<m << endl; int k1 = m * k; int k2 = (m + 1)*k - 1; if (m == nz - 1) k2 = n - 1; int kmax = 1; vk.clear(); vvk.assign(1000001, vk); //cerr << "k1/k2 = " << k1 << " " << k2 << endl; for (int i = k1; i <= k2; i++) { k = GetElement(i); vvk[k].push_back(i); kmax = max(kmax, k); } //cerr <<m<< " odczyta�em " << endl; //cerr << "kmax = " << kmax << endl; ib = 1; while (vvk[ib].size() == 0) ib++; vk = vvk[ib]; z = 0; for (int j = 0; j < vk.size(); j++) { z += vk[j] - j-k1; } /* if (m == 9) { for (int ix = 0; ix < vk.size(); ix++) cerr << "vk[ix] = " << vk[ix] << " "; cerr << endl; } if (m == 9) cerr << "z = " << z << endl; */ ib++; //if (m == 9) // cerr << "i0 = " << ib << endl; for (int ia=ib; ia<=kmax; ia++) { // if (m == 9) // cerr << "ia = " << ia << " "; for (int j = 0; j < vvk[ia].size(); j++) { z += vvk[ia][j] - bs(vvk[ia][j])-k1; } } if (m == 5) // cerr << endl; cerr <<m<< "policzy�em" << endl; if (kmax <= 1000) { vi vk0; vk0.assign(kmax, 0); if (m < nz - 1) { Receive(m + 1); int k0 = GetInt(m + 1); vi vk0; vk0.assign(k0, 0); for (int i = 1; i <= k0; i++) { vk0[i] = GetInt(m + 1); } Receive(m + 1); ll z0 = GetLL(m + 1); z += z0; // cerr << m << "dosta�emm" << endl; for (int i = 0; i < k0; i++) { b = k2 - k1 + 1; for (int j = 1; j <= kmax; j++) { b -= vvk[j].size(); z += vk0[i] * b; } } } if (m > 0) { for (int i = 0; i < max((int)vk0.size(), kmax - 1); i++) vk0[i] += vvk[i + 1].size(); PutInt(m - 1, (int)vk0.size()); for (int i = 0; i < vk0.size(); i++) PutInt(m - 1, vk0[i]); Send(m - 1); PutLL(m - 1, z); Send(m - 1); //cerr << m << "wys�a�em" << endl; } else cout << z << endl; } } //czas = clock() - czas; //printf("%lf\n",double(czas)/CLOCKS_PER_SEC); //} 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 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | #include <stdio.h> #include <time.h> #include <math.h> #include <stdlib.h> #include <string.h> #include <map> #include <string> #include <vector> #include <iostream> #include <sstream> #include <queue> #include <algorithm> #include <assert.h> #include "teatr.h" #include "message.h" using namespace std; #define ll long long #define PB push_back #define FOR(a,start,end) for(int a=int(start); a<int(end); a++) #define INF INT_MAX #define SORT(a) sort(a.begin(),a.end()) #define CL(a,x) memset(a,x,sizeof(a)) #define REP(a,x) for(int a=0;a<x;a++) #define REP1(a,x) for(int a=1;a<=x;a++) #define MP make_pair typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<string> vs; typedef vector<pii> vii; typedef vector<vector<int> > vvi; typedef vector<vector<string> > vvs; typedef vector<pair<string, string> > vss; typedef pair<string, string> pss; typedef pair<int, pii> ppii; typedef vector<ppii> vppii; typedef vector<vector<pii> > vvii; typedef vector<vvi> vvvi; int nz; int m, n, k, a, b, c, d,ib; ll z, z0; vi vk; vvi vvk; int bs(int a) { int k1 = 0; int k2 = vk.size() - 1; if (a < vk[k1]) { vk.insert(vk.begin(), a); return 0; } if (a > vk[k2]) { vk.push_back(a); return vk.size() - 1; } k = (k1 + k2) / 2; while (k2 - k1 > 1) { if (vk[k] < a) k1 = k; else k2 = k; } vk.insert(vk.begin() + k2, a); return k2; } int main() { //freopen( "c:\\wojtek\\uva\\pa\\debug\\t1.in", "rt", stdin); //pi=2*acos(0.0); m = MyNodeId(); nz = (ll)NumberOfNodes(); // if(m==4){ // cerr<<"m = "<<m<<" nz = "<<nz<<" w = "<<w<<" h = "<<h<<endl; // } n = GetN(); if (n <= 1000) { if (m == 0) { int kmax = 1; // cerr << "jestem 0" << endl; // cerr << "n = " << n << endl; vk.clear(); vvk.assign(1000001, vk); for (int i = 0; i < n; i++) { k = GetElement(i); kmax = max(kmax, k); vvk[k].push_back(i); } int i = 1; while (vvk[i].size() == 0) i++; vk = vvk[i]; z = 0; for (int j = 0; j < vk.size(); j++) { z += vk[j] - j; } i++; for (; i <= kmax; i++) { for (int j = 0; j < vvk[i].size(); j++) { z += vvk[i][j] - bs(vvk[i][j]); } } cout << z << endl; } } else { k = n / nz; //ile rz�d�w w ka�dej instancji //cerr << "instancja nr = "<<m << endl; int k1 = m * k; int k2 = (m + 1)*k - 1; if (m == nz - 1) k2 = n - 1; int kmax = 1; vk.clear(); vvk.assign(1000001, vk); //cerr << "k1/k2 = " << k1 << " " << k2 << endl; for (int i = k1; i <= k2; i++) { k = GetElement(i); vvk[k].push_back(i); kmax = max(kmax, k); } //cerr <<m<< " odczyta�em " << endl; //cerr << "kmax = " << kmax << endl; ib = 1; while (vvk[ib].size() == 0) ib++; vk = vvk[ib]; z = 0; for (int j = 0; j < vk.size(); j++) { z += vk[j] - j-k1; } /* if (m == 9) { for (int ix = 0; ix < vk.size(); ix++) cerr << "vk[ix] = " << vk[ix] << " "; cerr << endl; } if (m == 9) cerr << "z = " << z << endl; */ ib++; //if (m == 9) // cerr << "i0 = " << ib << endl; for (int ia=ib; ia<=kmax; ia++) { // if (m == 9) // cerr << "ia = " << ia << " "; for (int j = 0; j < vvk[ia].size(); j++) { z += vvk[ia][j] - bs(vvk[ia][j])-k1; } } if (m == 5) // cerr << endl; cerr <<m<< "policzy�em" << endl; if (kmax <= 1000) { vi vk0; vk0.assign(kmax, 0); if (m < nz - 1) { Receive(m + 1); int k0 = GetInt(m + 1); vi vk0; vk0.assign(k0, 0); for (int i = 1; i <= k0; i++) { vk0[i] = GetInt(m + 1); } Receive(m + 1); ll z0 = GetLL(m + 1); z += z0; // cerr << m << "dosta�emm" << endl; for (int i = 0; i < k0; i++) { b = k2 - k1 + 1; for (int j = 1; j <= kmax; j++) { b -= vvk[j].size(); z += vk0[i] * b; } } } if (m > 0) { for (int i = 0; i < max((int)vk0.size(), kmax - 1); i++) vk0[i] += vvk[i + 1].size(); PutInt(m - 1, (int)vk0.size()); for (int i = 0; i < vk0.size(); i++) PutInt(m - 1, vk0[i]); Send(m - 1); PutLL(m - 1, z); Send(m - 1); //cerr << m << "wys�a�em" << endl; } else cout << z << endl; } } //czas = clock() - czas; //printf("%lf\n",double(czas)/CLOCKS_PER_SEC); //} return 0; } |