結果

問題 No.2308 [Cherry 5th Tune B] もしかして、真?
ユーザー dyktr_06dyktr_06
提出日時 2023-05-19 22:38:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 10,189 bytes
コンパイル時間 5,487 ms
コンパイル使用メモリ 276,924 KB
実行使用メモリ 218,588 KB
最終ジャッジ日時 2024-05-10 06:07:24
合計ジャッジ時間 72,401 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
200,192 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 AC 159 ms
200,320 KB
testcase_38 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for(int i = 0; i < (int)(n); ++i)
#define rep2(i, n) for(int i = 0; i < (int)(n); ++i)
#define rep3(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep4(i, a, b, c) for(int i = (a); i < (int)(b); i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)

#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()
#define Sort(a) sort(a.begin(), a.end())
#define RSort(a) sort(a.rbegin(), a.rend())

typedef long long int ll;
typedef unsigned long long ul;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<char> vc;
typedef vector<string> vst;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef pair<long long, long long> P;

template<class T> long long sum(const T& a){ return accumulate(a.begin(), a.end(), 0LL); }
template<class T> auto min(const T& a){ return *min_element(a.begin(), a.end()); }
template<class T> auto max(const T& a){ return *max_element(a.begin(), a.end()); }

const long long MINF = 0x7fffffffffff;
const long long INF = 0x1fffffffffffffff;
const long long MOD = 1000000007;
const long double EPS = 1e-9;
const long double PI = acos(-1);
 
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 T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p){ is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){ os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for(T &in : v) is >> in; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v){ for(int i = 0; i < (int) v.size(); ++i){ os << v[i] << (i + 1 != (int) v.size() ? " " : ""); } return os; }
template <typename T, typename S> ostream &operator<<(ostream &os, const map<T, S> &mp){ for(auto &[key, val] : mp){ os << key << ":" << val << " "; } return os; }
template <typename T> ostream &operator<<(ostream &os, const set<T> &st){ auto itr = st.begin(); for(int i = 0; i < (int)st.size(); ++i){ os << *itr << (i + 1 != (int)st.size() ? " " : ""); itr++; } return os; }
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &st){ auto itr = st.begin(); for(int i = 0; i < (int)st.size(); ++i){ os << *itr << (i + 1 != (int)st.size() ? " " : ""); itr++; } return os; }
template <typename T> ostream &operator<<(ostream &os, queue<T> q){ while(q.size()){ os << q.front() << " "; q.pop(); } return os; }
template <typename T> ostream &operator<<(ostream &os, deque<T> q){ while(q.size()){ os << q.front() << " "; q.pop_front(); } return os; }
template <typename T> ostream &operator<<(ostream &os, stack<T> st){ while(st.size()){ os << st.top() << " "; st.pop(); } return os; }
template <class T, class Container, class Compare> ostream &operator<<(ostream &os, priority_queue<T, Container, Compare> pq){ while(pq.size()){ os << pq.top() << " "; pq.pop(); } return os; }

template<class T, class U> inline T vin(T& vec, U n) { vec.resize(n); for(int i = 0; i < (int) n; ++i) cin >> vec[i]; return vec; }
template<class T> inline void vout(T vec, string s = "\n"){ for(auto x : vec) cout << x << s; }
template<class... T> void in(T&... a){ (cin >> ... >> a); }
void out(){ cout << '\n'; }
template<class T, class... Ts> void out(const T& a, const Ts&... b){ cout << a; (cout << ... << (cout << ' ', b)); cout << '\n'; }
template<class T, class U> void inGraph(vector<vector<T>>& G, U n, U m, bool directed = false){ G.resize(n); for(int i = 0; i < m; ++i){ int a, b; cin >> a >> b; a--, b--; G[a].push_back(b); if(!directed) G[b].push_back(a); } }

template <typename T, int MAX_LOG, int NODES = 1 << 24>
struct BinaryTrie{
    struct Node{
        Node *nxt[2];
        int exist;
        vector<int> accept;
        Node() {}
    };
    Node *pool;
    int pid;
    T lazy;
    Node *nil;
    Node *root;

    BinaryTrie() : pid(0), lazy(0), nil(nullptr){
        pool = new Node[NODES];
        nil = _new();
        nil->nxt[0] = nil->nxt[1] = root = nil;
    }

    Node *_new(const int &exist_ = 0, const int &id = -1){
        pool[pid].nxt[0] = pool[pid].nxt[1] = nil;
        pool[pid].exist = exist_;
        if(id != -1) pool[pid].accept.push_back(id);
        return &(pool[pid++]);
    }

    Node *merge(Node *l, Node *r){
        pool[pid].nxt[0] = l;
        pool[pid].nxt[1] = r;
        pool[pid].exist = l->exist + r->exist;
        return &(pool[pid++]);
    }

private:
    Node *insert_(const T &x, const int &id, Node *n, const int &bit_idx){
        if(bit_idx == -1) {
            if(n == nil){
                return _new(1, id);
            }
            n->exist++;
            n->accept.push_back(id);
            return n;
        }
        if(((lazy >> bit_idx) & 1) == ((x >> bit_idx) & 1)){
            return merge(insert_(x, id, n->nxt[0], bit_idx - 1), n->nxt[1]);
        }else{
            return merge(n->nxt[0], insert_(x, id, n->nxt[1], bit_idx - 1));
        }
    }

