結果

問題 No.2308 [Cherry 5th Tune B] もしかして、真?
ユーザー dyktr_06dyktr_06
提出日時 2023-05-19 22:15:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 13,223 bytes
コンパイル時間 4,961 ms
コンパイル使用メモリ 275,460 KB
実行使用メモリ 83,024 KB
最終ジャッジ日時 2024-05-10 05:42:41
合計ジャッジ時間 34,726 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 RE -
testcase_06 WA -
testcase_07 RE -
testcase_08 WA -
testcase_09 WA -
testcase_10 RE -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 640 ms
43,072 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 819 ms
82,892 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 RE -
testcase_26 AC 832 ms
82,892 KB
testcase_27 AC 819 ms
82,892 KB
testcase_28 AC 814 ms
82,892 KB
testcase_29 AC 809 ms
83,020 KB
testcase_30 AC 821 ms
82,892 KB
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます

ソースコード

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, T INF>
struct SegmentTreeBeats{
    int n, n0;
    vector<T> max_v, smax_v, max_c;
    vector<T> min_v, smin_v, min_c;
    vector<T> sum;
    vector<T> len, ladd, lval;

    void update_node_max(int k, T x) {
        sum[k] += (x - max_v[k]) * max_c[k];

        if(max_v[k] == min_v[k]){
            max_v[k] = min_v[k] = x;
        }else if(max_v[k] == smin_v[k]){
            max_v[k] = smin_v[k] = x;
        }else{
            max_v[k] = x;
        }

        if(lval[k] != INF && x < lval[k]){
            lval[k] = x;
        }
    }

    void update_node_min(int k, T x) {
        sum[k] += (x - min_v[k]) * min_c[k];

        if(max_v[k] == min_v[k]){
            max_v[k] = min_v[k] = x;
        }else if(smax_v[k] == min_v[k]){
            min_v[k] = smax_v[k] = x;
        }else{
            min_v[k] = x;
        }

        if(lval[k] != INF && lval[k] < x){
            lval[k] = x;
        }
    }

    void push(int k){
        if(n0 - 1 <= k) return;

        if(lval[k] != INF){
            updateall(2 * k + 1, lval[k]);
            updateall(2 * k + 2, lval[k]);
            lval[k] = INF;
            return;
        }

        if(ladd[k] != 0){
            addall(2 * k + 1, ladd[k]);
            addall(2 * k + 2, ladd[k]);
            ladd[k] = 0;
        }

        if(max_v[k] < max_v[2 * k + 1]){
            update_node_max(2 * k + 1, max_v[k]);
        }
        if(min_v[2 * k + 1] < min_v[k]){
            update_node_min(2 * k + 1, min_v[k]);
        }

        if(max_v[k] < max_v[2 * k + 2]){
            update_node_max(2 * k + 2, max_v[k]);
        }
        if(min_v[2 * k + 2] < min_v[k]){
            update_node_min(2 * k + 2, min_v[k]);
        }
    }

    void update(int k){
        sum[k] = sum[2 * k + 1] + sum[2 * k + 2];

        if(max_v[2 * k + 1] < max_v[2 * k + 2]){
            max_v[k] = max_v[2 * k + 2];
            max_c[k] = max_c[2 * k + 2];
            smax_v[k] = max(max_v[2 * k + 1], smax_v[2 * k + 2]);
        }else if(max_v[2 * k + 1] > max_v[2 * k + 2]){
            max_v[k] = max_v[2 * k + 1];
            max_c[k] = max_c[2 * k + 1];
            smax_v[k] = max(smax_v[2 * k + 1], max_v[2 * k + 2]);
        }else{
            max_v[k] = max_v[2 * k + 1];
            max_c[k] = max_c[2 * k + 1] + max_c[2 * k + 2];
            smax_v[k] = max(smax_v[2 * k + 1], smax_v[2 * k + 2]);
        }

        if(min_v[2 * k + 1] < min_v[2 * k + 2]){
            min_v[k] = min_v[2 * k + 1];
            min_c[k] = min_c[2 * k + 1];
            smin_v[k] = min(smin_v[2 * k + 1], min_v[2 * k + 2]);
        }else if(min_v[2 * k + 1] > min_v[2 * k + 2]){
            min_v[k] = min_v[2 * k + 2];
            min_c[k] = min_c[2 * k + 2];
            smin_v[k] = min(min_v[2 * k + 1], smin_v[2 * k + 2]);
        }else{
            min_v[k] = min_v[2 * k + 1];
            min_c[k] = min_c[2 * k + 1] + min_c[2 * k + 2];
            smin_v[k] = min(smin_v[2 * k + 1], smin_v[2 * k + 2]);
        }
    }

