結果

問題 No.2308 [Cherry 5th Tune B] もしかして、真?
ユーザー 👑 kmjpkmjp
提出日時 2023-05-19 23:12:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 227 ms / 2,000 ms
コード長 2,029 bytes
コンパイル時間 2,528 ms
コンパイル使用メモリ 201,140 KB
実行使用メモリ 16,280 KB
最終ジャッジ日時 2023-08-23 01:08:41
合計ジャッジ時間 11,566 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
13,656 KB
testcase_01 AC 163 ms
14,344 KB
testcase_02 AC 181 ms
14,840 KB
testcase_03 AC 174 ms
15,064 KB
testcase_04 AC 172 ms
15,216 KB
testcase_05 AC 178 ms
15,140 KB
testcase_06 AC 192 ms
15,416 KB
testcase_07 AC 186 ms
15,464 KB
testcase_08 AC 196 ms
15,608 KB
testcase_09 AC 193 ms
15,648 KB
testcase_10 AC 172 ms
14,912 KB
testcase_11 AC 181 ms
14,836 KB
testcase_12 AC 183 ms
14,808 KB
testcase_13 AC 181 ms
14,776 KB
testcase_14 AC 176 ms
15,088 KB
testcase_15 AC 181 ms
14,944 KB
testcase_16 AC 177 ms
15,060 KB
testcase_17 AC 178 ms
14,968 KB
testcase_18 AC 182 ms
15,016 KB
testcase_19 AC 182 ms
15,044 KB
testcase_20 AC 179 ms
15,108 KB
testcase_21 AC 223 ms
15,976 KB
testcase_22 AC 211 ms
16,056 KB
testcase_23 AC 218 ms
16,052 KB
testcase_24 AC 220 ms
16,052 KB
testcase_25 AC 227 ms
16,272 KB
testcase_26 AC 221 ms
15,948 KB
testcase_27 AC 213 ms
16,280 KB
testcase_28 AC 221 ms
16,040 KB
testcase_29 AC 218 ms
15,972 KB
testcase_30 AC 219 ms
15,976 KB
testcase_31 AC 147 ms
15,948 KB
testcase_32 AC 147 ms
16,216 KB
testcase_33 AC 147 ms
16,116 KB
testcase_34 AC 152 ms
15,976 KB
testcase_35 AC 153 ms
16,216 KB
testcase_36 AC 153 ms
16,216 KB
testcase_37 AC 28 ms
13,660 KB
testcase_38 AC 177 ms
14,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int T,N;
int X[202020];
int Y[202020];
int table[2][2][4];

template<class V, int ME> class BIT {
public:
	V bit[1<<ME],val[1<<ME];
	V operator()(int e) {if(e<0) return 0;V s=0;e++;while(e) s+=bit[e-1],e-=e&-e; return s;}
	void add(int e,V v) { val[e++]+=v; while(e<=1<<ME) bit[e-1]+=v,e+=e&-e;}
	void set(int e,V v) { add(e,v-val[e]);}
	int lower_bound(V val) {
		V tv=0; int i,ent=0;
		for(i=ME-1;i>=0;i--) if(tv+bit[ent+(1<<i)-1]<val) tv+=bit[ent+(1<<i)-1],ent+=(1<<i);
		return ent;
	}
};
BIT<int,20> var,op;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	FOR(x,2) FOR(y,2) {
		table[x][y][0]=x&y;
		table[x][y][1]=x|y;
		table[x][y][2]=x^y;
		table[x][y][3]=(1-x)|y;
	}
	
	cin>>T;
	while(T--) {
		cin>>N;
		FOR(i,N) {
			var.add(i,1);
			cin>>s;
			X[i]=s=="True";
		}
		FOR(i,N-1) {
			op.add(i,1);
			cin>>s;
			if(s=="and") Y[i]=0;
			if(s=="or") Y[i]=1;
			if(s=="xor") Y[i]=2;
			if(s=="imp") Y[i]=3;
		}
		FOR(i,N-1) {
			cin>>x;
			int a=var.lower_bound(x);
			int b=var.lower_bound(x+1);
			int c=op.lower_bound(x);
			X[a]=table[X[a]][X[b]][Y[c]];
			var.add(b,-1);
			op.add(c,-1);
		}
		x=var.lower_bound(1);
		var.add(x,-1);
		if(X[x]) {
			cout<<"True"<<endl;
		}
		else {
			cout<<"False"<<endl;
		}
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0