結果

問題 No.2308 [Cherry 5th Tune B] もしかして、真?
ユーザー ecotteaecottea
提出日時 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
権限があれば一括ダウンロードができます

ソースコード

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^18int -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 TreapM-
/*
* 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 = string;
S102 e102() { return "$"; } // 使 OK
S102 op102(S102 x, S102 y) { return x == e102() ? y : x; }
using F102 = string;
F102 id102() { return "$"; } // 使 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<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();
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0