Submission #10074

#TimeUsernameProblemLanguageResultExecution timeMemory
10074gs14004공장 (KOI13_factory)C++98
20 / 20
228 ms9016 KiB
#include <cstdio> int n, mp[1000005], t; int c[500005]; struct f{ int tree[530000], lim; void init(int n){ for (lim = 1; lim <= n+1; lim <<= 1); } void add(int x){ x++; while(x <= lim){ tree[x]++; x += x & -x; } } int sum(int x){ x++; int res = 0; while(x){ res += tree[x]; x -= x & -x; } return res; } }bit; int main(){ scanf("%d",&n); for (int i=0; i<n; i++) { scanf("%d",&t); mp[t] = i; } for (int i=0; i<n; i++) { scanf("%d",&t); c[mp[t]] = i; } bit.init(n); long long res = 0; for (int i=0; i<n; i++) { res += i - bit.sum(c[i]); bit.add(c[i]); } printf("%lld",res); }
#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...