結果

問題 No.1209 XOR Into You
ユーザー RhoRho
提出日時 2020-07-29 01:57:41
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 361 ms / 2,000 ms
コード長 1,224 bytes
コンパイル時間 2,662 ms
コンパイル使用メモリ 181,400 KB
実行使用メモリ 80,576 KB
最終ジャッジ日時 2023-09-11 06:58:47
合計ジャッジ時間 17,301 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
70,984 KB
testcase_01 AC 61 ms
70,940 KB
testcase_02 AC 60 ms
71,252 KB
testcase_03 AC 61 ms
70,908 KB
testcase_04 AC 136 ms
72,092 KB
testcase_05 AC 136 ms
72,144 KB
testcase_06 AC 153 ms
74,960 KB
testcase_07 AC 278 ms
78,832 KB
testcase_08 AC 246 ms
77,940 KB
testcase_09 AC 248 ms
78,012 KB
testcase_10 AC 205 ms
76,472 KB
testcase_11 AC 244 ms
77,980 KB
testcase_12 AC 231 ms
77,328 KB
testcase_13 AC 262 ms
78,436 KB
testcase_14 AC 222 ms
77,152 KB
testcase_15 AC 234 ms
77,588 KB
testcase_16 AC 234 ms
77,400 KB
testcase_17 AC 228 ms
77,084 KB
testcase_18 AC 326 ms
80,012 KB
testcase_19 AC 240 ms
77,244 KB
testcase_20 AC 269 ms
78,432 KB
testcase_21 AC 204 ms
76,332 KB
testcase_22 AC 229 ms
80,404 KB
testcase_23 AC 229 ms
80,568 KB
testcase_24 AC 230 ms
80,416 KB
testcase_25 AC 339 ms
80,356 KB
testcase_26 AC 342 ms
80,428 KB
testcase_27 AC 332 ms
80,216 KB
testcase_28 AC 336 ms
80,576 KB
testcase_29 AC 341 ms
80,296 KB
testcase_30 AC 361 ms
80,344 KB
testcase_31 AC 190 ms
75,160 KB
testcase_32 AC 190 ms
75,072 KB
testcase_33 AC 189 ms
75,056 KB
testcase_34 AC 195 ms
75,084 KB
testcase_35 AC 189 ms
75,012 KB
testcase_36 AC 190 ms
74,964 KB
testcase_37 AC 158 ms
75,000 KB
testcase_38 AC 261 ms
78,676 KB
testcase_39 AC 235 ms
77,628 KB
testcase_40 AC 233 ms
80,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define vi vector<int>
#define all(a) a.begin(),a.end()
typedef pair<int,int> P;
const long long mod=998244353;
const long long inf=1ll<<61;

int BIT[100006];
int a[100006],b[100006];
void add(int i,int x){
  while(i<=100002){
    BIT[i]+=x;
    i+=i&-i;
  }
}
int sum(int i){
  int s=0;
  while(i>0){
    s+=BIT[i];
    i-=i&-i;
  }
  return s;
}

bool eq(vi a,vi b){
  sort(all(a));
  sort(all(b));
  return a==b;
}

deque<int>Q[100006];
signed main(){
  int n;cin>>n;
  rep(i,n)cin>>a[i];
  rep(i,n)cin>>b[i];
  if(a[0]!=b[0]||a[n-1]!=b[n-1]){
    cout<<-1<<endl;
    return 0;
  }
  vector<int>na,nb;
  rep(i,n-1){
    na.push_back(a[i]^a[i+1]);
    nb.push_back(b[i]^b[i+1]);
  }
  if(!eq(na,nb)){
    cout<<-1<<endl;
    return 0;
  }
  map<int,int>M;
  n--;
  rep(i,n)M[na[i]]++;
  int cn=0;
  for(auto itr=M.begin();itr!=M.end();itr++){
    M[itr->first]=cn;cn++;
  }
  rep(i,n){
    na[i]=M[na[i]];nb[i]=M[nb[i]];
  }
  rep(i,n){
    Q[na[i]].push_back(i);
    add(i+1,1);
  }
  int ans=0;
  rep(i,n){
    int k=Q[nb[i]].front();Q[nb[i]].pop_front();
    ans+=sum(k);
    add(k+1,-1);
  }
  cout<<ans<<endl;
}
0