結果
問題 | No.1209 XOR Into You |
ユーザー | hiroa |
提出日時 | 2021-08-23 21:33:22 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 140 ms / 2,000 ms |
コード長 | 3,586 bytes |
コンパイル時間 | 2,099 ms |
コンパイル使用メモリ | 179,548 KB |
実行使用メモリ | 7,808 KB |
最終ジャッジ日時 | 2024-11-08 00:54:29 |
合計ジャッジ時間 | 7,846 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 84 ms
5,504 KB |
testcase_05 | AC | 84 ms
5,632 KB |
testcase_06 | AC | 100 ms
5,632 KB |
testcase_07 | AC | 109 ms
7,168 KB |
testcase_08 | AC | 100 ms
7,168 KB |
testcase_09 | AC | 100 ms
7,040 KB |
testcase_10 | AC | 81 ms
5,760 KB |
testcase_11 | AC | 97 ms
7,168 KB |
testcase_12 | AC | 91 ms
6,784 KB |
testcase_13 | AC | 105 ms
7,168 KB |
testcase_14 | AC | 89 ms
6,656 KB |
testcase_15 | AC | 94 ms
6,912 KB |
testcase_16 | AC | 93 ms
6,912 KB |
testcase_17 | AC | 89 ms
6,912 KB |
testcase_18 | AC | 127 ms
7,552 KB |
testcase_19 | AC | 92 ms
6,912 KB |
testcase_20 | AC | 104 ms
7,168 KB |
testcase_21 | AC | 80 ms
5,632 KB |
testcase_22 | AC | 109 ms
7,680 KB |
testcase_23 | AC | 110 ms
7,808 KB |
testcase_24 | AC | 110 ms
7,552 KB |
testcase_25 | AC | 127 ms
7,552 KB |
testcase_26 | AC | 127 ms
7,680 KB |
testcase_27 | AC | 126 ms
7,680 KB |
testcase_28 | AC | 129 ms
7,552 KB |
testcase_29 | AC | 128 ms
7,680 KB |
testcase_30 | AC | 127 ms
7,808 KB |
testcase_31 | AC | 132 ms
7,552 KB |
testcase_32 | AC | 134 ms
7,680 KB |
testcase_33 | AC | 135 ms
7,680 KB |
testcase_34 | AC | 140 ms
7,680 KB |
testcase_35 | AC | 134 ms
7,680 KB |
testcase_36 | AC | 134 ms
7,680 KB |
testcase_37 | AC | 115 ms
7,680 KB |
testcase_38 | AC | 106 ms
7,168 KB |
testcase_39 | AC | 96 ms
7,040 KB |
testcase_40 | AC | 108 ms
7,552 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int MOD=1000000007; #define INF 1LL<<30 #define rep(i,n) for (int i = 0; i < (n); ++i) #define all(x) (x).begin(),(x).end() template < class Monoid > struct SegmentTree { private: using Func = std::function< Monoid(Monoid, Monoid) >; Func F; Monoid UNITY; int n; std::vector< Monoid > node; public: SegmentTree() {} SegmentTree(const std::vector< Monoid > &v, const Func f, const Monoid &unity) { F = f; UNITY = unity; int sz = v.size(); n = 1; while (n < sz) n <<= 1; node.resize(n * 2 - 1, UNITY); for (int i = 0; i < sz; i++) node[i + n - 1] = v[i]; build(); } SegmentTree(int m, const Monoid &val, const Func f, const Monoid &unity) { F = f; UNITY = unity; n = 1; while (n < m) n <<= 1; node.resize(n * 2 - 1, UNITY); if (val != UNITY) { for (int i = 0; i < m; i++) node[i] = val; build(); } } void set(int k, const Monoid &x) { node[n + k - 1] = x; } void build() { for (int i = n - 2; i >= 0; i--) node[i] = F(node[2 * i + 1], node[2 * i + 2]); } void update_query(int x, const Monoid &val) { if (x >= n || x < 0) return; x += n - 1; node[x] = val; while (x > 0) { x = (x - 1) >> 1; node[x] = F(node[2 * x + 1], node[2 * x + 2]); } } /* Monoid query(int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; if (r <= a || b <= l) return UNITY; if (a <= l && r <= b) return node[k]; Monoid vl = query(a, b, 2 * k + 1, l, (r - l) / 2 + l); Monoid vr = query(a, b, 2 * k + 2, (r - l) / 2 + l, r); return F(vl, vr); } */ Monoid get_query(int a, int b) { Monoid L = UNITY, R = UNITY; if (a < 0) a = 0; if (b < 0) return UNITY; if (a >= n) return UNITY; if (b >= n) b = n; for (a += n, b += n; a < b; a >>= 1, b >>= 1) { if (a & 1) L = F(L, node[a++ - 1]); if (b & 1) R = F(node[--b - 1], R); } return F(L, R); } Monoid operator[](int x) const { return node[n + x - 1]; } int size() { return n; } void print() { for (int i = 0; i < n; i++) { std::cout << i << "\t: " << node[n + i - 1] << std::endl; } } }; int main() { int n;cin >> n; vector<int> _a(n),_b(n); vector<pair<int,int>> a(n),b(n); for (int i = 0; i < n; i++) { cin >> _a[i]; if (i > 0) { a[i].first = _a[i-1] ^ _a[i]; a[i].second = i; } } for (int i = 0; i < n; i++) { cin >> _b[i]; if (i > 0) { b[i].first = _b[i-1] ^ _b[i]; b[i].second = i; } } if (_a[0] != _b[0] || _a[n-1] != _b[n-1]) { puts("-1"); return 0; } sort(a.begin(), a.end()); sort(b.begin(), b.end()); for (int i = 0; i < n; i++) { if (a[i].first != b[i].first) { puts("-1"); return 0; } a[i].first = a[i].second; a[i].second = b[i].second; } sort(a.begin(), a.end()); SegmentTree<ll> seg(n,0,[](int a, int b){return a+b;},0); ll ans = 0; for (int i = 0; i < n; i++) { ans += seg.get_query(a[i].second,n); seg.update_query(a[i].second,1); } cout << ans << endl; return 0; }