General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
39655752 Practice:
Single_Ready_To_Mingle
996D - 10 GNU C++14 Accepted 30 ms 12 KB 2018-06-25 20:00:32 2018-06-25 20:00:32
 
 
→ Source
#include "bits/stdc++.h"
using namespace std;

const int N = 1e2 + 5;

int n;
int a[2 * N];
int occ[2 * N];
int bit[N];

void update(int idx, int val)
{
    while(idx <= n)
    {
        bit[idx] += val;
        idx += (idx & (-idx));
    }
}

int query(int idx)
{
    int ans = 0;
    while(idx > 0)
    {
        ans += bit[idx];
        idx -= (idx & (-idx));
    }
    return ans;
}

int main()
{
    scanf("%d", &n);
    int x = 0;
    for(int i = 1 ; i <= (2 * n) ; i++)
    {
        scanf("%d", &a[i]);
        if(!occ[a[i]])
            occ[a[i]] = ++x;
        a[i] = occ[a[i]];
    }
    int inv = 0;
    for(int i = (2 * n) ; i >= 1 ; i--)
    {
        inv += query(a[i] - 1);
        update(a[i], 1);
    }
    printf("%d", inv);
    return 0;
}
 
 
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details