### Saratov State University :: Online Contester

::Go
- home
- news
- register
 - update personal info
 - problemset archive
- submit
- status online
- standing
- contests
- virtual contests
- forum
- statistic
- FAQ
- links
- projects

 ::Poll Are you registered on Codeforces?YesNoWhat is it???[results]

::webboard

 WHY WRONG ANSWER ON TEST 2!!!!!!!!!!!!!
Author: ata
ID: 059912
Problem: 180
Contest: 0
Date: 2014-07-28 12:20:48

#include <iostream>
using namespace std;

const int Maxn=65537+10;

int n,a[Maxn],t[Maxn];
unsigned long long s;
inline void input()
{
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i];
}

void mer(int f,int l)
{
int p1=f,mid=(f+l)/2,p2=mid+1;
for(int i=f;i<=l;i++)
if(p1<=mid&&p2<=l)
{
if(a[p1]>a[p2])
{
t[i]=a[p2];
p2++;
}
else if(a[p1]<=a[p2])
{
t[i]=a[p1];
s+=(p2-mid-1);
p1++;
}
}
else if(p1==mid+1)
{
t[i]=a[p2];
p2++;
}
else if(p2==l+1)
{
t[i]=a[p1];
s+=(p2-mid-1);
}

for(int i=f;i<=l;i++)
a[i]=t[i];
}

void merg_sort(int f,int l)
{
if(f==l)
return;
int mid=(f+l)/2;
merg_sort(f,mid);
merg_sort(mid+1,l);
mer(f,l);
}

inline void output()
{
cout<<s;
// for(int i=0;i<n;cout<<a[i]<<" ",i++);
}

int main()
{
input();
merg_sort(0,n-1);
output();
return 0;
}

 ::Login form.login input{margin:2px;font-size:10px;} your id: password: Forgot password?

 ::News 22.10.12 - The problems from the Southern Subregional Programming Contest 2012 added to the problemset archive (542 - 553). 22.10.12 - After the start of the contest the statements in PDF will be available by the link.23.10.11 - The problems from the Southern Subregional Programming Contest 2011 added to the problemset archive (530 - 541).

::Counter

 Server time: 2018-06-23 19:58:17 Online Contester Team © 2002 - 2016. All rights reserved.