//algorytm zapozyczony ze strony: https://www.geeksforgeeks.org/counting-inversions/
//Michal Holubowicz
#include "teatr.h"
#include "message.h"
#include <bits/stdc++.h>
using namespace std;
int arr[2000006];
int n;
int getInvCount(int arr[], int n)
{
int inv_count = 0;
for (int i = 0; i < n - 1; i++)
for (int j = i + 1; j < n; j++)
if (arr[i] > arr[j])
inv_count++;
return inv_count;
}
int main(int argv, char** args)
{
int fd=MyNodeId();
n=GetN();
if(fd>0)
return 0;
for(int i=0; i<n; i++)
arr[i]=GetElement(i);
printf("%d \n", getInvCount(arr, n));
}
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 | //algorytm zapozyczony ze strony: https://www.geeksforgeeks.org/counting-inversions/ //Michal Holubowicz #include "teatr.h" #include "message.h" #include <bits/stdc++.h> using namespace std; int arr[2000006]; int n; int getInvCount(int arr[], int n) { int inv_count = 0; for (int i = 0; i < n - 1; i++) for (int j = i + 1; j < n; j++) if (arr[i] > arr[j]) inv_count++; return inv_count; } int main(int argv, char** args) { int fd=MyNodeId(); n=GetN(); if(fd>0) return 0; for(int i=0; i<n; i++) arr[i]=GetElement(i); printf("%d \n", getInvCount(arr, n)); } |
English