QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#199313#4896. Alice、Bob 与 DFSAFewSuns0 3ms13500kbC++142.6kb2023-10-04 08:14:072023-10-04 08:14:08

Judging History

你现在查看的是最新测评结果

  • [2023-10-04 08:14:08]
  • 评测
  • 测评结果:0
  • 用时:3ms
  • 内存:13500kb
  • [2023-10-04 08:14:07]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
namespace my_std{
	#define ll long long
	#define bl bool
	ll my_pow(ll a,ll b,ll mod){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res=(res*a)%mod;
			a=(a*a)%mod;
			b>>=1;
		}
		return res;
	}
	ll qpow(ll a,ll b){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res*=a;
			a*=a;
			b>>=1;
		}
		return res;
	}
	#define db double
	#define pf printf
	#define pc putchar
	#define fr(i,x,y) for(register ll i=(x);i<=(y);i++)
	#define pfr(i,x,y) for(register ll i=(x);i>=(y);i--)
	#define go(u) for(ll i=head[u];i;i=e[i].nxt)
	#define enter pc('\n')
	#define space pc(' ')
	#define fir first
	#define sec second
	#define MP make_pair
	#define il inline
	#define inf 8e18
	#define random(x) rand()*rand()%(x)
	#define inv(a,mod) my_pow((a),(mod-2),(mod))
	il ll read(){
		ll sum=0,f=1;
		char ch=0;
		while(!isdigit(ch)){
			if(ch=='-') f=-1;
			ch=getchar();
		}
		while(isdigit(ch)){
			sum=sum*10+(ch^48);
			ch=getchar();
		}
		return sum*f;
	}
	il void write(ll x){
		if(x<0){
			x=-x;
			pc('-');
		}
		if(x>9) write(x/10);
		pc(x%10+'0');
	}
	il void writeln(ll x){
		write(x);
		enter;
	}
	il void writesp(ll x){
		write(x);
		space;
	}
}
using namespace my_std;
vector<ll> vec[200020],V;
ll n,q,col[200020],f[200020][4],tree[200020],ans=0;
il ll lowbit(ll x){
	return x&(-x);
}
il void mdf(ll x,ll v){
	while(x<=n){
		tree[x]+=v;
		x+=lowbit(x);
	}
}
ll query(ll k){
	k--;
	ll x=0;
	pfr(i,18,0){
		if((x|(1ll<<i))<=n&&((1ll<<i)-tree[x+(1ll<<i)])<=k){
			k-=(1ll<<i)-tree[x+(1ll<<i)];
			x|=1ll<<i;
		}
	}
	return x+1;
}
il void solve(ll x){
	if(col[x]||vec[x].empty()){
		fr(o,0,3){
			ll now=o;
			fr(i,0,(ll)vec[x].size()-1){
				ll tmp=f[vec[x][i]][now];
				if(tmp<2) now|=1ll<<tmp;
				else{
					tmp=query(tmp-1)+1;
					mdf(tmp-1,1);
					V.push_back(tmp-1);
				}
			}
			if(now<3) f[x][o]=now&1;
			else f[x][o]=query(1)+1;
			fr(i,0,(ll)V.size()-1) mdf(V[i],-1);
			V.clear();
		}
	}
	else{
		fr(o,0,3){
			ll now=o;
			fr(i,0,(ll)vec[x].size()-1){
				ll tmp=f[vec[x][i]][now];
				now=(bl)tmp+1;
			}
			f[x][o]=now&1;
		}
	}
}
int main(){
	n=read();
	fr(i,1,n) col[i]=read();
	fr(i,1,n){
		ll m=read();
		while(m--){
			ll x=read();
			vec[i].push_back(x);
		}
		reverse(vec[i].begin(),vec[i].end());
	}
	pfr(i,n,1) solve(i);
	q=read();
	while(q--){
		ll x=read();
		ans^=f[x][0];
	}
	if(ans) pf("Alice");
	else pf("Bob");
}
/*
6
0 1 0 0 1 0
2 2 6
3 3 4 5
0
0
0
0
1
1
ans:
Bob
*/

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 5
Accepted
time: 3ms
memory: 12980kb

input:

1000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

Alice

result:

ok "Alice"

Test #2:

score: 0
Accepted
time: 2ms
memory: 12424kb

input:

1000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

Bob

result:

ok "Bob"

Test #3:

score: 0
Accepted
time: 2ms
memory: 12356kb

input:

1000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

Alice

result:

ok "Alice"

Test #4:

score: -5
Wrong Answer
time: 3ms
memory: 13248kb

input:

10
0 0 0 0 0 0 0 0 0 0
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
0
1
1

output:

Alice

result:

wrong answer 1st words differ - expected: 'Bob', found: 'Alice'

Subtask #2:

score: 0
Wrong Answer

Test #18:

score: 15
Accepted
time: 3ms
memory: 13500kb

input:

7
0 0 1 1 0 1 1
1 2
2 3 4
0
2 5 6
0
1 7
0
1
1

output:

Bob

result:

ok "Bob"

Test #19:

score: 0
Accepted
time: 0ms
memory: 13144kb

input:

6
0 1 0 0 1 0
2 2 6
3 3 4 5
0
0
0
0
1
1

output:

Bob

result:

ok "Bob"

Test #20:

score: 0
Accepted
time: 0ms
memory: 12432kb

input:

3
0 1 0
1 2
1 3
0
1
1

output:

Bob

result:

ok "Bob"

Test #21:

score: -15
Wrong Answer
time: 3ms
memory: 13356kb

input:

10
1 1 1 1 1 1 1 1 1 1
1 2
4 3 5 7 8
1 4
0
1 6
0
0
1 9
1 10
0
1
1

output:

Bob

result:

wrong answer 1st words differ - expected: 'Alice', found: 'Bob'

Subtask #3:

score: 0
Wrong Answer

Test #55:

score: 15
Accepted
time: 2ms
memory: 12820kb

input:

7
0 0 1 1 0 1 1
1 2
2 3 4
0
2 5 6
0
1 7
0
1
1

output:

Bob

result:

ok "Bob"

Test #56:

score: 0
Accepted
time: 2ms
memory: 13272kb

input:

6
0 1 0 0 1 0
2 2 6
3 3 4 5
0
0
0
0
1
1

output:

Bob

result:

ok "Bob"

Test #57:

score: 0
Accepted
time: 0ms
memory: 11808kb

input:

3
0 1 0
1 2
1 3
0
1
1

output:

Bob

result:

ok "Bob"

Test #58:

score: -15
Wrong Answer
time: 0ms
memory: 12396kb

input:

10
1 1 1 1 1 1 1 1 1 1
1 2
4 3 5 7 8
1 4
0
1 6
0
0
1 9
1 10
0
1
1

output:

Bob

result:

wrong answer 1st words differ - expected: 'Alice', found: 'Bob'

Subtask #4:

score: 0
Wrong Answer

Test #103:

score: 0
Wrong Answer
time: 2ms
memory: 13080kb

input:

10
1 1 1 1 1 1 1 1 1 1
1 2
4 3 5 7 8
1 4
0
1 6
0
0
1 9
1 10
0
1
1

output:

Bob

result:

wrong answer 1st words differ - expected: 'Alice', found: 'Bob'

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%