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
#include<bits/stdc++.h>
#include "teatr.h"
#include "message.h"
using namespace std;
int drzewo[3000005];
int pot=1;
long long out;
void add(int a)
{
    int pom=a+pot;
    while(pom!=0)
    {
        drzewo[pom]++;
        pom/=2;
    }
}
void check(int a)
{
    int l=a+pot+1,r=1e6+pot+5;
    long long w=drzewo[r];
    if(l!=r)
        w+=drzewo[l];
    while(l/2!=r/2)
    {
        if(l%2==0)
            w+=drzewo[l+1];
        if(r%2==1)
            w+=drzewo[r-1];
        l/=2;
        r/=2;
    }
    out+=w;
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
    if (MyNodeId() == 0)
    {
        int a,b;
        a=GetN();
        while(pot<1e6)
            pot*=2;
        for(int x=0;x<a;x++)
        {
            b=GetElement(x);
            check(b);
            add(b);
        }
        cout<<out;
    }
	return 0;
}