結果
問題 | No.1209 XOR Into You |
ユーザー | ir5 |
提出日時 | 2024-06-17 22:23:28 |
言語 | C++23(gcc13) (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 381 ms / 2,000 ms |
コード長 | 2,797 bytes |
コンパイル時間 | 2,271 ms |
コンパイル使用メモリ | 155,896 KB |
実行使用メモリ | 17,408 KB |
最終ジャッジ日時 | 2024-06-17 22:23:44 |
合計ジャッジ時間 | 15,557 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 85 ms
5,376 KB |
testcase_05 | AC | 85 ms
5,376 KB |
testcase_06 | AC | 208 ms
15,744 KB |
testcase_07 | AC | 281 ms
15,104 KB |
testcase_08 | AC | 248 ms
13,824 KB |
testcase_09 | AC | 279 ms
13,824 KB |
testcase_10 | AC | 189 ms
12,032 KB |
testcase_11 | AC | 245 ms
13,696 KB |
testcase_12 | AC | 225 ms
12,928 KB |
testcase_13 | AC | 270 ms
14,464 KB |
testcase_14 | AC | 227 ms
12,672 KB |
testcase_15 | AC | 220 ms
13,184 KB |
testcase_16 | AC | 223 ms
13,056 KB |
testcase_17 | AC | 205 ms
12,544 KB |
testcase_18 | AC | 381 ms
16,768 KB |
testcase_19 | AC | 221 ms
13,184 KB |
testcase_20 | AC | 279 ms
14,464 KB |
testcase_21 | AC | 179 ms
11,776 KB |
testcase_22 | AC | 210 ms
17,280 KB |
testcase_23 | AC | 232 ms
17,408 KB |
testcase_24 | AC | 210 ms
17,280 KB |
testcase_25 | AC | 352 ms
17,408 KB |
testcase_26 | AC | 354 ms
17,408 KB |
testcase_27 | AC | 372 ms
17,408 KB |
testcase_28 | AC | 357 ms
17,408 KB |
testcase_29 | AC | 354 ms
17,408 KB |
testcase_30 | AC | 376 ms
17,280 KB |
testcase_31 | AC | 212 ms
12,800 KB |
testcase_32 | AC | 208 ms
12,672 KB |
testcase_33 | AC | 212 ms
12,672 KB |
testcase_34 | AC | 213 ms
12,800 KB |
testcase_35 | AC | 211 ms
12,672 KB |
testcase_36 | AC | 209 ms
12,672 KB |
testcase_37 | AC | 150 ms
12,544 KB |
testcase_38 | AC | 275 ms
14,976 KB |
testcase_39 | AC | 237 ms
13,568 KB |
testcase_40 | AC | 215 ms
17,280 KB |
ソースコード
#include <algorithm> #include <cassert> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <iostream> #include <numeric> #include <vector> #include <map> #include <set> #include <queue> #include <functional> #include <iomanip> using namespace std; using ll = long long; class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n; public:range(int n_):i({0}),n({n_}){}range(int i_,int n_):i({i_}),n({n_}){}I& begin(){return i;}I& end(){return n;}}; template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; } template<typename T> ostream& operator<<(ostream& os, const vector<T>& obj) { os << "{"; for (const auto& e : obj) os << e << ", "; return os << "}"; } template<typename T> ostream& operator<<(ostream& os, const set<T>& obj) { os << "set{"; for (const auto& e : obj) os << e << ", "; return os << "}"; } template<typename T, typename U> ostream& operator<<(ostream& os, const map<T, U>& obj) { os << "map{"; for (const auto& e : obj) os << e << ", "; return os << "}"; } #ifdef ONLINE_JUDGE #define dump(expr) ; #else #define dump(expr) { cerr << "\033[33m#L" << __LINE__ << ": " << expr << "\033[39m" << endl; } #endif template<typename T> struct BinaryIndexedTree { int size; vector<T> ft; BinaryIndexedTree(int size_) : size(size_), ft(size, (T)0) {} void add(int i, T value) { // val[i] += value for (; i < size; i |= i + 1) ft[i] += value; } T sum(int i) { // val[0] + ... + val[i] T s = 0; for (; i >= 0; i = (i & (i + 1)) - 1) s += ft[i]; return s; } }; ll compute_inversion_number(vector<ll> vs) { // vs must be a permutation of (0, 1, ..., n - 1) int n = static_cast<int>(vs.size()); BinaryIndexedTree<ll> bt(n); ll res = 0LL; for (int i = n - 1; i >= 0; --i) { res += bt.sum(vs[i]); bt.add(vs[i], 1); } return res; } ll solve() { int n; cin >> n; vector<ll> vs(n), vt(n); for (int i : range(n)) cin >> vs[i]; for (int i : range(n)) cin >> vt[i]; if (vs[0] != vt[0]) return -1; if (vs[n - 1] != vt[n - 1]) return -1; for (int i : range(n - 1)) vs[i] ^= vs[i + 1], vt[i] ^= vt[i + 1]; vs.resize(n - 1); vt.resize(n - 1); n--; map<pair<int, int>, int> mp; map<int, int> count; for (int i : range(n)) { int t = vt[i]; int c = count[t]; mp[{t, c}] = i; count[t]++; } count.clear(); for (int i : range(n)) { int s = vs[i]; int c = count[s]; if (!mp.count({s, c})) return -1; vs[i] = mp[{s, c}]; count[s]++; } dump(vs); return compute_inversion_number(vs); } int main() { cout << fixed << setprecision(12); cout << solve() << endl; }