結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー KKT89KKT89
提出日時 2020-07-17 22:02:06
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 1,218 bytes
コンパイル時間 1,827 ms
コンパイル使用メモリ 127,460 KB
実行使用メモリ 9,436 KB
最終ジャッジ日時 2023-08-20 01:11:36
合計ジャッジ時間 4,654 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 74 ms
8,256 KB
testcase_04 AC 90 ms
9,040 KB
testcase_05 AC 73 ms
8,496 KB
testcase_06 AC 65 ms
8,000 KB
testcase_07 AC 90 ms
9,096 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 30 ms
6,644 KB
testcase_10 AC 54 ms
9,300 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 89 ms
9,380 KB
testcase_13 AC 91 ms
9,436 KB
testcase_14 AC 89 ms
9,364 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 6 ms
4,376 KB
testcase_24 AC 25 ms
5,236 KB
testcase_25 AC 60 ms
7,736 KB
testcase_26 AC 13 ms
4,460 KB
testcase_27 AC 35 ms
5,760 KB
testcase_28 AC 47 ms
6,752 KB
testcase_29 AC 63 ms
7,988 KB
testcase_30 AC 79 ms
9,224 KB
testcase_31 AC 18 ms
4,920 KB
testcase_32 AC 12 ms
4,380 KB
testcase_33 AC 69 ms
8,552 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

struct BIT {
  private:
   vector<int> bit;
   int N;
 
  public:
   BIT(int size) {
     N = size;
     bit.resize(N + 1);
   }
 
   // 一点更新です
   void add(int a, int w) {
     for (int x = a; x <= N; x += x & -x) bit[x] += w;
   }
 
   // 1~Nまでの和を求める。
   int sum(int a) {
     int ret = 0;
     for (int x = a; x > 0; x -= x & -x) ret += bit[x];
     return ret;
   }
};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> v(n),a(n),bb(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    map<int,int> mp;
    for(int i=0;i<n;i++){
        cin >> bb[i];
        mp[bb[i]]=i+1;
    }
    for(int i=0;i<n;i++){
        v[i]=mp[a[i]];
    }
    BIT b(n);
    ll res=0;
    for(int i=0;i<n;i++){
        res+=i-b.sum(v[i]);
        b.add(v[i],1);
    }
    cout << res << endl;
}
0