# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
59993 | baekjoon | 공장 (KOI13_factory) | C++14 | 500 ms | 8428 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int l;
void update(vector<int> &a, int i, int diff) {
while (i <= l) {
a[i] += diff;
i += (i & -i);
}
}
int sum(vector<int> &a, int i) {
int ans = 0;
while (i > 0) {
ans += a[i];
i -= (i & -i);
}
return ans;
}
int sum(vector<int> &a, int l, int r) {
if (l > r) return 0;
return sum(a, r) - sum(a, l-1);
}
int d[1000001];
int main() {
int n;
scanf("%d",&n);
vector<int> a(n);
for (int i=0; i<n; i++) {
scanf("%d",&a[i]);
}
for (int i=0; i<n; i++) {
int num;
scanf("%d",&num);
d[num] = i+1;
}
long long ans = 0;
vector<int> tree(n+1);
l = n;
for (int i=0; i<n; i++) {
ans += (long long)sum(tree, d[a[i]]+1, n);
update(tree, d[a[i]], 1);
}
printf("%lld\n",ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |