結果

問題 No.1209 XOR Into You
ユーザー ゆきのんゆきのん
提出日時 2020-08-30 22:47:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,074 bytes
コンパイル時間 1,843 ms
コンパイル使用メモリ 186,496 KB
実行使用メモリ 32,768 KB
最終ジャッジ日時 2024-04-27 13:33:57
合計ジャッジ時間 11,683 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 207 ms
27,136 KB
testcase_05 WA -
testcase_06 AC 199 ms
27,136 KB
testcase_07 AC 258 ms
27,776 KB
testcase_08 AC 224 ms
25,216 KB
testcase_09 AC 217 ms
25,344 KB
testcase_10 AC 171 ms
21,376 KB
testcase_11 AC 216 ms
24,960 KB
testcase_12 AC 206 ms
23,424 KB
testcase_13 AC 244 ms
26,240 KB
testcase_14 AC 202 ms
22,912 KB
testcase_15 AC 210 ms
23,936 KB
testcase_16 AC 209 ms
23,552 KB
testcase_17 AC 194 ms
22,656 KB
testcase_18 AC 316 ms
31,360 KB
testcase_19 AC 207 ms
23,680 KB
testcase_20 AC 238 ms
26,496 KB
testcase_21 AC 178 ms
20,864 KB
testcase_22 AC 217 ms
32,512 KB
testcase_23 AC 203 ms
32,640 KB
testcase_24 AC 205 ms
32,768 KB
testcase_25 AC 325 ms
32,640 KB
testcase_26 AC 320 ms
32,512 KB
testcase_27 AC 317 ms
32,640 KB
testcase_28 AC 310 ms
32,640 KB
testcase_29 AC 309 ms
32,512 KB
testcase_30 AC 312 ms
32,640 KB
testcase_31 AC 118 ms
7,296 KB
testcase_32 AC 118 ms
7,296 KB
testcase_33 AC 118 ms
7,424 KB
testcase_34 AC 126 ms
7,424 KB
testcase_35 AC 123 ms
7,424 KB
testcase_36 AC 122 ms
7,424 KB
testcase_37 AC 85 ms
6,944 KB
testcase_38 AC 241 ms
27,648 KB
testcase_39 AC 214 ms
24,704 KB
testcase_40 AC 205 ms
32,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};

template< typename T >
struct BinaryIndexedTree{

    //0-indexed
    vector< T > bit;

    BinaryIndexedTree(int sz){
        bit.assign(sz, 0);
    }

    //[0,k)までの総和を返す
    T sum(int k){
        T ret = 0;
        for (--k; k >= 0; k = (k&(k+1))-1) ret += bit[k];
        return ret;
    }
    
    //[l,r)の総和を返す
    T sum(int l, int r){
        return sum(r) - sum(l);
    }

    //kにx加算する
    void add(int k, T x){
        for (; k < bit.size(); k |= k+1) bit[k] += x;
    }
};
 
int main(){
    int n;cin >> n;
    vector<int> a(n),b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    vector<int> av(n-1), bv(n-1);
    map<int,vector<int> > ma,mb;
    for (int i = 0; i < n-1; i++) {
        av[i] = a[i] ^ a[i+1];
        ma[av[i]].pb(i);
        bv[i] = b[i] ^ b[i+1];
        mb[bv[i]].pb(i);
    }
    auto tav = av;
    sort(ALL(tav));
    for(auto A:ma){
        if(A.sc.size() != mb[A.fs].size()){
            puts("-1");
            return 0;
        }
    }
    vector<int> map_av(n - 1);
    map<int,int> m_id;
    for (int i = 0; i < n-1; i++) {
        map_av[i] = mb[av[i]][m_id[av[i]]++];
    }
    BinaryIndexedTree<int> bit(n);
    LL ans = 0;
    for (int i = 0; i < n-1; i++) {
        ans += bit.sum(map_av[i], n);
        bit.add(map_av[i], 1);
    }
    cout << ans << endl;
    return 0;
}
0