結果
問題 | No.1115 二つの数列 / Two Sequences |
ユーザー |
![]() |
提出日時 | 2020-07-17 21:29:31 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 62 ms / 2,000 ms |
コード長 | 723 bytes |
コンパイル時間 | 1,631 ms |
コンパイル使用メモリ | 168,116 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-29 21:32:32 |
合計ジャッジ時間 | 3,642 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 35 |
ソースコード
#include <bits/stdc++.h>using namespace std;long long inversion_number(vector<int> &p){int N = p.size();long long ans = 0;vector<int> bit(N + 1, 0);for (int i = 0; i < N; i++){ans += i;int j = p[i];while (j > 0){ans -= bit[j];j -= j & -j;}j = p[i];while (j <= N){bit[j]++;j += j & -j;}}return ans;}int main(){int n;cin >> n;vector<int> a(n);for (int i = 0; i < n; i++){cin >> a[i];a[i]--;}vector<int> b(n);for (int i = 0; i < n; i++){cin >> b[i];b[i]--;}vector<int> A(n);for (int i = 0; i < n; i++){A[a[i]] = i;}for (int i = 0; i < n; i++){b[i] = A[b[i]] + 1;}cout << inversion_number(b) << endl;}