    Node *erase_(const T &x, const int &id, Node *n, const int &bit_idx){
        if(bit_idx == -1){
            n->exist--;
            return n;
        }
        if(((lazy >> bit_idx) & 1) == ((x >> bit_idx) & 1)){
            return merge(erase_(x, id, n->nxt[0], bit_idx - 1), n->nxt[1]);
        }else{
            return merge(n->nxt[0], erase_(x, id, n->nxt[1], bit_idx - 1));
        }
    }

    pair<int, vector<int>&> find_(const T &x, Node *n, const int &bit_idx){
        if(bit_idx == -1){
            return pair<int, vector<int>&>(n->exist, n->accept);
        }
        if(((lazy >> bit_idx) & 1) == ((x >> bit_idx) & 1)){
            return find_(x, n->nxt[0], bit_idx - 1);
        }else{
            return find_(x, n->nxt[1], bit_idx - 1);
        }
    }

    pair<T, vector<int>&> max_element_(Node *n, const int &bit_idx) {
        if(bit_idx == -1){
            return pair<T, vector<int>&>(0, n->accept);
        }
        if(n->nxt[~(lazy >> bit_idx) & 1]->exist){
            auto ret = max_element_(n->nxt[~(lazy >> bit_idx) & 1], bit_idx - 1);
            ret.first |= T(1) << bit_idx;
            return ret;
        }
        return max_element_(n->nxt[(lazy >> bit_idx) & 1], bit_idx - 1);
    }

    pair<T, vector<int>&> min_element_(Node *n, const int &bit_idx){
        if(bit_idx == -1){
            return pair<T, vector<int>&>(0, n->accept);
        }

        if(n->nxt[(lazy >> bit_idx) & 1]->exist){
            return min_element_(n->nxt[(lazy >> bit_idx) & 1], bit_idx - 1);
        }

        auto ret = min_element_(n->nxt[~(lazy >> bit_idx) & 1], bit_idx - 1);
        ret.first |= T(1) << bit_idx;
        return ret;
    }

    pair<T, vector<int>&> kth_element_(Node *n, const int &k, const int &bit_idx){
        if(bit_idx == -1){
            return pair<T, vector<int>&>(0, n->accept);
        }

        int ex0 = n->nxt[(lazy >> bit_idx) & 1]->exist;
        if(ex0 < k){
            auto ret = kth_element_(n->nxt[~(lazy >> bit_idx) & 1], k - ex0, bit_idx - 1);
            ret.first |= T(1) << bit_idx;
            return ret;
        }
        return kth_element_(n->nxt[(lazy >> bit_idx) & 1], k, bit_idx - 1);
    }

    int count_less_(Node *n, const T &x, const int &bit_idx) {
        if(bit_idx == -1){
            return 0;
        }

        int ret = 0;
        bool f = (lazy >> bit_idx) & 1;
        if((x >> bit_idx & 1) && n->nxt[f]){
            ret += n->nxt[f]->exist;
        }
        if(n->nxt[f ^ (x >> bit_idx & 1)]){
            ret += count_less_(n->nxt[f ^ (x >> bit_idx & 1)], x, bit_idx - 1);
        }
        return ret;
    }

public:
    void insert(const T &x, const int &id = -1){
        root = insert_(x, id, root, MAX_LOG);
    }

    void erase(const T &x, const int &id = -1){ 
        root = erase_(x, id, root, MAX_LOG);
    }

    pair<int, vector<int>&> find(const T &x){
        return find_(x, root, MAX_LOG);
    }

    pair<T, vector<int>&> max_element(){
        return max_element_(root, MAX_LOG);
    }

    pair<T, vector<int>&> min_element(){
        return min_element_(root, MAX_LOG);
    }

    pair<T, vector<int>&> kth_element(const int &k){
        return kth_element_(root, k, MAX_LOG);
    }

    int count_less(const T &x){
        return count_less_(root, x, MAX_LOG);
    }

    size_t size() const {
        if(root->exist <= 0){
            return 0;
        }
        return root->exist;
    }

    bool empty() const {
        return size() == 0;
    }

    void operate_xor(const T &x){
        lazy ^= x;
    }
};

ll t;

void input(){
    in(t);
}

void solve(){
	BinaryTrie<int, 19, 1 << 21> bt, bt2;
    while(t--){
        ll n; in(n);
        vst x, y; vin(x, n);
        
        vin(y, n - 1);
        vll s; vin(s, n - 1);
        vll a(n);
        rep(i, n){
            if(x[i] == "True") a[i] = 1;
            else a[i] = 0;

            bt.insert(i);
        }
        rep(i, n - 1) bt2.insert(i);

        rep(i, n - 1){
            ll l = bt.kth_element(s[i]).first, r = bt.kth_element(s[i] + 1).first;
            ll opi = bt2.kth_element(s[i]).first;
            string op = y[opi];
            // out(l, r, opi);
            bt.erase(l);
            bt2.erase(opi);
            if(op == "and"){
                a[r] = a[l] & a[r];
            }else if(op == "or"){
                a[r] = a[l] | a[r];
            }else if(op == "xor"){
                a[r] = a[l] ^ a[r];
            }else{
                if(a[l] == 0){
                    a[r] = 1; 
                }
            }
        }
        ll idx = bt.kth_element(1).first;
        if(a[idx]){
            out("True");
        }else{
            out("False");
        }
        bt.erase(idx);
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(20);
    
    input();
    solve();
}
0