結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー 👑 kmjpkmjp
提出日時 2020-07-17 23:08:56
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 1,150 bytes
コンパイル時間 1,941 ms
コンパイル使用メモリ 199,092 KB
実行使用メモリ 6,900 KB
最終ジャッジ日時 2023-08-20 03:12:22
合計ジャッジ時間 3,983 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,524 KB
testcase_01 AC 2 ms
5,512 KB
testcase_02 AC 2 ms
5,452 KB
testcase_03 AC 21 ms
6,440 KB
testcase_04 AC 23 ms
6,584 KB
testcase_05 AC 21 ms
6,436 KB
testcase_06 AC 19 ms
6,344 KB
testcase_07 AC 24 ms
6,888 KB
testcase_08 AC 3 ms
5,740 KB
testcase_09 AC 15 ms
6,156 KB
testcase_10 AC 23 ms
6,900 KB
testcase_11 AC 2 ms
5,460 KB
testcase_12 AC 24 ms
6,592 KB
testcase_13 AC 24 ms
6,588 KB
testcase_14 AC 24 ms
6,708 KB
testcase_15 AC 2 ms
5,552 KB
testcase_16 AC 2 ms
5,492 KB
testcase_17 AC 2 ms
5,456 KB
testcase_18 AC 2 ms
5,560 KB
testcase_19 AC 2 ms
5,624 KB
testcase_20 AC 2 ms
5,432 KB
testcase_21 AC 2 ms
5,456 KB
testcase_22 AC 2 ms
5,432 KB
testcase_23 AC 4 ms
5,656 KB
testcase_24 AC 10 ms
6,024 KB
testcase_25 AC 18 ms
6,348 KB
testcase_26 AC 6 ms
5,636 KB
testcase_27 AC 12 ms
5,992 KB
testcase_28 AC 15 ms
6,208 KB
testcase_29 AC 19 ms
6,632 KB
testcase_30 AC 23 ms
6,556 KB
testcase_31 AC 8 ms
5,768 KB
testcase_32 AC 5 ms
5,724 KB
testcase_33 AC 21 ms
6,648 KB
testcase_34 AC 2 ms
5,556 KB
testcase_35 AC 2 ms
5,428 KB
testcase_36 AC 2 ms
5,492 KB
testcase_37 AC 2 ms
5,516 KB
testcase_38 AC 2 ms
5,640 KB
testcase_39 AC 2 ms
5,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int A[101010],B[101010];

template<class V, int ME> class BIT {
public:
	V bit[1<<ME];
	V operator()(int e) {if(e<0) return 0;V s=0;e++;while(e) s+=bit[e-1],e-=e&-e; return s;}
	void add(int e,V v) { e++; while(e<=1<<ME) bit[e-1]+=v,e+=e&-e;}
};
BIT<int,20> bt;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>A[i];
	FOR(i,N) {
		cin>>x;
		B[x]=i;
	}
	ll ret=0;
	FOR(i,N) {
		x=B[A[i]];
		ret+=bt(N)-bt(x);
		bt.add(x,1);
	}
	cout<<ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0