結果
問題 | No.1115 二つの数列 / Two Sequences |
ユーザー |
|
提出日時 | 2020-07-17 21:55:35 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 62 ms / 2,000 ms |
コード長 | 1,472 bytes |
コンパイル時間 | 1,486 ms |
コンパイル使用メモリ | 168,404 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-29 23:34:34 |
合計ジャッジ時間 | 3,716 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 35 |
ソースコード
#include <bits/stdc++.h>#define rep(i,n) for (int i = 0; i < (n); i ++)using namespace std;using ll = long long;using PL = pair<ll,ll>;using P = pair<int,int>;constexpr int INF = 1000000000;constexpr long long HINF = 1000000000000000;constexpr long long MOD = 1000000007;// = 998244353;constexpr double EPS = 1e-4;constexpr double PI = 3.14159265358979;template<class T> class BinaryIndexedTree {int N;vector<T> bit;public :BinaryIndexedTree(int _N): N(_N),bit(N + 1,0){}void add(int i,T x) {while (i <= N) {bit[i] += x;i += (i & -i);}}T sum(int i) {T ret = 0;while (i > 0) {ret += bit[i];i -= (i & -i);}return ret;}int lower_bound(T x) {if (x <= 0) return 0;int i = 0;int K = 1;while (2*K > N) K <<= 1;for (;K > 0; K >>= 1) {if (i + K <= N && bit[i + K] < x) {x -= bit[i + K];i += K;}}return i + 1;}};int main() {int N; cin >> N;vector<int> A(N),B(N),C(N + 1);rep(i,N) cin >> A[i];rep(i,N) cin >> B[i];rep(i,N) C[B[i]] = i;rep(i,N) A[i] = C[A[i]];BinaryIndexedTree<int> bit(N);ll ans = 0;rep(i,N) {ans += i - bit.sum(A[i] + 1);bit.add(A[i] + 1,1);}cout << ans << '\n';return 0;}