結果

問題 No.2308 [Cherry 5th Tune B] もしかして、真?
ユーザー CoCo_Japan_panCoCo_Japan_pan
提出日時 2023-05-19 22:58:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 167 ms / 2,000 ms
コード長 4,519 bytes
コンパイル時間 3,512 ms
コンパイル使用メモリ 222,524 KB
実行使用メモリ 5,752 KB
最終ジャッジ日時 2023-08-23 00:59:06
合計ジャッジ時間 11,297 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 129 ms
4,384 KB
testcase_02 AC 143 ms
4,488 KB
testcase_03 AC 135 ms
4,384 KB
testcase_04 AC 133 ms
4,384 KB
testcase_05 AC 139 ms
4,676 KB
testcase_06 AC 149 ms
5,272 KB
testcase_07 AC 147 ms
4,812 KB
testcase_08 AC 153 ms
5,140 KB
testcase_09 AC 153 ms
5,204 KB
testcase_10 AC 137 ms
4,384 KB
testcase_11 AC 144 ms
4,400 KB
testcase_12 AC 143 ms
4,400 KB
testcase_13 AC 144 ms
4,480 KB
testcase_14 AC 143 ms
4,396 KB
testcase_15 AC 144 ms
4,412 KB
testcase_16 AC 144 ms
4,388 KB
testcase_17 AC 144 ms
4,480 KB
testcase_18 AC 143 ms
4,380 KB
testcase_19 AC 145 ms
4,392 KB
testcase_20 AC 142 ms
4,472 KB
testcase_21 AC 164 ms
5,668 KB
testcase_22 AC 165 ms
5,688 KB
testcase_23 AC 164 ms
5,752 KB
testcase_24 AC 163 ms
5,684 KB
testcase_25 AC 165 ms
5,684 KB
testcase_26 AC 165 ms
5,684 KB
testcase_27 AC 166 ms
5,744 KB
testcase_28 AC 164 ms
5,684 KB
testcase_29 AC 165 ms
5,692 KB
testcase_30 AC 167 ms
5,684 KB
testcase_31 AC 85 ms
5,684 KB
testcase_32 AC 85 ms
5,704 KB
testcase_33 AC 85 ms
5,688 KB
testcase_34 AC 97 ms
5,696 KB
testcase_35 AC 97 ms
5,740 KB
testcase_36 AC 97 ms
5,672 KB
testcase_37 AC 8 ms
4,384 KB
testcase_38 AC 141 ms
4,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 2 "/home/cocojapanpan/Procon_CPP/proconLibrary/lib/template/procon.hpp"

#ifndef DEBUG
// 提出時にassertはオフ
#ifndef NDEBUG
#define NDEBUG
#endif
// 定数倍高速化
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define ALL(x) (x).begin(), (x).end()
template <class T>
using vec = vector<T>;
template <class T, class S>
inline bool chmax(T &a, const S &b) {
    return (a < b ? a = b, 1 : 0);
}
template <class T, class S>
inline bool chmin(T &a, const S &b) {
    return (a > b ? a = b, 1 : 0);
}
template <class T>
constexpr T INF = 1'000'000'000;
template <>
constexpr int INF<int> = 1'000'000'000;
template <>
constexpr ll INF<ll> = ll(INF<int>) * INF<int> * 2;
#line 2 "/home/cocojapanpan/Procon_CPP/proconLibrary/lib/data-structure/fenwickTree.hpp"

#line 4 "/home/cocojapanpan/Procon_CPP/proconLibrary/lib/data-structure/fenwickTree.hpp"

template <typename T>
// 内部では1-baseですが、外からは0-baseに見せてます
struct fenwickTree {
   public:
    explicit fenwickTree(int size) : _size(size), data(size + 1, 0) {
        // sizeを超えない2べきを求めておく(lowerBound用)
        beki_floor = 1;
        while (beki_floor * 2 <= _size) {
            beki_floor *= 2;
        }
    }

    // 全てを1にする初期化
    void init_all_one() {
        for (int i = 1; i <= _size; i++) {
            data[i] = i & (-i);
        }
    }

    // a[index] += x を行う
    void add(int index, const T &x) {
        assert(0 <= index && index < _size);
        int curIndex = index + 1;
        while (curIndex <= _size) {
            data[curIndex] += x;
            // 区間の長さ分だけ番号に足したところを更新していく
            curIndex += curIndex & (-curIndex);
        }
    }

    // a[index] = xとする
    void set(int index, const T &x) {
        assert(0 <= index && index < _size);
        // +(x - a[index])をするだけ
        add(index, x - sum(index, index + 1));
    }

    // a[left] + ... + a[right - 1] を求める
    T sum(int left, int right) const {
        assert(0 <= left && left <= right && right <= _size);
        return sumFromFirst(right) - sumFromFirst(left);
    }

    // a[0] + ... a[x] >= w なる最小のxを求める(なければx = _size)
    int lowerBound(int w) const {
        if (w <= 0) return 0;
        int x = 0;
        for (int k = beki_floor; k > 0; k >>= 1) {
            if (x + k <= _size && data[x + k] < w) {
                w -= data[x + k];
                x += k;
            }
        }
        return x;
    }

   private:
    int _size;
    std::vector<T> data;  // 1-base
    int beki_floor;  // _size以下の最大の2べき
    // a[0] + ... a[right - 1] の和を求める
    T sumFromFirst(int right) const {
        assert(0 <= right && right <= _size);
        if (right == 0) {
            return 0;
        }
        T ans = 0;
        int curIndex = right;
        while (curIndex > 0) {
            ans += data[curIndex];
            // 次に足すべき区間は番号から区間の長さだけ引いたもの
            curIndex -= curIndex & (-curIndex);
        }
        return ans;
    }
};
#line 3 "main.cpp"

bool op(bool l, char ope, bool r) {
    if(ope == 'a') return l & r;
    if(ope == 'o') return l | r;
    if(ope == 'x') return l ^ r;
    if(!l) return true;
    return r;
}

bool solve() {
    int N;
    cin >> N;
    vec<bool> X(N);
    for(int i = 0; i < N; i++) {
        string x;
        cin >> x;
        if(x == "True") {
            X[i] = true;
        } else {
            X[i] = false;
        }
    }
    vec<char> Y(N - 1);
    for(int i = 0; i < N - 1; i++) {
        string x;
        cin >> x;
        Y[i] = x[0];
    }
    vec<int> S(N - 1);
    for(int &s : S) {
        cin >> s;
    }
    fenwickTree<int> BIT_X(N), BIT_Y(N - 1);
    BIT_X.init_all_one(); BIT_Y.init_all_one();
    for(int s : S) {
        int x_id_l = BIT_X.lowerBound(s);
        int x_id_r = BIT_X.lowerBound(s + 1);
        int y_id = BIT_Y.lowerBound(s);
        bool ans = op(X[x_id_l], Y[y_id], X[x_id_r]);
        X[x_id_l] = ans;
        BIT_X.add(x_id_r, -1);
        BIT_Y.add(y_id, -1);
    }
    return X[BIT_X.lowerBound(1)];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    while(T--) {
        cout << (solve() ? "True" : "False") << "\n";    
    }
}
0