QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#764994 | #5024. 【模板】双端队列 | ANIG | 60 | 466ms | 27852kb | C++14 | 1.2kb | 2024-11-20 11:33:31 | 2024-11-20 11:33:33 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+5;
unordered_map<int,int>f[N][2];
int t,n,p[N],qz[N],hz[N],sm[N];
int solve(int l,int r,int op){
if(l>r)return op;
if(f[l][op].count(r))return f[l][op][r];
if((op^qz[l-1]^hz[r+1])==op){
if((r-l+1)%2==0)return 1;
else if(sm[r]-sm[l-1]>>1&1^op)return 0;
int res=0;
if(p[l])res|=solve(l+1,r,qz[l-1]^hz[r+1]^op)^1;
if(res)return f[l][op][r]=res;
if(p[r])res|=solve(l,r-1,qz[l-1]^hz[r+1]^op)^1;
return f[l][op][r]=res;
}else{
if((r-l+1)%2==0&&sm[r]-sm[l-1]>>1&1^op)return 0;
int res=0;
res|=(solve(l+1,r,qz[l-1]^hz[r+1]^op)^1);
if(res)return f[l][op][r]=res;
return f[l][op][r]=solve(l,r-1,qz[l-1]^hz[r+1]^op)^1;
}
}
signed main(){
cin>>t;
while(t--){
cin>>n;
int he=0;
for(int i=1;i<=n;i++)cin>>p[i],he^=p[i],f[i][0].clear(),f[i][1].clear();
if(!he){
cout<<"Draw\n";
continue;
}
int t=__lg(he);
for(int i=1;i<=n;i++){
p[i]=p[i]>>t&1;
qz[i]=qz[i-1]^p[i];
sm[i]=sm[i-1]+p[i];
}
hz[n+1]=0;
for(int i=n;i>=1;i--){
hz[i]=hz[i+1]^p[i];
}
if(solve(1,n,0))cout<<"First\n";
else cout<<"Second\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 15
Accepted
Test #1:
score: 15
Accepted
time: 2ms
memory: 16068kb
input:
40 15 1042186166 1065050038 1052442342 117744385 1044381358 996146407 947617159 1031691934 27328777 130294601 1065311743 1065082111 12845136 941620871 1042177446 15 1068465534 15766217 69219008 95461385 1048542590 1051709438 1048575351 1072652151 978275647 1044381687 999247358 1062194999 1054829887 ...
output:
Second Second Second First First Second Second Draw Draw Draw Draw Second Second Second Second First First Draw Second Second Second Draw Second Draw Draw First Second Second Draw Second First First Second Second First First Second First First Draw
result:
ok 40 tokens
Subtask #2:
score: 20
Accepted
Test #2:
score: 20
Accepted
time: 183ms
memory: 27852kb
input:
40 987 1073733087 9437225 570431533 1031755263 1031755251 579873284 571521061 536872960 546353705 43000364 535780827 1065313790 536834043 41953824 503270871 1040175099 8426021 537960961 1054732 545292837 34648585 34603052 546314244 537965060 9439748 41953292 43037189 9447949 536864767 1073698294 503...
output:
Second Second First Second First Second Second First Second First Draw First Second First First Second Second Second Draw Draw Draw Draw First Second Second Second Second First Second Second Draw Second First Second First Draw Second First First First
result:
ok 40 tokens
Test #3:
score: 20
Accepted
time: 171ms
memory: 26832kb
input:
40 985 1051584087 161093905 991143886 498485632 221004168 788260831 916059871 274356401 213536945 95177001 98458032 869773278 787854966 1051043535 603582199 3672200 216942729 975171167 93067289 603832174 292948248 602275551 354556312 4589841 22567337 428083233 89540913 589692543 361906352 77353112 9...
output:
Second First Draw Second First Second Draw First First Second First Draw First First Draw Second First Second Second Draw First First First Second Second Second Draw First Second Second First Second First Second First First Second First First First
result:
ok 40 tokens
Subtask #3:
score: 25
Accepted
Test #4:
score: 25
Accepted
time: 466ms
memory: 17728kb
input:
40 49999 30704571 23631198 10459697 452884 909025 3745220 5633170 29257098 24428644 21991837 21100897 21249665 18667093 13809790 21220831 32750672 29531337 31709216 17139349 4444339 787544 14509794 3855820 201034 13281440 26541636 31476242 10318360 20485824 26793325 8264891 22349828 20554718 7556006...
output:
Second First Second Second First Second Second First Second Second Second First First First Second Second Second Second First First Second Second Second Second First First Second First Second First First First First Second First Second First First First First
result:
ok 40 tokens
Test #5:
score: 25
Accepted
time: 459ms
memory: 17228kb
input:
40 50000 32128601 23900639 9898059 10642201 2516432 19994626 8905808 23168114 27093651 32766595 7092623 14455293 32272254 11330578 25018676 9383756 16276912 15628227 6205425 11630483 19952395 19133325 22760569 7587885 30335157 13910732 11179526 4266775 18282905 14622912 11401940 33485172 9826535 292...
output:
First Second First First Second Second Second Second Second First Second First First First First Second First Second First First First Second First First First Second First First Second Second Second First First First First First First Second First Second
result:
ok 40 tokens
Subtask #4:
score: 0
Time Limit Exceeded
Test #6:
score: 0
Time Limit Exceeded
input:
40 49035 1073176430 531291499 1005508607 675350672 368768 867368831 139504132 1321089 134482448 464248170 1068169195 68946580 469491567 738764816 742459920 535197167 531887598 672172545 609558673 608209040 335282031 532674543 72878741 610117777 138447508 398155759 71608464 672172165 402325355 609845...