# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
82845 | leejseo | 공장 (KOI13_factory) | C++11 | 256 ms | 62484 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 <bits/stdc++.h>
using namespace std;
typedef long long lld;
typedef struct BIT{
lld tree[524288];
const int MAXN = 524288;
lld sum(int i){
lld ans = 0;
while (i > 0){
ans += tree[i];
i -= (i & -i);
}
return ans;
}
void update(int i, lld diff){
while (i < MAXN){
tree[i] += diff;
i += (i & -i);
}
}
} BIT;
int N, I[1000001];
vector<int> L;
BIT tree;
void input(){
scanf("%d", &N);
for (int i=1; i<=N; i++){
int temp;
scanf("%d", &temp);
I[temp] = i;
}
L.push_back(-1);
for (int i=1; i<=N; i++){
int temp;
scanf("%d", &temp);
L.push_back(I[temp]);
}
}
lld solve(){
lld ans = 0;
for (int i=1; i<=N; i++){
ans += i - tree.sum(L[i]) - 1;
tree.update(L[i], 1);
}
return ans;
}
int main(void){
input();
printf("%lld\n", solve());
}
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... |