Submission #14440

# Submission time Handle Problem Language Result Execution time Memory
14440 2015-05-16T13:53:37 Z ansol4328 공장 (KOI13_factory) C++
9.4 / 20
315 ms 16708 KB
#include<stdio.h>
#include<algorithm>

struct A
{
    int x, num;
};

int n, IT[2000002], check[1000002], sum;
A m[500002];

int cmp(const A &a, const A &b)
{
    return a.x<b.x;
}

void input()
{
    int i, a;
    scanf("%d",&n);
    for(i=1 ; i<=n ; i++)
    {
        scanf("%d",&a);
        check[a]=i;
    }
    for(i=1 ; i<=n ; i++)
    {
        scanf("%d",&a);
        m[i].x=check[a];
        m[i].num=i;
    }
    std::sort(m+1,m+1+n,cmp);
}

void insert(int p)
{
    while(p!=0)
    {
        IT[p]++;
        p/=2;
    }
}

int find(int from, int to)
{
    int s=0;
    while(from<to)
    {
        if(from%2==1)
        {
            s+=IT[from];
            from++;
        }
        if(to%2==0)
        {
            s+=IT[to];
            to--;
        }
        from/=2, to/=2;
    }
    if(from==to) s+=IT[from];
    return s;
}
void process()
{
    int i, k=1;
    while(k<n) k*=2;
    k--;
    for(i=1 ; i<=n ; i++)
    {
        insert(k+m[i].num);
        sum+=find(k+m[i].num+1,k+n);
    }
}

void output()
{
    printf("%d",sum);
}

int main()
{
    input();
    process();
    output();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 16708 KB Output is correct
2 Correct 0 ms 16708 KB Output is correct
3 Correct 0 ms 16708 KB Output is correct
4 Correct 0 ms 16708 KB Output is correct
5 Correct 0 ms 16708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 16708 KB Output is correct
2 Correct 0 ms 16708 KB Output is correct
3 Correct 3 ms 16708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 16708 KB Output is correct
2 Correct 28 ms 16708 KB Output is correct
3 Correct 43 ms 16708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 74 ms 16708 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 315 ms 16708 KB Output isn't correct
2 Halted 0 ms 0 KB -