#include <bits/stdc++.h>
#include "teatr.h"
#include "message.h"
using namespace std;
long long T[10],w;
int main()
{
int a=GetN(),podzial=1e6,ID=MyNodeId();
for(int i=ID*podzial;i<min((ID+1)*podzial,a);i++)
{
int x=GetElement(i);
for(int j=x+1;j<=5;j++)
{
w+=T[j];
}
T[x]++;
}
if(ID!=0)
{
Receive(ID-1);
for(int i=1;i<=5;i++)
{
int p=GetInt(ID-1);
for(int j=i+1;j<=5;j++)w+=T[j]*p;
T[i]+=p;
}
w+=GetLL(ID-1);
}
if(ID!=99)
{
for(int i=1;i<=5;i++)
{
PutInt(ID+1, T[i]);
}
PutLL(ID+1, w);
Send(ID+1);
}
else
printf("%lld",w);
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 | #include <bits/stdc++.h> #include "teatr.h" #include "message.h" using namespace std; long long T[10],w; int main() { int a=GetN(),podzial=1e6,ID=MyNodeId(); for(int i=ID*podzial;i<min((ID+1)*podzial,a);i++) { int x=GetElement(i); for(int j=x+1;j<=5;j++) { w+=T[j]; } T[x]++; } if(ID!=0) { Receive(ID-1); for(int i=1;i<=5;i++) { int p=GetInt(ID-1); for(int j=i+1;j<=5;j++)w+=T[j]*p; T[i]+=p; } w+=GetLL(ID-1); } if(ID!=99) { for(int i=1;i<=5;i++) { PutInt(ID+1, T[i]); } PutLL(ID+1, w); Send(ID+1); } else printf("%lld",w); return 0; } |
English