結果
問題 | No.2308 [Cherry 5th Tune B] もしかして、真? |
ユーザー |
|
提出日時 | 2023-05-19 22:41:53 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 18,623 bytes |
コンパイル時間 | 4,121 ms |
コンパイル使用メモリ | 262,536 KB |
最終ジャッジ日時 | 2025-02-13 02:50:51 |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 2 TLE * 37 |
ソースコード
#ifndef HIDDEN_IN_VS // 折りたたみ用// 警告の抑制#define _CRT_SECURE_NO_WARNINGS// ライブラリの読み込み#include <bits/stdc++.h>using namespace std;// 型名の短縮using ll = long long; // -2^63 ~ 2^63 = 9 * 10^18(int は -2^31 ~ 2^31 = 2 * 10^9)using pii = pair<int, int>; using pll = pair<ll, ll>; using pil = pair<int, ll>; using pli = pair<ll, int>;using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;using vl = vector<ll>; using vvl = vector<vl>; using vvvl = vector<vvl>;using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;using vc = vector<char>; using vvc = vector<vc>; using vvvc = vector<vvc>;using vd = vector<double>; using vvd = vector<vd>; using vvvd = vector<vvd>;template <class T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;using Graph = vvi;// 定数の定義const double PI = acos(-1);const vi DX = { 1, 0, -1, 0 }; // 4 近傍(下,右,上,左)const vi DY = { 0, 1, 0, -1 };int INF = 1001001001; ll INFL = 4004004004004004004LL;double EPS = 1e-15;// 入出力高速化struct fast_io { fast_io() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(18); } } fastIOtmp;// 汎用マクロの定義#define all(a) (a).begin(), (a).end()#define sz(x) ((int)(x).size())#define lbpos(a, x) (int)distance((a).begin(), std::lower_bound(all(a), x))#define ubpos(a, x) (int)distance((a).begin(), std::upper_bound(all(a), x))#define Yes(b) {cout << ((b) ? "Yes\n" : "No\n");}#define YES(b) {cout << ((b) ? "YES\n" : "NO\n");}#define rep(i, n) for(int i = 0, i##_len = int(n); i < i##_len; ++i) // 0 から n-1 まで昇順#define repi(i, s, t) for(int i = int(s), i##_end = int(t); i <= i##_end; ++i) // s から t まで昇順#define repir(i, s, t) for(int i = int(s), i##_end = int(t); i >= i##_end; --i) // s から t まで降順#define repe(v, a) for(const auto& v : (a)) // a の全要素(変更不可能)#define repea(v, a) for(auto& v : (a)) // a の全要素(変更可能)#define repb(set, d) for(int set = 0; set < (1 << int(d)); ++set) // d ビット全探索(昇順)#define repp(a) sort(all(a)); for(bool a##_perm = true; a##_perm; a##_perm = next_permutation(all(a))) // a の順列全て(昇順)#define smod(n, m) ((((n) % (m)) + (m)) % (m)) // 非負mod#define uniq(a) {sort(all(a)); (a).erase(unique(all(a)), (a).end());} // 重複除去#define EXIT(a) {cout << (a) << endl; exit(0);} // 強制終了// 汎用関数の定義template <class T> inline ll pow(T n, int k) { ll v = 1; rep(i, k) v *= n; return v; }template <class T> inline bool chmax(T& M, const T& x) { if (M < x) { M = x; return true; } return false; } // 最大値を更新(更新されたら trueを返す)template <class T> inline bool chmin(T& m, const T& x) { if (m > x) { m = x; return true; } return false; } // 最小値を更新(更新されたら trueを返す)template <class T> inline T get(T set, int i) { return (set >> i) & T(1); }// 演算子オーバーロードtemplate <class T, class U> inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }template <class T> inline istream& operator>>(istream& is, vector<T>& v) { repea(x, v) is >> x; return is; }template <class T> inline vector<T>& operator--(vector<T>& v) { repea(x, v) --x; return v; }template <class T> inline vector<T>& operator++(vector<T>& v) { repea(x, v) ++x; return v; }#endif // 折りたたみ用#if __has_include(<atcoder/all>)#include <atcoder/all>using namespace atcoder;#ifdef _MSC_VER#include "localACL.hpp"#endif//using mint = modint1000000007;using mint = modint998244353;//using mint = modint; // mint::set_mod(m);namespace atcoder {inline istream& operator>>(istream& is, mint& x) { ll x_; is >> x_; x = x_; return is; }inline ostream& operator<<(ostream& os, const mint& x) { os << x.val(); return os; }}using vm = vector<mint>; using vvm = vector<vm>; using vvvm = vector<vvm>;#endif#ifdef _MSC_VER // 手元環境(Visual Studio)#include "local.hpp"#else // 提出用(gcc)inline int popcount(int n) { return __builtin_popcount(n); }inline int popcount(ll n) { return __builtin_popcountll(n); }inline int lsb(int n) { return n != 0 ? __builtin_ctz(n) : -1; }inline int lsb(ll n) { return n != 0 ? __builtin_ctzll(n) : -1; }inline int msb(int n) { return n != 0 ? (31 - __builtin_clz(n)) : -1; }inline int msb(ll n) { return n != 0 ? (63 - __builtin_clzll(n)) : -1; }#define gcd __gcd#define dump(...)#define dumpel(v)#define dump_list(v)#define dump_mat(v)#define input_from_file(f)#define output_to_file(f)#define Assert(b) { if (!(b)) while (1) cout << "OLE"; }#endif//【Implicit Treap(M-可換モノイド)】/** Implicit_treap<S, op, e, F, act, comp, id>() : O(1)* 空で初期化する.* 要素は左作用付き可換モノイド (S, op, e, F, act, comp, id) の元とする.** Implicit_treap<S, op, e, F, act, comp, id>(vS a) : O(n log n)* 配列 a[0..n) で初期化する.** bool empty() : O(1)* 空かを返す.** int size() : O(1)* 要素数を返す.** S get(int i) : O(log n)* a[i] を返す(なければ e() を返す)** S prod(int l, int r) : O(log n)* Σa[l..r) を返す(空なら e() を返す)** apply(int i, F f) : O(log n)* a[i] = f( a[i] ) とする.** apply(int l, int r, F f) : O(log n)* a[l..r) = f( a[l..r) ) とする(空なら何もしない)** int max_right(int l, function<bool(S)> g) : O(log n)* g( Σa[l..r) ) = true となる最大の r を返す.* 制約:g( e() ) = true かつ g は単調** int min_left(int r, function<bool(S)> g) : O(log n)* g( Σa[l..r) ) = true となる最小の l を返す.* 制約:g( e() ) = true かつ g は単調** insert(int i, S x) : O(log n)* a[i] = x を挿入する(元々あった要素は右に移動する)** erase(int i) : O(log n)* a[i] の要素を削除し左詰めする(なければ何もしない)** reverse(int l, int r) : O(log n)* a[l..r) を左右反転する.** rotate(int l, int m, int r) : O(log n)* a[l, r) を,a[m] が先頭にくるよう巡回シフトする.** Implicit_treap split(int key) : O(log n)* 自身から位置 key 以上の要素を切り出し,切り出して出来た木を返す.** void merge(Implicit_treap IT) : O(log n)* 自身の右側に IT をマージする.** vS get_all() : O(n)* 全要素のリストを返す.*/template <class S, S(*op)(S, S), S(*e)(), class F, S(*act)(F, S), F(*comp)(F, F), F(*id)()>class Implicit_treap {// 参考 : https://xuzijian629.hatenablog.com/entry/2018/12/08/000452inline static bool first_call = true;inline static mt19937 rnd;struct Node {S value; // 頂点の値S acc; // 部分木のノードの総 opF lazy; // 部分木のノードへの遅延作用unsigned int priority; // ランダムに決めた優先度int cnt; // 部分木のノード数bool rev; // 部分木が反転されているかNode* l, * r; // 左右の子へのポインタNode(S value, unsigned int priority) : value(value), acc(e()), lazy(id()), priority(priority),cnt(1), rev(false), l(nullptr), r(nullptr) {}};Node* root;// 部分木 t のノード数を返す.int cnt(Node* t) {return t ? t->cnt : 0;}// op(部分木 t) を返す.S acc(Node* t) {return t ? t->acc : e();}// 部分木 t のノード数を更新する.void update_cnt(Node* t) {if (t) t->cnt = cnt(t->l) + 1 + cnt(t->r);}// op(部分木 t) を更新する.void update_acc(Node* t) {if (t) t->acc = op(acc(t->l), op(t->value, acc(t->r)));}// 部分木 t の cnt と acc を更新する(子は更新済であること)void pushup(Node* t) {update_cnt(t);update_acc(t);}// 遅延評価を適用する.void pushdown(Node* t) {// 部分木 t の反転フラグが true なら,実際に反転させた上で反転フラグを false にする.if (t && t->rev) {t->rev = false;swap(t->l, t->r);// t の子については反転フラグを flip しておくだけにする.if (t->l) t->l->rev ^= 1;if (t->r) t->r->rev ^= 1;}// 部分木 t に作用が溜まっていたら,実際に作用させた上で作用を id() にする.if (t && t->lazy != id()) {// t の子については作用を遅延させておくだけにする(acc だけは更新する)if (t->l) {t->l->lazy = comp(t->lazy, t->l->lazy);t->l->acc = act(t->lazy, t->l->acc);}if (t->r) {t->r->lazy = comp(t->lazy, t->r->lazy);t->r->acc = act(t->lazy, t->r->acc);}t->value = act(t->lazy, t->value);t->lazy = id();}// 部分木 t の cnt と acc を更新する.pushup(t);}// 部分木 t を位置 key 未満[以上] に分割し,それぞれの根へのポインタを l[ r ] に格納する.void split(Node* t, int key, Node*& l, Node*& r) {// 空なら分割しなくていい.if (!t) {l = r = nullptr;return;}// t の情報を更新する.pushdown(t);// 部分木 t 内の自身の位置を得る.int implicit_key = cnt(t->l);if (key <= implicit_key) {// 左の木を分割しその左側を l に採用する.小さくなった右側は t->l に繋ぎ直す.split(t->l, key, l, t->l);r = t;}else {// 右の木を分割しその右側を r に採用する.小さくなった左側は t->r に繋ぎ直す.split(t->r, key - implicit_key - 1, t->r, r);l = t;}// 繋ぎ変えで部分木 t の cnt と acc が壊れたので更新する.pushup(t);}// 部分木 l, r をこの順にマージした部分木を t に格納する.void merge(Node*& t, Node* l, Node* r) {// l, r の情報を更新する.pushdown(l);pushdown(r);// 片方が空ならもう一方を根とすればよい.if (!l) t = r;else if (!r) t = l;// 優先度が高い方を根とし,もう一方をその子とマージする.else if (l->priority > r->priority) {merge(l->r, l->r, r);t = l;}else {merge(r->l, l, r->l);t = r;}// 部分木 t の cnt と acc を更新する.pushup(t);}int max_right(Node* t, S x, int offset, const function<bool(S)>& g) {if (!t) return offset;// t の情報を更新する.pushdown(t);// 左の子の中に答えがあるなら左の子へif (t->l) {S nx = op(x, t->l->acc);if (!g(nx)) return max_right(t->l, x, offset, g);x = nx;}// 自身が答えならそれを返す.S nx = op(x, t->value);if (!g(nx)) return offset + cnt(t->l);x = nx;// 右の子の中に答えがあるなら右の子へif (t->r) {S nx = op(x, t->r->acc);if (!g(nx)) return max_right(t->r, x, offset + cnt(t->l) + 1, g);x = nx;}// どこにもないなら右端を返す.return offset + cnt(t->l) + 1 + cnt(t->r);}int min_left(Node* t, S x, int offset, const function<bool(S)>& g) {if (!t) return offset;// t の情報を更新する.pushdown(t);// 右の子の中に答えがあるなら右の子へif (t->r) {S nx = op(t->r->acc, x);if (!g(nx)) return min_left(t->r, x, offset + cnt(t->l) + 1, g);x = nx;}// 自身が答えならそれを返す.S nx = op(t->value, x);if (!g(nx)) return offset + cnt(t->l);x = nx;// 左の子の中に答えがあるなら左の子へif (t->l) {S nx = op(t->l->acc, x);if (!g(nx)) return min_left(t->l, x, offset, g);x = nx;}// どこにもないなら左端を返す.return offset;}void get_all(Node* t, vector<S>& seq) {if (!t) return;pushdown(t);get_all(t->l, seq);seq.emplace_back(t->value);get_all(t->r, seq);}public:// 空で初期化する.Implicit_treap() : root(nullptr) {// verify : https://www.spoj.com/problems/IITWPC4D/if (Implicit_treap::first_call) {rnd = mt19937((int)time(NULL));Implicit_treap::first_call = false;}}// 配列 a[0..n) で初期化する.Implicit_treap(const vector<S>& a) : root(nullptr) {// verify : https://judge.yosupo.jp/problem/dynamic_sequence_range_affine_range_sumif (Implicit_treap::first_call) {rnd = mt19937((int)time(NULL));Implicit_treap::first_call = false;}rep(i, sz(a)) insert(i, a[i]);}// 要素が空かを返す.bool empty() {return !(bool)root;}// 要素数を返す.int size() {// verify : https://www.spoj.com/problems/IITWPC4D/return cnt(root);}// a[l..r) = f( a[l..r) ) とする(空なら何もしない)void apply(int l, int r, F f) {// verify : https://judge.yosupo.jp/problem/dynamic_sequence_range_affine_range_sumif (l >= r) return;Node* lt, * mt, * rt;// [l..r) に対応する部分木 mt を切り出してくる.split(root, l, lt, rt);split(rt, r - l, mt, rt);// mt への作用 f を遅延させる(acc だけは更新する)if (mt) {mt->lazy = comp(f, mt->lazy);mt->acc = act(f, mt->acc);}// 木を元に戻しておく.merge(rt, mt, rt);merge(root, lt, rt);}// a[i] = f( a[i] ) とする(なければ何もしない)void apply(int i, F f) {apply(i, i + 1, f);}// op( a[l..r) ) を返す(空なら e() を返す)S prod(int l, int r) {// verify : https://judge.yosupo.jp/problem/dynamic_sequence_range_affine_range_sumif (l >= r) return e();Node* lt, * mt, * rt;// [l..r) に対応する部分木 mt を切り出してくる.split(root, l, lt, rt);split(rt, r - l, mt, rt);// 値は既に acc に格納されている.S res = acc(mt);// 木を元に戻しておく.merge(rt, mt, rt);merge(root, lt, rt);return res;}// a[i] を返す(なければ e() を返す)S get(int i) {// verify : https://www.spoj.com/problems/IITWPC4D/return prod(i, i + 1);}// g( op( a[l..r) ) ) = true となる最大の r を返す.int max_right(int l, const function<bool(S)>& g) {// verify : https://atcoder.jp/contests/practice2/tasks/practice2_jNode* lt, * rt;// [l..n) に対応する部分木 rt を切り出してくる.split(root, l, lt, rt);S x = e();int res = max_right(rt, x, l, g);// 木を元に戻しておく.merge(root, lt, rt);return res;}// g( op( a[l..r) ) ) = true となる最小の l を返す.int min_left(int r, const function<bool(S)>& g) {Node* lt, * rt;// [0..r) に対応する部分木 lt を切り出してくる.split(root, r, lt, rt);S x = e();int res = min_left(lt, x, 0, g);// 木を元に戻しておく.merge(root, lt, rt);return res;}// a[i] = x を挿入する(元々あった要素は右に移動する)void insert(int i, S x) {// verify : https://judge.yosupo.jp/problem/dynamic_sequence_range_affine_range_sumNode* lt, * rt;// 一旦 i で分割し,x を挟んでからマージする.split(root, i, lt, rt);merge(lt, lt, new Node(x, rnd()));merge(root, lt, rt);}// a[i] の要素を削除し左詰めする(なければ何もしない)void erase(int i) {// verify : https://judge.yosupo.jp/problem/dynamic_sequence_range_affine_range_sumNode* lt, * mt, * rt;// i の前後で分割し,i だけ除いてマージする.split(root, i + 1, lt, rt);split(lt, i, lt, mt);merge(root, lt, rt);}// a[l..r) を左右反転する.void reverse(int l, int r) {// verify : https://judge.yosupo.jp/problem/dynamic_sequence_range_affine_range_sumif (l >= r) return;Node* lt, * mt, * rt;// [l..r) に対応する部分木 mt を切り出してくる.split(root, l, lt, rt);split(rt, r - l, mt, rt);// 反転フラグを flip する.mt->rev ^= 1;// 木を元に戻しておく.merge(rt, mt, rt);merge(root, lt, rt);}// a[l, r) を,a[m] が先頭にくるよう巡回シフトする.void rotate(int l, int m, int r) {// verify : https://onlinejudge.u-aizu.ac.jp/problems/1508// 全体を反転reverse(l, r);// 左右それぞれを反転reverse(l, l + r - m);reverse(l + r - m, r);}// 自身から位置 key 以上の要素を切り出し,切り出して出来た木を返す.Implicit_treap split(int key) {// verify : https://judge.yosupo.jp/problem/dynamic_sequence_range_affine_range_sumNode* l, * r;split(root, key, l, r);root = l;Implicit_treap ret;ret.root = r;return ret;}// 自身の右側に IT をマージする.void merge(Implicit_treap& IT) {// verify : https://judge.yosupo.jp/problem/dynamic_sequence_range_affine_range_summerge(root, root, IT.root);}// 全要素のリストを返す.vector<S> get_all() {// verify : https://www.spoj.com/problems/TWIST/vector<S> seq;get_all(root, seq);return seq;}#ifdef _MSC_VERfriend ostream& operator<<(ostream& os, Implicit_treap IT) {os << IT.get_all();return os;}#endif};//【変更 作用付き 左変更 モノイド】using S102 = string;S102 e102() { return "$"; } // 使わない値なら何でも OKS102 op102(S102 x, S102 y) { return x == e102() ? y : x; }using F102 = string;F102 id102() { return "$"; } // 使わない値なら何でも OKS102 act102(F102 f, S102 x) { return f == id102() ? x : f; }F102 comp102(F102 f, F102 g) { return f == id102() ? g : f; }#define Update_LUpdate_mmonoid S102, op102, e102, F102, act102, comp102, id102void Main() {int n;cin >> n;vector<string> x(n), y(n - 1);cin >> x >> y;Implicit_treap<Update_LUpdate_mmonoid> IPx(x), IPy(y);rep(hoge, n - 1) {int s;cin >> s;s--;string l = IPx.get(s);string r = IPx.get(s + 1);string op = IPy.get(s);string res;if (op == "and") {res = (l == "True" && r == "True" ? "True" : "False");}else if (op == "or") {res = (l == "True" || r == "True" ? "True" : "False");}else if (op == "xor") {res = ((l == "True") != (r == "True") ? "True" : "False");}else if (op == "imp") {res = ((l == "False") || (r == "True") ? "True" : "False");}IPx.apply(s, res);IPx.erase(s + 1);IPy.erase(s);}cout << IPx.get(0) << endl;}int main() {// input_from_file("input.txt");// output_to_file("output.txt");int t;cin >> t; // マルチテストケースの場合// t = 1; // シングルテストケースの場合while (t--) {dump("------------------------------");Main();}}