QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#291932 | #4896. Alice、Bob 与 DFS | do_while_true | 0 | 0ms | 0kb | C++20 | 2.9kb | 2023-12-27 14:03:22 | 2023-12-27 14:03:22 |
answer
#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<random>
#include<assert.h>
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define dbg(x) cerr<<"In Line "<< __LINE__<<" the "<<#x<<" = "<<x<<'\n'
#define dpi(x,y) cerr<<"In Line "<<__LINE__<<" the "<<#x<<" = "<<x<<" ; "<<"the "<<#y<<" = "<<y<<'\n'
#define DE(fmt,...) fprintf(stderr, "Line %d : " fmt "\n",__LINE__,##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef pair<ll,int>pli;
typedef pair<ll,ll>pll;
typedef pair<int,ll>pil;
typedef vector<int>vi;
typedef vector<ll>vll;
typedef vector<pii>vpii;
typedef vector<pll>vpll;
template<typename T>T cmax(T &x, T y){return x=x>y?x:y;}
template<typename T>T cmin(T &x, T y){return x=x<y?x:y;}
template<typename T>
T &read(T &r){
r=0;bool w=0;char ch=getchar();
while(ch<'0'||ch>'9')w=ch=='-'?1:0,ch=getchar();
while(ch>='0'&&ch<='9')r=r*10+(ch^48),ch=getchar();
return r=w?-r:r;
}
template<typename T1,typename... T2>
void read(T1 &x,T2& ...y){read(x);read(y...);}
const int N=400010;
const int M=400001;
int n,m;
int c[N],f[N][4];
vi eg[N];
int tree[N],ok[N];
inline int lowbit(int x){return x&(-x);}
void modify(int x,int v){
if(v==1)ok[x]=1;
++x;
for(;x<=M;x+=lowbit(x))tree[x]+=v;
}
int kth(int k){
int x=0;--k;
for(int i=18;~i;--i){
int p=(1<<i);
if(x+p<=M && k>=p-tree[x+p])
k-=p-tree[x+p],x+=p;
}
return x;
}
signed main(){
// #ifdef do_while_true
// assert(freopen("data6.in","r",stdin));
assert(freopen("Genshin_lmpact.in","r",stdin));
assert(freopen("Genshin_lmpact.out","w",stdout));
// #endif
read(n);
for(int i=1;i<=n;i++)read(c[i]);
for(int i=1;i<=n;i++){
int k;read(k);
for(int j=1;j<=k;j++){
int x;read(x);
eg[i].pb(x);
}
reverse(eg[i].begin(),eg[i].end());
if(eg[i].empty())c[i]=1;
}
for(int x=n;x>=1;x--)
for(int i=0;i<4;i++)
if(c[x]){
vi vec;
int now=i;
if(now&1)modify(0,1),vec.pb(0);
if(now&2)modify(1,1),vec.pb(1);
for(auto v:eg[x]){
now=ok[0]|(ok[1]<<1);
int w=0;
if(c[v]==0)w=f[v][now];
else w=kth(f[v][now]+1-ok[0]-ok[1]);
if(!ok[w]){
modify(w,1);
vec.pb(w);
}
}
f[x][i]=kth(1);
for(auto w:vec)ok[w]=0,modify(w,-1);
}
else{
int now=i;
for(auto v:eg[x]){
if(f[v][now]==0)now=1;//new S={0}
else now=2;//new S={1}
}
f[x][i]=now==2?0:1;
}
// for(int i=1;i<=n;i++){
// cout<<f[i][0]<<' '<<f[i][1]<<' '<<f[i][2]<<' '<<f[i][3]<<'\n';
// }
int q,s=0;read(q);
while(q--){
int x;read(x);
s^=f[x][1];
}
if(s)puts("Alice");
else puts("Bob");
#ifdef do_while_true
// cerr<<'\n'<<"Time:"<<1.0*clock()/CLOCKS_PER_SEC*1000<<" ms"<<'\n';
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
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:
result:
Subtask #2:
score: 0
Runtime Error
Test #18:
score: 0
Runtime Error
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:
result:
Subtask #3:
score: 0
Runtime Error
Test #55:
score: 0
Runtime Error
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:
result:
Subtask #4:
score: 0
Runtime Error
Test #103:
score: 0
Runtime Error
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:
result:
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
0%