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
#include <bits/stdc++.h>
#include <sys/time.h>
#include "teatr.h"
#include "message.h"
#define ST first
#define ND second
#define pb push_back
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, a, n) for (int i = a; i >= n; i--)
#define SZ(x) ((int)x.size())
#define ALL(x) (x.begin(), x.end())
#define pii pair <int, int>
#define ll long long
#define LD long double
using namespace std;
long long ans;
int ilosc, id;
int wl, wr, idx, n, mid, klotni, d[7000005], x;
int base = (1<<20);
void wstaw(int w)
{
    w += base;
    while(w>=1)
    {
        d[w]++;
        w/=2;
    }
}
/*void query(int a, int b, int w, int lo, int hi)
{
    if (a==lo && b==hi)
    {
        ans+=d[w];
        return;
    }
    if (a > b || a < lo || a > hi || b < lo || b > hi) return;
    int mid = (lo+hi)/2;
    query(a, min(mid, b), w*2, lo, mid);
    query(max(mid+1, a), b, w*2+1, mid+1, hi);
}*/
void query(int w)
{
    w+=base;
    while(w > 1)
    {
        if(w%2==0)
            ans+=d[w+1];
        w/=2;
    }
}
main()
{
    ilosc = NumberOfNodes();
    id = MyNodeId();
    if(id!=0)return 0;
    n = GetN();
    rep(i, 0, n-1)
    {
        x = GetElement(i);
        //cin>>x;
        //cout<<i<<endl;
        query(x);
        //query(x+1, 1000000, 1, 1, base+1);
        wstaw(x);
    }
    cout<<ans;
}