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
#include "message.h"
#include "teatr.h"
#include <cstdio>

using namespace std;

long long wyn, d[20000], zak=16380, il, ile;
int p,a,n,k,x;

int main() {
  if(MyNodeId() == 0) {
	for(int i=1; i<=62; i++)
	{
		Receive(i);
		wyn+=GetLL(i);
	}
	printf("%lld", wyn);
  }
  else if(MyNodeId()<=62)
  {
	  n=GetN();
	  p=1+(MyNodeId()-1)*zak; k=p+zak-1;
	  for(int i=0; i<n; i++)
	  {
		  a=GetElement(i);
		  if(a>k)il++;
		  if(p<=a&&a<=k)
		  {
			  wyn+=il+ile;
			  x=a-p+1;
			  while(x>0)
			  {
				  wyn-=d[x];
				  x-=(x&(-x));
			  }
			  x=a-p+1;
			  while(x<=zak)
			  {
				  d[x]++;
				  x+=(x&(-x));
			  }
			  ile++;
		  }
	  }
	  PutLL(0,wyn);
	  Send(0);
  }
}