結果

問題 No.2308 [Cherry 5th Tune B] もしかして、真?
ユーザー hongrockhongrock
提出日時 2023-05-19 22:21:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 151 ms / 2,000 ms
コード長 1,931 bytes
コンパイル時間 1,935 ms
コンパイル使用メモリ 200,144 KB
実行使用メモリ 12,356 KB
最終ジャッジ日時 2023-08-23 00:12:59
合計ジャッジ時間 8,785 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,984 KB
testcase_01 AC 109 ms
10,896 KB
testcase_02 AC 126 ms
11,336 KB
testcase_03 AC 116 ms
11,204 KB
testcase_04 AC 118 ms
11,324 KB
testcase_05 AC 120 ms
11,352 KB
testcase_06 AC 128 ms
11,784 KB
testcase_07 AC 129 ms
11,764 KB
testcase_08 AC 133 ms
11,892 KB
testcase_09 AC 133 ms
11,940 KB
testcase_10 AC 119 ms
11,228 KB
testcase_11 AC 130 ms
11,356 KB
testcase_12 AC 129 ms
11,268 KB
testcase_13 AC 127 ms
11,184 KB
testcase_14 AC 125 ms
11,220 KB
testcase_15 AC 125 ms
11,208 KB
testcase_16 AC 128 ms
11,408 KB
testcase_17 AC 129 ms
11,264 KB
testcase_18 AC 128 ms
11,324 KB
testcase_19 AC 124 ms
11,212 KB
testcase_20 AC 127 ms
11,224 KB
testcase_21 AC 147 ms
12,200 KB
testcase_22 AC 150 ms
12,200 KB
testcase_23 AC 147 ms
12,156 KB
testcase_24 AC 151 ms
12,140 KB
testcase_25 AC 147 ms
12,136 KB
testcase_26 AC 142 ms
12,356 KB
testcase_27 AC 140 ms
12,140 KB
testcase_28 AC 144 ms
12,220 KB
testcase_29 AC 145 ms
12,136 KB
testcase_30 AC 149 ms
12,164 KB
testcase_31 AC 82 ms
12,120 KB
testcase_32 AC 83 ms
12,120 KB
testcase_33 AC 81 ms
12,284 KB
testcase_34 AC 86 ms
12,208 KB
testcase_35 AC 88 ms
12,220 KB
testcase_36 AC 86 ms
12,216 KB
testcase_37 AC 9 ms
9,952 KB
testcase_38 AC 125 ms
11,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0