結果
問題 | No.2308 [Cherry 5th Tune B] もしかして、真? |
ユーザー | sten_san |
提出日時 | 2023-05-19 22:17:25 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 252 ms / 2,000 ms |
コード長 | 7,618 bytes |
コンパイル時間 | 2,177 ms |
コンパイル使用メモリ | 206,796 KB |
実行使用メモリ | 17,280 KB |
最終ジャッジ日時 | 2024-12-18 03:00:39 |
合計ジャッジ時間 | 11,624 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 162 ms
7,404 KB |
testcase_02 | AC | 197 ms
10,292 KB |
testcase_03 | AC | 182 ms
10,352 KB |
testcase_04 | AC | 180 ms
10,916 KB |
testcase_05 | AC | 187 ms
11,272 KB |
testcase_06 | AC | 210 ms
13,928 KB |
testcase_07 | AC | 203 ms
13,040 KB |
testcase_08 | AC | 228 ms
14,976 KB |
testcase_09 | AC | 228 ms
15,104 KB |
testcase_10 | AC | 189 ms
10,496 KB |
testcase_11 | AC | 211 ms
10,316 KB |
testcase_12 | AC | 206 ms
10,316 KB |
testcase_13 | AC | 203 ms
10,320 KB |
testcase_14 | AC | 205 ms
10,320 KB |
testcase_15 | AC | 205 ms
10,320 KB |
testcase_16 | AC | 204 ms
10,320 KB |
testcase_17 | AC | 205 ms
10,188 KB |
testcase_18 | AC | 209 ms
10,316 KB |
testcase_19 | AC | 209 ms
10,188 KB |
testcase_20 | AC | 202 ms
10,316 KB |
testcase_21 | AC | 244 ms
17,280 KB |
testcase_22 | AC | 249 ms
17,280 KB |
testcase_23 | AC | 244 ms
17,280 KB |
testcase_24 | AC | 252 ms
17,280 KB |
testcase_25 | AC | 249 ms
17,280 KB |
testcase_26 | AC | 246 ms
17,280 KB |
testcase_27 | AC | 251 ms
17,280 KB |
testcase_28 | AC | 242 ms
17,280 KB |
testcase_29 | AC | 246 ms
17,280 KB |
testcase_30 | AC | 246 ms
17,152 KB |
testcase_31 | AC | 119 ms
17,152 KB |
testcase_32 | AC | 119 ms
17,152 KB |
testcase_33 | AC | 121 ms
17,152 KB |
testcase_34 | AC | 124 ms
17,280 KB |
testcase_35 | AC | 124 ms
17,152 KB |
testcase_36 | AC | 125 ms
17,280 KB |
testcase_37 | AC | 13 ms
5,248 KB |
testcase_38 | AC | 193 ms
10,312 KB |
ソースコード
#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[r] = x[l] & x[r]; } if (y[l] == 1) { x[r] = x[l] | x[r]; } if (y[l] == 2) { x[r] = x[l] ^ x[r]; } if (y[l] == 3) { x[r] = !x[l] | x[r]; } index.erase(l); } cout << (x[index.nth_element(0)] ? "True" : "False") << '\n'; } cout << flush; }