結果

問題 No.2308 [Cherry 5th Tune B] もしかして、真?
ユーザー ecotteaecottea
提出日時 2023-05-19 22:45:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,902 ms / 2,000 ms
コード長 18,687 bytes
コンパイル時間 5,402 ms
コンパイル使用メモリ 264,576 KB
実行使用メモリ 23,568 KB
最終ジャッジ日時 2023-08-23 00:41:13
合計ジャッジ時間 63,805 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1,401 ms
22,484 KB
testcase_02 AC 1,624 ms
22,504 KB
testcase_03 AC 1,508 ms
22,180 KB
testcase_04 AC 1,520 ms
22,164 KB
testcase_05 AC 1,580 ms
22,200 KB
testcase_06 AC 1,611 ms
22,996 KB
testcase_07 AC 1,653 ms
22,276 KB
testcase_08 AC 1,706 ms
22,224 KB
testcase_09 AC 1,687 ms
22,344 KB
testcase_10 AC 1,560 ms
22,444 KB
testcase_11 AC 1,624 ms
23,196 KB
testcase_12 AC 1,672 ms
22,952 KB
testcase_13 AC 1,651 ms
22,924 KB
testcase_14 AC 1,649 ms
22,940 KB
testcase_15 AC 1,671 ms
22,952 KB
testcase_16 AC 1,671 ms
22,956 KB
testcase_17 AC 1,650 ms
23,008 KB
testcase_18 AC 1,651 ms
23,064 KB
testcase_19 AC 1,660 ms
22,916 KB
testcase_20 AC 1,661 ms
22,932 KB
testcase_21 AC 1,847 ms
23,480 KB
testcase_22 AC 1,839 ms
23,360 KB
testcase_23 AC 1,878 ms
23,412 KB
testcase_24 AC 1,796 ms
23,384 KB
testcase_25 AC 1,812 ms
23,408 KB
testcase_26 AC 1,842 ms
23,468 KB
testcase_27 AC 1,902 ms
23,420 KB
testcase_28 AC 1,839 ms
23,376 KB
testcase_29 AC 1,871 ms
23,380 KB
testcase_30 AC 1,899 ms
23,396 KB
testcase_31 AC 707 ms
23,476 KB
testcase_32 AC 736 ms
23,372 KB
testcase_33 AC 717 ms
23,400 KB
testcase_34 AC 670 ms
23,404 KB
testcase_35 AC 695 ms
23,568 KB
testcase_36 AC 699 ms
23,388 KB
testcase_37 AC 34 ms
5,480 KB
testcase_38 AC 1,706 ms
22,976 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘void Main()’ 内:
main.cpp:620:21: 警告: ‘res’ may be used uninitialized [-Wmaybe-uninitialized]
  620 |                 int res;
      |                     ^~~

ソースコード

diff #

#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/000452

	inline static bool first_call = true;
	inline static mt19937 rnd;

	struct Node {
		S value; // 頂点の値
		S acc; // 部分木のノードの総 op
		F 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_sum

		if (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_sum

		if (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_sum

		if (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_j

		Node* 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_sum

		Node* 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_sum

		Node* 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_sum

		if (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_sum

		Node* 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_sum

		merge(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_VER
	friend ostream& operator<<(ostream& os, Implicit_treap IT) {
		os << IT.get_all();
		return os;
	}
#endif
};


//【変更 作用付き 左変更 モノイド】
using S102 = int;
S102 e102() { return INF + 1; } // 使わない値なら何でも OK
S102 op102(S102 x, S102 y) { return x == e102() ? y : x; }
using F102 = int;
F102 id102() { return INF + 2; } // 使わない値なら何でも OK
S102 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, id102


void Main() {
	int n;
	cin >> n;

	vector<int> x(n), y(n - 1);
	rep(i, n) {
		string s;
		cin >> s;

		if (s == "True") x[i] = 1;
		else x[i] = 0;
	}
	rep(i, n - 1) {
		string s;
		cin >> s;

		if (s == "and") y[i] = 0;
		else if (s == "or") y[i] = 1;
		else if (s == "xor") y[i] = 2;
		else if (s == "imp") y[i] = 3;
	}

	Implicit_treap<Update_LUpdate_mmonoid> IPx(x), IPy(y);

	rep(hoge, n - 1) {
		int s;
		cin >> s;
		s--;

		int l = IPx.get(s);
		int r = IPx.get(s + 1);
		int op = IPy.get(s);

		int res;
		if (op == 0) {
			res = l & r;
		}
		else if (op == 1) {
			res = l | r;
		}
		else if (op == 2) {
			res = l ^ r;
		}
		else if (op == 3) {
			res = (1 - l) | r;
		}

		IPx.apply(s, res);
		IPx.erase(s + 1);
		IPy.erase(s);
	}

	cout << (IPx.get(0) ? "True" : "False") << endl;
}

int main() {
//	input_from_file("input.txt");
//	output_to_file("output.txt");

	int t;
	cin >> t; // マルチテストケースの場合
//	t = 1; // シングルテストケースの場合

	while (t--) {
		dump("------------------------------");
		Main();
	}
}
0