    void _query_chmin(T x, int a, int b, int k, int l, int r) {
        if(b <= l || r <= a || max_v[k] <= x){
            return;
        }
        if(a <= l && r <= b && smax_v[k] < x){
            update_node_max(k, x);
            return;
        }

        push(k);
        _query_chmin(x, a, b, 2 * k + 1, l, (l + r) / 2);
        _query_chmin(x, a, b, 2 * k + 2, (l + r) / 2, r);
        update(k);
    }

    void _query_chmax(T x, int a, int b, int k, int l, int r) {
        if(b <= l || r <= a || x <= min_v[k]){
            return;
        }
        if(a <= l && r <= b && x < smin_v[k]){
            update_node_min(k, x);
            return;
        }

        push(k);
        _query_chmax(x, a, b, 2 * k + 1, l, (l + r) / 2);
        _query_chmax(x, a, b, 2 * k + 2, (l + r) / 2, r);
        update(k);
    }

    void addall(int k, T x) {
        max_v[k] += x;
        if(smax_v[k] != -INF) smax_v[k] += x;
        min_v[k] += x;
        if(smin_v[k] != INF) smin_v[k] += x;

        sum[k] += len[k] * x;
        if(lval[k] != INF){
            lval[k] += x;
        }else{
            ladd[k] += x;
        }
    }

    void updateall(int k, T x) {
        max_v[k] = x; smax_v[k] = -INF;
        min_v[k] = x; smin_v[k] = INF;
        max_c[k] = min_c[k] = len[k];

        sum[k] = x * len[k];
        lval[k] = x; ladd[k] = 0;
    }

    void _query_add(T x, int a, int b, int k, int l, int r) {
        if(b <= l || r <= a){
            return;
        }
        if(a <= l && r <= b){
            addall(k, x);
            return;
        }

        push(k);
        _query_add(x, a, b, 2 * k + 1, l, (l + r) / 2);
        _query_add(x, a, b, 2 * k + 2, (l + r) / 2, r);
        update(k);
    }

    void _query_update(T x, int a, int b, int k, int l, int r) {
        if(b <= l || r <= a){
            return;
        }
        if(a <= l && r <= b){
            updateall(k, x);
            return;
        }

        push(k);
        _query_update(x, a, b, 2 * k + 1, l, (l + r) / 2);
        _query_update(x, a, b, 2 * k + 2, (l + r) / 2, r);
        update(k);
    }

    T _query_max(int a, int b, int k, int l, int r) {
        if(b <= l || r <= a){
            return -INF;
        }
        if(a <= l && r <= b){
            return max_v[k];
        }
        push(k);
        T lv = _query_max(a, b, 2 * k + 1, l, (l + r) / 2);
        T rv = _query_max(a, b, 2 * k + 2, (l + r) / 2, r);
        return max(lv, rv);
    }

    T _query_min(int a, int b, int k, int l, int r) {
        if(b <= l || r <= a){
            return INF;
        }
        if(a <= l && r <= b){
            return min_v[k];
        }
        push(k);
        T lv = _query_min(a, b, 2 * k + 1, l, (l + r) / 2);
        T rv = _query_min(a, b, 2 * k + 2, (l + r) / 2, r);
        return min(lv, rv);
    }

