結果
| 問題 | No.1115 二つの数列 / Two Sequences |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-07-17 22:02:06 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 89 ms / 2,000 ms |
| コード長 | 1,218 bytes |
| コンパイル時間 | 6,211 ms |
| コンパイル使用メモリ | 163,072 KB |
| 最終ジャッジ日時 | 2025-01-11 22:39:58 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 35 |
ソースコード
#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;
}