結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー cn_449
提出日時 2020-07-17 21:33:59
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 2,290 bytes
コンパイル時間 1,279 ms
コンパイル使用メモリ 116,456 KB
実行使用メモリ 6,912 KB
最終ジャッジ日時 2024-11-29 22:00:57
合計ジャッジ時間 3,105 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << #x << ':' << x << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }
template<class T> class segtree {
int n;
vector<T> data;
T id = 0;
T operation(T a, T b) { return a + b; };
public:
segtree(int _n) {
n = 1;
while (n < _n + 2) n <<= 1;
data = vector<T>(2 * n, id);
}
void change(int i, T x) {
i += n;
data[i] = x;
while (i > 1) {
i >>= 1;
data[i] = operation(data[i << 1], data[i << 1 | 1]);
}
}
void add(int i, T x) { change(i, data[i + n] + x); }
T get(int a, int b) {
T left = id; T right = id;
a += n; b += n;
while (a < b) {
if (a & 1) left = operation(left, data[a++]);
if (b & 1) right = operation(data[--b], right);
a >>= 1; b >>= 1;
}
return operation(left, right);
}
T get_all() { return data[1]; }
T operator[](int i) { return data[i + n]; }
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
int n;
cin >> n;
vector<int> a(n), b(n), ainv(n), p(n);
rep(i, n) {
cin >> a[i];
a[i]--;
ainv[a[i]] = i;
}
rep(i, n) cin >> b[i], b[i]--;
rep(i, n) p[i] = ainv[b[i]];
segtree<ll> seg(n);
ll ans = 0;
rep(i, n) {
ans += seg.get(p[i] + 1, n + 1);
seg.add(p[i], 1);
}
cout << ans << '\n';
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0