// Jedna instancja wypisuje maksymalny wzrost.
#include "message.h"
#include "teatr.h"
#include "bits/stdc++.h"
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
const int MXN=1e6+5;
const int roz=1e6;
long long zlicz[2*MXN+5],wynikus;
inline void dodaj(int v){
v+=roz;
zlicz[v]++;
while(v>0){
v/=2;
zlicz[v]++;
}
}
inline long long suma(int a,int b){
a+=roz;b+=roz;
long long wynik=zlicz[a];
if(a!=b)wynik+=zlicz[b];
while(a/2!=b/2){
if(a%2==0)wynik+=zlicz[a+1];
if(b%2==1)wynik+=zlicz[b-1];
a/=2;b/=2;
}
return wynik;
}
int main() {
if(MyNodeId()!=0)return 0;
int n = GetN();
for(int i=0;i<n;i++){
long long dzban=GetElement(i);
wynikus+=suma(dzban+1,roz);
dodaj(dzban);
}
cout<<wynikus<<endl;
}
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 | // Jedna instancja wypisuje maksymalny wzrost. #include "message.h" #include "teatr.h" #include "bits/stdc++.h" #include <iostream> #include <cstdio> #include <algorithm> #include <cmath> using namespace std; const int MXN=1e6+5; const int roz=1e6; long long zlicz[2*MXN+5],wynikus; inline void dodaj(int v){ v+=roz; zlicz[v]++; while(v>0){ v/=2; zlicz[v]++; } } inline long long suma(int a,int b){ a+=roz;b+=roz; long long wynik=zlicz[a]; if(a!=b)wynik+=zlicz[b]; while(a/2!=b/2){ if(a%2==0)wynik+=zlicz[a+1]; if(b%2==1)wynik+=zlicz[b-1]; a/=2;b/=2; } return wynik; } int main() { if(MyNodeId()!=0)return 0; int n = GetN(); for(int i=0;i<n;i++){ long long dzban=GetElement(i); wynikus+=suma(dzban+1,roz); dodaj(dzban); } cout<<wynikus<<endl; } |
English