結果
問題 | No.2308 [Cherry 5th Tune B] もしかして、真? |
ユーザー |
![]() |
提出日時 | 2023-05-19 22:21:06 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 149 ms / 2,000 ms |
コード長 | 1,931 bytes |
コンパイル時間 | 1,955 ms |
コンパイル使用メモリ | 195,004 KB |
最終ジャッジ日時 | 2025-02-13 02:11:22 |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 39 |
ソースコード
#include<bits/stdc++.h> using namespace std; #define rep(i, a, n) for(int i=(a); i<(n); ++i) #define per(i, a, n) for(int i=(a); i>(n); --i) #define pb emplace_back #define mp make_pair #define clr(a, b) memset(a, b, sizeof(a)) #define all(x) (x).begin(),(x).end() #define lowbit(x) (x & -x) #define fi first #define se second #define lson o<<1 #define rson o<<1|1 #define gmid l[o]+r[o]>>1 using ll = long long; using ull = unsigned long long; using pii = pair<int,int>; using pll = pair<ll, ll>; using ui = unsigned int; constexpr int mod = 998244353; constexpr int inf = 0x3f3f3f3f; constexpr double EPS = 1e-8; const double PI = acos(-1.0); constexpr int N = 2e5 + 10; int T, n; bool f[N]; string g, op[N]; int pre[N], nxt[N], s[N]; bool calc(bool x, string &op, bool y){ if(op == "and") return x & y; if(op == "or") return x | y; if(op == "xor") return x ^ y; return x ? y : 1; } void add(int x, int v){ for(; x<n; x+=lowbit(x)) s[x] += v; } int sum(int x){ int ret = 0; for(; x>0; x-=lowbit(x)) ret += s[x]; return ret; } void _main(){ cin >> T; while(T--){ cin >> n; rep(i, 1, n + 1){ cin >> g; f[i] = g[0] == 'T'; } nxt[0] = 1; pre[n] = n - 1; rep(i, 1, n){ cin >> op[i]; pre[i] = i - 1; nxt[i] = i + 1; s[i] = 0; } rep(i, 1, n) add(i, 1); int x; rep(i, 1, n){ cin >> x; int low = 1, top = n - 1, mid, key = n - 1; while(low <= top){ mid = low + top >> 1; if(sum(mid) >= x){ key = min(key, mid); top = mid - 1; } else { low = mid + 1; } } x = key; add(x, -1); f[nxt[x]] = calc(f[x], op[x], f[nxt[x]]); nxt[pre[x]] = nxt[x]; pre[nxt[x]] = pre[x]; } cout << (f[n] ? "True" : "False") << '\n'; } } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); _main(); return 0; }