답안 #7587

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
7587 2014-08-11T13:31:45 Z jihoon 공장 (KOI13_factory) C++
20 / 20
256 ms 12996 KB
#include<cstdio>
int n;
int bit[1048577];
int num[1000001];
int idx[1000001];

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

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

int main(){
    int i,ia;
    long long int dap=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&ia);
        num[ia]=i+1;
    }
    for(i=0;i<n;i++){
        scanf("%d",&ia);
        dap+=i-sum(num[ia]);
        update(num[ia]);
    }
    printf("%lld",dap);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 12996 KB Output is correct
2 Correct 0 ms 12996 KB Output is correct
3 Correct 0 ms 12996 KB Output is correct
4 Correct 0 ms 12996 KB Output is correct
5 Correct 0 ms 12996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 12996 KB Output is correct
2 Correct 0 ms 12996 KB Output is correct
3 Correct 4 ms 12996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 12996 KB Output is correct
2 Correct 20 ms 12996 KB Output is correct
3 Correct 28 ms 12996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 12996 KB Output is correct
2 Correct 76 ms 12996 KB Output is correct
3 Correct 96 ms 12996 KB Output is correct
4 Correct 144 ms 12996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 180 ms 12996 KB Output is correct
2 Correct 212 ms 12996 KB Output is correct
3 Correct 208 ms 12996 KB Output is correct
4 Correct 252 ms 12996 KB Output is correct
5 Correct 256 ms 12996 KB Output is correct
6 Correct 252 ms 12996 KB Output is correct