#include <iostream>
#include "teatr.h"
#include "message.h"
using namespace std;
const int maks=1048576;
long long int tree[2*maks];
void Aktualizuj(int x)
{
int indeks=maks+x-1;
while(indeks>=1){
tree[indeks]++;
indeks/=2;
}
}
long long int Dodaj(int x)
{
int indeks=maks+x-1;
long long int suma=0;
while(indeks>1){
if(indeks%2==0) suma+=tree[indeks+1];
indeks/=2;
}
return suma;
}
int main()
{
int n=GetN(), x;
long long int wynik=0;
for(int i=0; i<2*maks; ++i) tree[i]=0;
if(MyNodeId()==0){
for(int i=0; i<n; ++i){
x=GetElement(i);
Aktualizuj(x);
wynik+=Dodaj(x);
}
cout<<wynik<<endl;
}
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 43 44 | #include <iostream> #include "teatr.h" #include "message.h" using namespace std; const int maks=1048576; long long int tree[2*maks]; void Aktualizuj(int x) { int indeks=maks+x-1; while(indeks>=1){ tree[indeks]++; indeks/=2; } } long long int Dodaj(int x) { int indeks=maks+x-1; long long int suma=0; while(indeks>1){ if(indeks%2==0) suma+=tree[indeks+1]; indeks/=2; } return suma; } int main() { int n=GetN(), x; long long int wynik=0; for(int i=0; i<2*maks; ++i) tree[i]=0; if(MyNodeId()==0){ for(int i=0; i<n; ++i){ x=GetElement(i); Aktualizuj(x); wynik+=Dodaj(x); } cout<<wynik<<endl; } return 0; } |
English