样例不过求调。
查看原帖
样例不过求调。
1296826
lcfollower楼主2024/8/12 10:11

rt。

#include <bits/stdc++.h>

#define int long long
#define rint register int
const int N = 2e6 + 10;
using namespace std;
int flag[N] ,opt[N] ,rev[N] ,l[N] ,r[N] ,val[N];
int n ,cnt; string s;
stack <int> sta;
inline bool dfs1(int u ,int op){
  opt[u] ^= op;
  if(u <= n) return opt[u];
  bool x = dfs1(l[u] ,op ^ flag[l[u]]) ,y = dfs1(r[u] ,op ^ flag[r[u]]);
  if(opt[u] == 0){
    if(!x) rev[l[u]] = 1;
    if(!y) rev[r[u]] = 1;
    return x & y;
  } else{
    if(x) rev[l[u]] = 1;
    if(y) rev[r[u]] = 1;
    return x | y;
  }
} inline void dfs2(int u){
  if(u <= n) return;
  rev[l[u]] |= rev[u];
  rev[r[u]] |= rev[u];
  dfs2(l[u]);
  dfs2(r[u]);
} signed main(){
  getline(cin ,s);
  scanf("%lld", &n);
  cnt = n;
  int num = 0;
  for(rint i = 1 ; i <= n; i ++) scanf("%lld" ,opt + i);
  for(char i : s){
    if(i == 'x') continue;
    if((int)i == 32) if(num) sta.push(num) ,num = 0;
    else if(i == '!'){
      flag[sta.top()] ^= 1;
    } else if(i == '&' || i == '|'){
      l[++ cnt] = sta.top();
      sta.pop();
      r[cnt] = sta.top();
      sta.pop();
      sta.push(cnt);
      opt[cnt] = (i == '&' ? 0 : 1);
    } else num = (num << 1ll) + (num << 3ll) + (i ^ 48);
  } 
  bool now = dfs1(cnt ,flag[cnt]);
  for(rint i = 1;i <= n; i++) cout << rev[i] << ' ';
  puts("");
  dfs2(cnt);
  int Q;
  scanf("%lld", &Q);
  while(Q --) {
    int x;
    scanf("%lld", &x);
    if(rev[x]) cout << (now) << endl;
    else cout << (now ^ 1) << endl;
  }
  return 0;
}
2024/8/12 10:11
加载中...