QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#770859 | #9745. 递增序列 | liuhuahua# | WA | 50ms | 3804kb | C++14 | 1.7kb | 2024-11-22 00:55:56 | 2024-11-22 00:55:57 |
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;
while(T--){
scanf("%lld%lld",&n,&k);
for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
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: 3804kb
input:
1 4 17 3 2 5 16
output:
4
result:
ok single line: '4'
Test #2:
score: -100
Wrong Answer
time: 50ms
memory: 3632kb
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 2 1 0 811009189367843523 0 1 0 114457959388827198 36028797018963968 0 274363960091065218 91540211282631659 2 694703231769895640 144115188075855872 0 1 1 288230376151711744 432345564227567616 653331529621...
result:
wrong answer 8th lines differ - expected: '0', found: '2'