結果
問題 | No.2308 [Cherry 5th Tune B] もしかして、真? |
ユーザー | sten_san |
提出日時 | 2023-05-19 22:08:58 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 7,619 bytes |
コンパイル時間 | 2,120 ms |
コンパイル使用メモリ | 205,824 KB |
実行使用メモリ | 17,408 KB |
最終ジャッジ日時 | 2024-05-10 05:38:02 |
合計ジャッジ時間 | 10,113 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 164 ms
10,316 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | AC | 163 ms
10,316 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | AC | 157 ms
10,320 KB |
testcase_21 | WA | - |
testcase_22 | AC | 184 ms
17,280 KB |
testcase_23 | AC | 182 ms
17,280 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 185 ms
17,152 KB |
testcase_27 | AC | 189 ms
17,280 KB |
testcase_28 | AC | 188 ms
17,280 KB |
testcase_29 | AC | 184 ms
17,280 KB |
testcase_30 | AC | 185 ms
17,280 KB |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | AC | 93 ms
17,152 KB |
testcase_34 | AC | 111 ms
17,280 KB |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
ソースコード
#include <bits/stdc++.h> using namespace std; struct iofast_t { iofast_t() { ios::sync_with_stdio(false); cin.tie(nullptr); } } iofast; struct uns_t {} uns; template <typename Element, typename Head, typename ...Args> auto vec(Element init, Head arg, Args ...args) { if constexpr (sizeof...(Args) == 0) return vector(arg, init); else return vector(arg, vec(init, args...)); } template <typename Element, typename Head, typename ...Args> auto vec(uns_t, Head arg, Args ...args) { return vec(Element(), arg, args...); } template <typename Container> auto distance(const Container &c, decltype(begin(c)) iter) { return distance(begin(c), iter); } template <typename RIter, typename Compare = less<typename iterator_traits<RIter>::value_type>> auto isort(RIter first, RIter last, Compare comp = Compare()) { vector<int> i(distance(first, last)); iota(begin(i), end(i), 0); sort(begin(i), end(i), [&](auto x, auto y) { return comp(*(first + x), *(first + y)); }); return i; } template <typename, template <typename> typename, typename = void_t<>> struct detect : false_type {}; template <typename T, template <typename> typename Check> struct detect<T, Check, void_t<Check<T>>> : true_type {}; template <typename T, template <typename> typename Check> constexpr inline bool detect_v = detect<T, Check>::value; template <typename T> using has_member_sort = decltype(declval<T>().sort()); template <typename Container, typename Compare = less<typename Container::value_type>> auto sorted(Container c, Compare comp = Compare()) { if constexpr (detect_v<Container, has_member_sort>) { c.sort(comp); return c; } else { sort(begin(c), end(c), comp); return c; } } template <typename Container, typename Compare = equal_to<typename Container::value_type>> auto uniqued(Container c, Compare comp = Compare()) { c.erase(unique(begin(c), end(c), comp), end(c)); return c; } template <typename T, typename Compare = less<T>> T &chmin(T &l, T r, Compare &&f = less<T>()) { return l = min(l, r, f); } template <typename T, typename Compare = less<T>> T &chmax(T &l, T r, Compare &&f = less<T>()) { return l = max(l, r, f); } template <typename F> constexpr auto fix(F &&f) noexcept { return [f = std::tuple<F>(std::forward<F>(f))](auto &&...args) mutable { return std::get<0>(f)(fix(std::get<0>(f)), std::forward<decltype(args)>(args)...); }; } template <size_t Bits> struct binary_trie { static_assert(0 < Bits); constexpr static size_t bits = Bits; // O(1) binary_trie() noexcept: xor_all{ 0 }, root{} { } // O(1) // 0 <= v < 2^Bits void apply_xor(size_t v) noexcept { xor_all ^= v; } // O(1) size_t size() const noexcept { return root.count; } // O(Bits) // 0 <= v < 2^Bits size_t count(size_t v) const noexcept { return count_(v ^ xor_all); } // O(Bits) // 0 <= v < 2^Bits bool exist(size_t v) const noexcept { return exist_(v ^ xor_all); } // O(Bits) // 0 <= v < 2^Bits void insert(size_t v) { insert_(v ^ xor_all); } // O(Bits) // 0 <= v < 2^Bits void erase(size_t v) noexcept { erase_(v ^ xor_all); } // O(Bits) // 0 <= n < size(binary_trie) size_t nth_element(size_t n) const { if (size() <= n) { throw std::out_of_range("binary_trie"); } size_t path = 0; auto b = (size_t(1) << (Bits - 1)); const node *iter = &root; while (0 < b) { auto m = !!(xor_all & b); auto c = iter->c[m]; b >>= 1; path <<= 1; if (c != nullptr) { if (n < c->count) { iter = c; path |= 0; continue; } n -= c->count; } iter = iter->c[!m]; path |= 1; } return path; } // O(Bits) // 0 <= v < 2^Bits size_t lower_bound(size_t v) const noexcept { if (v == 0) { return 0; } return upper_bound(v - 1); } // O(Bits) // 0 <= v < 2^Bits size_t upper_bound(size_t v) const noexcept { auto b = (size_t(1) << (Bits - 1)); size_t sum = 0; const node *iter = &root; while (0 < b) { auto m = !!(xor_all & b); auto f = !!(v & b); auto c = iter->c[m]; if (c != nullptr && f) { sum += c->count; } auto d = iter->c[m ^ f]; if (d == nullptr) { return sum; } iter = d; b >>= 1; } sum += iter->count; return sum; } private: struct node { node() noexcept: count{ 0 }, c{ nullptr, nullptr } { } ~node() { if (c[0] != nullptr) delete c[0]; if (c[1] != nullptr) delete c[1]; } node *advance(bool f) { if (c[f] == nullptr) { c[f] = new node(); } return c[f]; } size_t count = 0; node *c[2]; }; size_t count_(size_t n) const noexcept { auto b = (size_t(1) << (Bits - 1)); const node *iter = &root; while (0 < b) { iter = iter->c[!!(n & b)]; if (iter == nullptr || iter->count == 0) { return 0; } b >>= 1; } return iter->count; } bool exist_(size_t n) const noexcept { return 0 < count_(n); } void insert_(size_t n) { auto b = (size_t(1) << (Bits - 1)); node *iter = &root; ++root.count; while (0 < b) { iter = iter->advance(!!(n & b)); ++iter->count; b >>= 1; } } void erase_(size_t n) noexcept { if (exist_(n)) { auto b = (size_t(1) << (Bits - 1)); node *iter = &root; --root.count; while (0 < b) { iter = iter->c[!!(n & b)]; --iter->count; b >>= 1; } } } size_t xor_all; node root; }; int main() { int t; cin >> t; while (t--) { int n; cin >> n; auto x = vec<int>(uns, n); for (auto &v : x) { string s; cin >> s; v = (s[0] == 'T'); } auto y = vec<int>(uns, n - 1); for (auto &v : y) { string s; cin >> s; if (s[0] == 'a') { v = 0; } if (s[0] == 'o') { v = 1; } if (s[0] == 'x') { v = 2; } if (s[0] == 'i') { v = 3; } } binary_trie<18> index; for (int i = 0; i < n; ++i) { index.insert(i); } for (int i = 1; i < n; ++i) { int s; cin >> s; --s; int l = index.nth_element(s); int r = index.nth_element(s + 1); if (y[l] == 0) { x[l] = x[l] & x[r]; } if (y[l] == 1) { x[l] = x[l] | x[r]; } if (y[l] == 2) { x[l] = x[l] ^ x[r]; } if (y[l] == 3) { x[l] = !x[l] || y[r]; } index.erase(r); } cout << (x[index.nth_element(0)] ? "True" : "False") << '\n'; } cout << flush; }