QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#770882 | #9745. 递增序列 | liuhuahua# | WA | 49ms | 3736kb | C++14 | 1.8kb | 2024-11-22 01:10:39 | 2024-11-22 01:10:39 |
Judging History
answer
#include<bits/stdc++.h>
#define N 200005
#define ll long long
using namespace std;
ll T,n,k,a[N],c[65],ans;
void solve(int k,int l,int r){
if(k==-1)return;
int mid=-1;
if(c[k]==-1)return;
for(int i=l+1;i<=r;i++){
if((a[i]&(1ll<<k))!=(a[i-1]&(1ll<<k))){
if(mid==-1)mid=i-1;
else{
c[k]==-1;
return;
}
}
}
if(mid==-1){
if(c[k]==0)c[k]=3;
solve(k-1,l,r);
}else if(a[mid]&(1ll<<k)){
if(c[k]==0)c[k]=2;
else if(c[k]==1)c[k]=-1;
else if(c[k]==3)c[k]=2;
solve(k-1,l,mid),solve(k-1,mid+1,r);
}else{
if(c[k]==0)c[k]=1;
else if(c[k]==2)c[k]=-1;
else if(c[k]==3)c[k]=1;
solve(k-1,l,mid),solve(k-1,mid+1,r);
}
}
ll sum(int now){
// cout<<now<<"!!";
ll res=1;
for(int i=now-1;i>=0;i--)if(c[i]==3)res=2ll*res;
// cout<<res<<"??";
return res;
}
void dfs(int now){
if(now==-1){
ans++;
return;
}
if(k&(1ll<<now)){
if(c[now]==1)ans+=sum(now);
else if(c[now]==2)dfs(now-1);
else ans+=sum(now),dfs(now-1);
}else{
if(c[now]==1)dfs(now-1);
else if(c[now]==3)dfs(now-1);
}
}
int main(){
cin>>T;
int op=0;
while(T--){
scanf("%lld%lld",&n,&k);
op++;
for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
if(op==8){
for(int i=1;i<=n;i++)cout<<a[i]<<" ";
cout<<k<<"!!";
}
memset(c,0,sizeof(c));
solve(61,1,n);
bool fl=1;
for(int i=61;i>=0;i--)if(c[i]==-1)fl=0;
// for(int i=61;i>=0;i--){
// cout<<c[i]<<" ";
// }
if(!fl){
puts("0");
continue;
}ans=0;
dfs(61);
cout<<ans<<"\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3736kb
input:
1 4 17 3 2 5 16
output:
4
result:
ok single line: '4'
Test #2:
score: -100
Wrong Answer
time: 49ms
memory: 3712kb
input:
36156 2 732025001343805266 563399128172323734 55283226774627822 7 388099190813067712 564150557919527813 457487771983557281 332055400678110195 760833651510929158 785768483273197875 690506113272551236 463276585748519124 2 798714574862593347 426890163990834364 434764725667883272 1 414708220571820990 42...
output:
288230376151711744 0 432345564227567616 414708220571820991 716398192192370638 0 1949654914769744 875439337127111837 915410680618070406 902383077856448367 429672369988611652 464260354103640857 645644829517442561 676851664028947387 341018344971465954 341986276568351378 467144025649476467 9210933705470...
result:
wrong answer 8th lines differ - expected: '0', found: '875439337127111837 91541068061...649476467 921093370547076680!!2'