    T _query_sum(int a, int b, int k, int l, int r) {
        if(b <= l || r <= a){
            return 0;
        }
        if(a <= l && r <= b){
            return sum[k];
        }
        push(k);
        T lv = _query_sum(a, b, 2 * k + 1, l, (l + r) / 2);
        T rv = _query_sum(a, b, 2 * k + 2, (l + r) / 2, r);
        return lv + rv;
    }

public:
    SegmentTreeBeats(int n) : n(n){
        vector<T> a;
        init(n, a);
    }

    SegmentTreeBeats(int n, vector<T> &a) : n(n){
        init(n, a);
    }

    void init(int n, vector<T> &a){
        max_v.assign(4 * n, 0), smax_v.assign(4 * n, 0), max_c.assign(4 * n, 0);
        min_v.assign(4 * n, 0), smin_v.assign(4 * n, 0), min_c.assign(4 * n, 0);
        sum.assign(4 * n, 0);
        len.assign(4 * n, 0), ladd.assign(4 * n, 0); lval.assign(4 * n, 0);

        n0 = 1;
        while(n0 < n) n0 <<= 1;

        for(int i = 0; i < 2 * n0; ++i) ladd[i] = 0, lval[i] = INF;
        len[0] = n0;
        for(int i = 0; i < n0 - 1; ++i) len[2 * i + 1] = len[2 * i + 2] = (len[i] >> 1);

        for(int i = 0; i < n; ++i){
            max_v[n0 - 1 + i] = min_v[n0 - 1 + i] = sum[n0 - 1 + i] = (!a.empty() ? a[i] : 0);
            smax_v[n0 - 1 + i] = -INF;
            smin_v[n0 - 1 + i] = INF;
            max_c[n0 - 1 + i] = min_c[n0 - 1 + i] = 1;
        }

        for(int i = n; i < n0; ++i){
            max_v[n0 - 1 + i] = smax_v[n0 - 1 + i] = -INF;
            min_v[n0 - 1 + i] = smin_v[n0 - 1 + i] = INF;
            max_c[n0 - 1 + i] = min_c[n0 - 1 + i] = 0;
        }
        for(int i = n0 - 2; i >= 0; --i){
            update(i);
        }
    }

    // range minimize query
    void query_chmin(int a, int b, T x){
        _query_chmin(x, a, b, 0, 0, n0);
    }

    // range maximize query
    void query_chmax(int a, int b, T x){
        _query_chmax(x, a, b, 0, 0, n0);
    }

    // range add query
    void query_add(int a, int b, T x){
        _query_add(x, a, b, 0, 0, n0);
    }

    // range update query
    void query_update(int a, int b, T x){
        _query_update(x, a, b, 0, 0, n0);
    }

    // range minimum query
    T query_max(int a, int b){
        return _query_max(a, b, 0, 0, n0);
    }

    // range maximum query
    T query_min(int a, int b){
        return _query_min(a, b, 0, 0, n0);
    }

    // range sum query
    T query_sum(int a, int b){
        return _query_sum(a, b, 0, 0, n0);
    }

    T get(int x){
        return _query_sum(x, x + 1, 0, 0, n0);
    }
};

ll t;

void input(){
    in(t);
}

void solve(){
    ll n; in(n);
    vst x, y; vin(x, n);
    
    vin(y, n - 1);
    vll s; vin(s, n - 1);
    vll a(n), idx(n);
    rep(i, n){
        if(x[i] == "True") a[i] = 1;
        else a[i] = 0;

        idx[i] = i; 
    }
    SegmentTreeBeats<ll, INF> seg(n, idx);
    rep(i, n - 1){
        ll l = seg.get(s[i] - 1), r = seg.get(s[i]);
        string op = y[l];
        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; 
            }
        }
        seg.query_add(l, n, r - l);
    }
    if(a[seg.get(0)]){
        out("True");
    }else{
        out("False");
    }
}

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