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
#include "teatr.h"
#include "message.h"
#include<bits/stdc++.h>
#define f first
#define s second
using namespace std;

const int MAXN=1e6+13;
int tree[4*MAXN];

int sprawdz (int v, int x, int y, int a)
{
    if (y<a)
        return 0;
    if (x>=a)
        return tree[v];
    return sprawdz (v*2, x, (x+y)/2, a)+sprawdz (v*2+1, (x+y)/2+1, y, a);
}

void dodaj (int x)
{
    while (x>0)
    {
        tree[x]++;
        x/=2;
    }
}

int main()
{
    int n,x;
    long long wyn=0;
    int pot=1;
    //scanf ("%d", &n);
    if (MyNodeId()!=0)
        return 0;
    n=GetN();
    while (pot<n)
        pot*=2;
    for (int i=0; i<n; i++)
    {
        x=GetElement(i);
        //scanf ("%d", &x);
        wyn+=(long long)(sprawdz (1,1,pot,x+1));
        dodaj (x+pot-1);
    }
    printf ("%lld", wyn);
    return 0;
}