結果
問題 | No.1115 二つの数列 / Two Sequences |
ユーザー |
![]() |
提出日時 | 2020-07-17 22:55:26 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 84 ms / 2,000 ms |
コード長 | 943 bytes |
コンパイル時間 | 1,473 ms |
コンパイル使用メモリ | 174,656 KB |
実行使用メモリ | 9,216 KB |
最終ジャッジ日時 | 2024-11-30 02:11:09 |
合計ジャッジ時間 | 3,855 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 35 |
ソースコード
#define _USE_MATH_DEFINES#include <bits/stdc++.h>using namespace std;//template#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)#define ALL(v) (v).begin(),(v).end()typedef long long int ll;const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}//endint bit[200010]={},n;void add(int i,int x){while(i<=n){bit[i]+=x;i+=(i&(-i));}}ll sum(int i){ll s=0;while(i){s+=bit[i];i-=(i&(-i));}return s;}int main(){scanf("%d",&n);vector<int> a(n),b(n);rep(i,0,n)scanf("%d",&a[i]);rep(i,0,n)scanf("%d",&b[i]);map<int,int> pos;rep(i,0,n)pos[b[i]]=i+1;rep(i,0,n)a[i]=pos[a[i]];ll ans=0;rep(i,0,n){ans+=i-sum(a[i]);add(a[i],1);}printf("%lld\n",ans);return 0;}