結果
問題 |
No.1115 二つの数列 / Two Sequences
|
ユーザー |
👑 ![]() |
提出日時 | 2020-10-04 08:28:45 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 58 ms / 2,000 ms |
コード長 | 894 bytes |
コンパイル時間 | 1,457 ms |
コンパイル使用メモリ | 168,988 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-19 04:15:34 |
合計ジャッジ時間 | 4,094 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 35 |
ソースコード
#include<bits/stdc++.h> using namespace std; using LL = long long; using ULL = unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) struct BIT { int N; vector<int> V; void init(int n) { N = 1; while (N < n) N *= 2; V.resize(N); } void add(int p, int v) { p++; while (p <= N) { V[p - 1] += v; p += p & -p; } } int sum(int r) { int ans = 0; while (r >= 1) { ans += V[r - 1]; r -= r & -r; } return ans; } }; int N; int A[100000]; int B[100000]; int main() { cin >> N; rep(i, N) { int a; cin >> a; a--; A[a] = i; } rep(i, N) { int b; cin >> b; b--; B[i] = A[b]; } BIT G; G.init(N); LL ans = 0; rep(i, N) { ans += i - G.sum(B[i]); G.add(B[i], 1); } cout << ans << endl; return 0; }