結果

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

ソースコード

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

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
template <typename T>
struct bit{
int n;
vector<T> data;
bit(int n_){
n = 1;
while(n < n_) n *= 2;
data = vector<T>(n+1);
for(int i = 0; i <= n; i++) data[i] = 0;
}
T sum(int i){
T ret = 0;
while(i > 0){
ret += data[i];
i -= i&-i;
}
return ret;
}
void add(int i, T x){
while(i <= n){
data[i] += x;
i += i&-i;
}
}
};
int idx[100001];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
int n; cin >> n;
for(int i = 0; i < n; i++){
int a; cin >> a;
idx[a] = i+1;
}
bit<ll> bt(n);
ll ans = 0;
for(int i = 0; i < n; i++){
int b; cin >> b;
ans += i-bt.sum(idx[b]);
bt.add(idx[b], 1);
}
cout << ans << endl;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0