結果
| 問題 |
No.1115 二つの数列 / Two Sequences
|
| コンテスト | |
| ユーザー |
はまやんはまやん
|
| 提出日時 | 2020-07-18 08:39:13 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 116 ms / 2,000 ms |
| コード長 | 3,029 bytes |
| コンパイル時間 | 2,439 ms |
| コンパイル使用メモリ | 209,472 KB |
| 最終ジャッジ日時 | 2025-01-12 00:09:14 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 35 |
ソースコード
#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;
}
はまやんはまやん