結果

問題 No.2308 [Cherry 5th Tune B] もしかして、真?
ユーザー kotatsugamekotatsugame
提出日時 2023-05-19 21:37:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 179 ms / 2,000 ms
コード長 1,519 bytes
コンパイル時間 1,423 ms
コンパイル使用メモリ 77,456 KB
実行使用メモリ 35,284 KB
最終ジャッジ日時 2023-08-22 23:40:47
合計ジャッジ時間 10,135 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
19,736 KB
testcase_01 AC 160 ms
22,276 KB
testcase_02 AC 174 ms
24,648 KB
testcase_03 AC 168 ms
22,960 KB
testcase_04 AC 166 ms
23,344 KB
testcase_05 AC 163 ms
23,536 KB
testcase_06 AC 165 ms
25,468 KB
testcase_07 AC 172 ms
26,148 KB
testcase_08 AC 173 ms
25,472 KB
testcase_09 AC 172 ms
25,504 KB
testcase_10 AC 168 ms
22,660 KB
testcase_11 AC 169 ms
24,748 KB
testcase_12 AC 171 ms
24,852 KB
testcase_13 AC 171 ms
24,820 KB
testcase_14 AC 168 ms
24,748 KB
testcase_15 AC 172 ms
24,868 KB
testcase_16 AC 168 ms
24,668 KB
testcase_17 AC 169 ms
24,664 KB
testcase_18 AC 176 ms
24,808 KB
testcase_19 AC 169 ms
24,776 KB
testcase_20 AC 169 ms
24,748 KB
testcase_21 AC 175 ms
25,676 KB
testcase_22 AC 179 ms
25,724 KB
testcase_23 AC 177 ms
25,788 KB
testcase_24 AC 175 ms
25,696 KB
testcase_25 AC 174 ms
25,720 KB
testcase_26 AC 174 ms
25,828 KB
testcase_27 AC 172 ms
25,664 KB
testcase_28 AC 176 ms
26,064 KB
testcase_29 AC 174 ms
25,668 KB
testcase_30 AC 172 ms
25,656 KB
testcase_31 AC 145 ms
35,228 KB
testcase_32 AC 143 ms
35,164 KB
testcase_33 AC 147 ms
35,284 KB
testcase_34 AC 158 ms
30,460 KB
testcase_35 AC 159 ms
30,408 KB
testcase_36 AC 158 ms
30,484 KB
testcase_37 AC 31 ms
19,684 KB
testcase_38 AC 166 ms
24,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<cassert>
#include<atcoder/segtree>
using namespace std;
//1-indexed
#include<vector>
template<typename T>
struct BIT{
	int n;
	vector<T>bit;
	BIT(int n_=0):n(n_),bit(n_+1){}
	T sum(int i)
	{
		T ans=0;
		for(;i>0;i-=i&-i)ans+=bit[i];
		return ans;
	}
	void add(int i,T a)
	{
		if(i==0)return;
		for(;i<=n;i+=i&-i)bit[i]+=a;
	}
	int lower_bound(T k)//k<=sum(ret)
	{
		if(k<=0)return 0;
		int ret=0,i=1;
		while((i<<1)<=n)i<<=1;
		for(;i;i>>=1)
			if(ret+i<=n&&bit[ret+i]<k)k-=bit[ret+=i];
		return ret+1;
	}
};
pair<int,int>op(pair<int,int>l,pair<int,int>r){return max(l,r);}
pair<int,int>e(){return make_pair(-1,-1);}
int N;
string X[2<<17];
string Y[2<<17];
atcoder::segtree<pair<int,int>,op,e>seg;
bool f(int l,int r)
{
	if(l==r)return X[l]=="True";
	int idx=seg.prod(l,r).second;
	bool L=f(l,idx),R=f(idx+1,r);
	//cout<<l<<" "<<r<<" sp at "<<idx<<" : "<<L<<" "<<R<<endl;
	if(Y[idx]=="and")return L&&R;
	else if(Y[idx]=="or")return L||R;
	else if(Y[idx]=="xor")return L!=R;
	else return !L||R;
}
int main()
{
	int T;cin>>T;
	for(;T--;)
	{
		cin>>N;
		for(int i=0;i<N;i++)cin>>X[i];
		for(int i=0;i<N-1;i++)cin>>Y[i];
		BIT<int>bit(N-1);
		for(int i=1;i<=N-1;i++)bit.add(i,1);
		vector<pair<int,int> >init(N-1,e());
		for(int i=0;i<N-1;i++)
		{
			int s;cin>>s;
			int idx=bit.lower_bound(s)-1;
			assert(init[idx]==e());
			init[idx]=make_pair(i,idx);
			bit.add(idx+1,-1);
		}
		seg=atcoder::segtree<pair<int,int>,op,e>(init);
		cout<<(f(0,N-1)?"True\n":"False\n");
	}
}
0