結果

問題 No.1209 XOR Into You
ユーザー chocoruskchocorusk
提出日時 2020-08-30 22:13:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 307 ms / 2,000 ms
コード長 1,818 bytes
コンパイル時間 1,604 ms
コンパイル使用メモリ 144,564 KB
実行使用メモリ 22,144 KB
最終ジャッジ日時 2024-04-27 13:31:34
合計ジャッジ時間 10,436 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 83 ms
6,944 KB
testcase_05 AC 82 ms
6,948 KB
testcase_06 AC 98 ms
6,944 KB
testcase_07 AC 233 ms
18,944 KB
testcase_08 AC 203 ms
17,824 KB
testcase_09 AC 209 ms
17,408 KB
testcase_10 AC 169 ms
14,876 KB
testcase_11 AC 204 ms
17,280 KB
testcase_12 AC 187 ms
16,384 KB
testcase_13 AC 224 ms
18,048 KB
testcase_14 AC 176 ms
15,988 KB
testcase_15 AC 194 ms
16,568 KB
testcase_16 AC 189 ms
16,336 KB
testcase_17 AC 175 ms
15,896 KB
testcase_18 AC 291 ms
21,256 KB
testcase_19 AC 185 ms
16,340 KB
testcase_20 AC 229 ms
18,304 KB
testcase_21 AC 163 ms
14,720 KB
testcase_22 AC 173 ms
22,016 KB
testcase_23 AC 173 ms
22,040 KB
testcase_24 AC 176 ms
22,144 KB
testcase_25 AC 283 ms
21,940 KB
testcase_26 AC 300 ms
22,016 KB
testcase_27 AC 284 ms
22,052 KB
testcase_28 AC 293 ms
22,144 KB
testcase_29 AC 307 ms
22,144 KB
testcase_30 AC 307 ms
22,144 KB
testcase_31 AC 135 ms
7,040 KB
testcase_32 AC 134 ms
7,040 KB
testcase_33 AC 134 ms
7,168 KB
testcase_34 AC 139 ms
7,084 KB
testcase_35 AC 134 ms
7,168 KB
testcase_36 AC 133 ms
7,168 KB
testcase_37 AC 94 ms
6,940 KB
testcase_38 AC 232 ms
18,816 KB
testcase_39 AC 201 ms
17,152 KB
testcase_40 AC 173 ms
22,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<typename T>
struct BIT{
    vector<T> bit;
    int size;
    BIT(int n):size(n), bit(n+1, 0){}
    T sum(int i){ //[0, i)
        T s=0;
        while(i>0){
            s+=bit[i];
            i-=(i&(-i));
        }
        return s;
    }
    T sum(int l, int r){ //[l, r)
        return sum(r)-sum(l);
    }
    void add(int i, T x){
        i++;
        while(i<=size){
            bit[i]+=x;
            i+=(i&(-i));
        }
    }
};
int main()
{
	int n; cin>>n;
	int a[100010], b[100010];
	int a1[100010], b1[100010];
	int a2[100010], b2[100010];
	for(int i=0; i<n; i++) cin>>a[i];
	for(int i=0; i<n; i++) cin>>b[i];
	if(a[0]!=b[0]){
		cout<<-1<<endl;
		return 0;
	}
	for(int i=0; i<n-1; i++){
		a1[i]=(a[i]^a[i+1]);
		b1[i]=(b[i]^b[i+1]);
		a2[i]=a1[i], b2[i]=b1[i];
	}
	sort(a2, a2+n-1); sort(b2, b2+n-1);
	for(int i=0; i<n-1; i++){
		if(a2[i]!=b2[i]){
			cout<<-1<<endl;
			return 0;
		}
	}
	map<int, vector<int>> mp;
	for(int i=0; i<n-1; i++) mp[a1[i]].push_back(i);
	map<int, int> cnt;
	int x[100010];
	for(int i=0; i<n-1; i++){
		x[i]=mp[b1[i]][cnt[b1[i]]];
		cnt[b1[i]]++;
	}
	ll ans=0;
	BIT<int> bit(n-1);
	for(int i=0; i<n-1; i++){
		ans+=bit.sum(x[i]+1, n-1);
		bit.add(x[i], 1);
	}
	cout<<ans<<endl;
	return 0;
}
0