hiho week 39 register

Ended

Participants:2159

Verdict:Accepted
Score:100 / 100
Submitted:2015-03-30 13:52:53

Lang:G++

Edit
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
#include <cstdio>
#include <cstring>
int N;
int a[100000];
int tmp[100000];
long long ans = 0;
void solve(int L, int R)
{
    if (L == R)
    {
        return;
    }
    int M = (L + R) >> 1;
    solve(L, M);
    solve(M + 1, R);
    int pos1 = L;
    int pos2 = M + 1;
    while (pos1 <= M && pos2 <= R)
    {
        if (a[pos1] > a[pos2])
        {
            ans += R - pos2 + 1;
            tmp[pos1 - L + pos2 - M - 1] = a[pos1];
            pos1++;
        }
        else
        {
            tmp[pos1 - L + pos2 - M - 1] = a[pos2];
            pos2++;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX