Submission #16238

# Submission time Handle Problem Language Result Execution time Memory
16238 2015-08-18T11:12:46 Z eaststar 공장 (KOI13_factory) C++14
20 / 20
258 ms 6944 KB
#include <cstdio>
int a[1000010],bit[500010];
long long int s;
int getsum(int k){
    int sum=0;
    while(k){
        sum+=bit[k];
        k-=k&-k;
    }
    return sum;
}
void update(int k,int e,int v){
    while(k<=e){
        bit[k]+=v;
        k+=k&-k;
    }
}
int main(){
    int i,n,k;
    scanf("%d",&n);
    for(i=1;i<=n;++i)scanf("%d",&k),a[k]=i;
    for(i=1;i<=n;++i){
        scanf("%d",&k);
        update(a[k],n,1);
        s+=getsum(n)-getsum(a[k]);
    }
    printf("%lld",s);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 6944 KB Output is correct
2 Correct 0 ms 6944 KB Output is correct
3 Correct 0 ms 6944 KB Output is correct
4 Correct 0 ms 6944 KB Output is correct
5 Correct 0 ms 6944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 6944 KB Output is correct
2 Correct 0 ms 6944 KB Output is correct
3 Correct 0 ms 6944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 6944 KB Output is correct
2 Correct 0 ms 6944 KB Output is correct
3 Correct 0 ms 6944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 6944 KB Output is correct
2 Correct 48 ms 6944 KB Output is correct
3 Correct 96 ms 6944 KB Output is correct
4 Correct 136 ms 6944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 181 ms 6944 KB Output is correct
2 Correct 199 ms 6944 KB Output is correct
3 Correct 210 ms 6944 KB Output is correct
4 Correct 147 ms 6944 KB Output is correct
5 Correct 240 ms 6944 KB Output is correct
6 Correct 258 ms 6944 KB Output is correct