結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2020-07-18 08:39:13
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 98 ms / 2,000 ms
コード長 3,029 bytes
コンパイル時間 2,406 ms
コンパイル使用メモリ 213,264 KB
実行使用メモリ 10,956 KB
最終ジャッジ日時 2023-08-20 17:00:14
合計ジャッジ時間 5,093 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 79 ms
10,000 KB
testcase_04 AC 91 ms
10,712 KB
testcase_05 AC 78 ms
9,976 KB
testcase_06 AC 72 ms
9,616 KB
testcase_07 AC 98 ms
10,704 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 33 ms
7,464 KB
testcase_10 AC 61 ms
10,836 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 95 ms
10,880 KB
testcase_13 AC 94 ms
10,956 KB
testcase_14 AC 93 ms
10,776 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 7 ms
4,376 KB
testcase_24 AC 29 ms
5,924 KB
testcase_25 AC 66 ms
9,284 KB
testcase_26 AC 14 ms
4,604 KB
testcase_27 AC 37 ms
6,776 KB
testcase_28 AC 51 ms
7,616 KB
testcase_29 AC 70 ms
9,512 KB
testcase_30 AC 86 ms
10,472 KB
testcase_31 AC 19 ms
4,868 KB
testcase_32 AC 13 ms
4,376 KB
testcase_33 AC 67 ms
10,056 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
template<class V> struct BIT { BIT() {}  // [L, R)
    int NV;vector<V> bit;BIT(int n){init(n);}void init(int n){NV=1;while(NV<n)NV*=2;bit.resize(NV);}
    V operator[](int e) { V s = 0; e++; while (e) s += bit[e - 1], e -= e&-e; return s; }
    void add(int e, V v) { e++; while (e <= NV) bit[e - 1] += v, e += e&-e; }
    int lower_bound(V val) { V tv = 0; int i, ent = 0; for (i = NV - 1; i >= 0; i--)
        if(tv+bit[ent+(1<<i)-1]<=val)tv+=bit[ent+(1<<i)-1],ent += (1 << i);return ent;}
    V get(int L, int R) {assert(0 <= L); assert(R <= NV); assert(L <= R);
        V res = 0; if(R) res += operator[](R - 1); if (L) res -= operator[](L - 1);return res;}
    void clear() { bit.clear(); }};
ll BubbleSortCount(vector<int> &v) {
    int n = v.size();

    vector<int> dic;
    fore(i, v) dic.push_back(i);
    sort(dic.begin(), dic.end());
    dic.erase(unique(dic.begin(), dic.end()), dic.end());

    vector<int> w;
    fore(i, v) w.push_back(lower_bound(dic.begin(), dic.end(), i) - dic.begin());

    ll res = 0;
    BIT<ll> bit(n + 10);
    fore(i, w) bit.add(i, 1);
    fore(i, w) {
        res += bit.get(0, i);
        bit.add(i, -1);
    }
    return res;
}
ll BubbleSortCount(int* start, int* end) {
    vector<int> v;
    for (int* ite = start; ite != end; ite++) v.push_back(*ite);
    return BubbleSortCount(v);
}
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int N, A[101010], B[101010];
map<int, int> cov;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	rep(i, 0, N) cin >> A[i];
	rep(i, 0, N) cin >> B[i];

	rep(i, 0, N) cov[B[i]] = i;
	rep(i, 0, N) A[i] = cov[A[i]];

    ll ans = BubbleSortCount(A, A + N);
    cout << ans << endl;
}





0