Submission #14441

#TimeUsernameProblemLanguageResultExecution timeMemory
14441ansol4328공장 (KOI13_factory)C++98
20 / 20
402 ms16708 KiB
#include<stdio.h> #include<algorithm> struct A { int x, num; }; int n, IT[2000002], check[1000002]; long long 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("%lld",sum); } int main() { input(); process(); output(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...