当前位置:网站首页>Atcoder regular contest 133 d.range XOR (digital dp+ classification discussion)
Atcoder regular contest 133 d.range XOR (digital dp+ classification discussion)
2022-07-28 17:07:00 【Code92007】
subject
Given L,R,V(1<=L<=R<=1e18,0<=V<=1e18)
Please L<=l<=r<=R, And (l,r) The exclusive or sum of numbers between is exactly equal to v Of (l,r) Number of two tuples ,
The answer is right 998244353 modulus
Source of ideas
YLWang Code
Answer key
heltion Of dp Unify all situations , But I can't understand orz, Just fill this
Official explanation , It's also digital dp+ Classification of discussion
be aware [0,x] There are only four prefix XOR values ,
①x%4==0 when , by x
②x%4==1 when , by 1
③x%4==2 when , by x+1
④x%4==3 when , by 0
[l,r] Exclusive or and , That is, prefix exclusive or and sum[r]^sum[l-1]
Then points l-1 model 4 Value ,r model 4 Value ,16 There are two situations to discuss
What is more difficult to deal with are the following four situations :
①(l-1)%4=0 And r%4=0
②(l-1)%4=0 And r%4=2
③(l-1)%4=2 And r%4=0
④(l-1)%4=2 And r%4=2
rest 12 In this case ,
Or you can determine the location of an endpoint ,
Or it's like an arithmetic sequence , Can be obtained quickly
this 4 In this case , It can be reduced to one problem ,
That is, given interval [x,y], Extract two unequal numbers from the interval lb,rb(lb<rb), seek lb^rb=w Binary logarithm of (lb,rb)
there x the truth is that l-1, and y Still r
therefore , Introduce digits dp,
dp[i][j][k] It means that there is still i position , The first number is / No card upper bound , Whether the second number is the number of schemes of the upper bound of the card
One dimensional digits dp, It's usually used dfs(r)-dfs(l-1), Prefix subtraction to find the answer
The same goes for two dimensions , Because it can only control the upper bound of card or not , So the problem of the lower bound of the card is left to Rong Xu ,
Similar to two-dimensional matrix solution (l,l) To (r,r) The area of , Subtract two rectangular areas from the total area , Add back the area of the rectangle in the upper left corner

Analogy shows that , The final two-dimensional answer is solve(r,r)-2*solve(l-1,r)+solve(l-1,l-1)
Due to the fact that l-1<r, So when v=0 when , You need to extract any equal number (l-1==r) Subtract the number of ,
And because of the number dp in ,i and j It's symmetrical , It doesn't matter , So the final answer is divided by 2
Code
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10,mod=998244353,inv2=(mod+1)/2;
ll l,r,v;
int ans,a[66],b[66],dp[66][2][2];
void add(int &x,int y){
x+=y;
if(x>=mod)x-=mod;
if(x<0)x+=mod;
}
int dfs(int pos,bool lima,bool limb,ll my_v){
if(pos==-1){
return 1;
}
if(~dp[pos][lima][limb])return dp[pos][lima][limb];
int ret=0;
int upa=lima?a[pos]:1,upb=limb?b[pos]:1;
for(int i=0;i<=upa;++i){
for(int j=0;j<=upb;++j){
if(pos==0 && (i || j))continue;//l:(0,2) r:(0,2)
if(pos==1){
if((i^j) && (v%4!=3))continue;//l:0 r:2; l:2 r:0
if((i==j) && (v%4!=0))continue;//l:0 r:0; l:2 r:2
}
if((i^j) != (my_v>>pos&1))continue;
add(ret,dfs(pos-1,lima && i==upa,limb && j==upb,my_v));
}
}
dp[pos][lima][limb]=ret;
return ret;
}
int solve(ll x,ll y,ll v){
memset(a,0,sizeof a);
memset(b,0,sizeof b);
int sza=0,szb=0;
for(;x;x/=2)a[sza++]=x%2;
for(;y;y/=2)b[szb++]=y%2;
memset(dp,-1,sizeof dp);
return dfs(63,1,1,v);
}
int cal(ll lb,ll rb,int re){
if(rb<re || lb>rb)return 0;
ll nowl=0,nowr=0;
nowr=(rb-re)/4+1;
lb--;
if(lb<re)nowl=0;
else nowl=(lb-re)/4+1;
ll ans=nowr-nowl;
ans%=mod;
return (int)ans;
}
//[lb,rb] Internal extraction l<=r, bring (l^r)==v Logarithm of number , Special judgement lb=0
int cal2(ll lb,ll rb,ll v){
int ans=0;
ans=((1ll*solve(rb,rb,v)-2ll*solve(lb-1,rb,v)+solve(lb-1,lb-1,v))%mod+mod)%mod;
if(!v){//l=r illegal ,l It's practical l-1
ans=(ans-cal(lb,rb,0)+mod)%mod;
ans=(ans-cal(lb,rb,2)+mod)%mod;
}
ans=1ll*ans*inv2%mod;
return ans;
}
int main(){
scanf("%lld%lld%lld",&l,&r,&v);
if(v==0){
int three=cal(l-1,r,3);//l-1:3 r:3 C(x,2)
add(ans,1ll*(three-1)*three%mod*inv2%mod);
int one=cal(l-1,r,1);//l-1:1 r:1 C(x,2)
add(ans,1ll*(one-1)*one%mod*inv2%mod);
}
if(v==1){
int two=cal(l,r,2);
if(two){//l-1:1 r:3
ll ltwo=l;while(ltwo%4!=2)ltwo++;
int lthree=cal(ltwo,r,3);
ll rtwo=r;while(rtwo%4!=2)rtwo--;
int rthree=cal(rtwo,r,3);
add(ans,1ll*(lthree+rthree)*two%mod*inv2%mod);
}
int zero=cal(l,r,0);
if(zero){//l-1:3 r:1
ll lzero=l;while(lzero%4)lzero++;
int lone=cal(lzero,r,1);
ll rzero=r;while(rzero%4)rzero--;
int rone=cal(rzero,r,1);
add(ans,1ll*(lone+rone)*zero%mod*inv2%mod);
}
}
if(v%4==0){
if(l<=v+1 && v+1<=r){
add(ans,cal(v+1,r,3));//l-1:0 r:3
}
if(l<=v && v<=r){
add(ans,cal(l,v,0));//l-1:3 r:0
}
if(l>1)add(ans,cal2(l-1,r,v));//l-1:0 r:0 l-1:2 r:2
else add(ans,cal2(1,r,v)+(l<=v && v<=r));// Special judgement l-1=0, Split into two parts for statistics
}
if(v%4==1){
if(l<=v && v<=r){
add(ans,cal(v,r,1));//l-1:0 r:1
}
if(l<=(v^1) && (v^1)<=r){
add(ans,cal(l,v^1,2));//l-1:1 r:0
}
}
if(v%4==2){
if(l<=v && v<=r){
add(ans,cal(l,v,2));//l-1:1 r:2
}
if(l<=(v^1) && (v^1)<=r){
add(ans,cal(v^1,r,1));//l-1:2 r:1
}
}
if(v%4==3){
if(l<=v && v<=r){
add(ans,cal(v,r,3));//l-1:2 r:3
}
if(l<=(v^1) && (v^1)<=r){
add(ans,cal(l,v^1,0));//l-1:3 r:2
}
if(l>1)add(ans,cal2(l-1,r,v^1));//l-1:0 r:2;l-1:2 r:0
else add(ans,cal2(1,r,v^1)+(l<=(v^1) && (v^1)<=r));// Special judgement l-1=0, Split into two parts for statistics
}
printf("%d\n",ans);
return 0;
}边栏推荐
- Semtech launched Lora edge, a geolocation solution for the Internet of things, and the first chip lr1110 is now on the market
- 【深度学习】:《PyTorch入门到项目实战》第九天:Dropout实现(含源码)
- Ugui learning notes (VI) get the information of the clicked UI
- Is smart park the trend of future development?
- kubenertes 1.16集群部署问题总结
- Do you really understand CMS garbage collector?
- 打造自组/安全/可控的LoRa网!Semtech首度回应“工信部新规”影响
- [deep learning]: the second day of pytorch introduction to project practice: realize linear regression from zero (including detailed code)
- Android Development - set cache
- 关于 CMS 垃圾回收器,你真的懂了吗?
猜你喜欢

MySQL 5.7 and sqlyogv12 installation and use cracking and common commands

Re10: are we really making much progress? Revisiting, benchmarking, and refining heterogeneous gr

Applet: scroll view slides to the bottom by default

Binary representation of negative integers and floating point numbers
![[deep learning]: day 8 of pytorch introduction to project practice: weight decline (including source code)](/img/19/18d6e94a1e0fa4a75b66cf8cd99595.png)
[deep learning]: day 8 of pytorch introduction to project practice: weight decline (including source code)
![[deep learning]: model evaluation and selection on the seventh day of pytorch introduction to project practice (Part 1): under fitting and over fitting (including source code)](/img/19/18d6e94a1e0fa4a75b66cf8cd99595.png)
[deep learning]: model evaluation and selection on the seventh day of pytorch introduction to project practice (Part 1): under fitting and over fitting (including source code)

Re12:读论文 Se3 Semantic Self-segmentation for Abstractive Summarization of Long Legal Documents in Low
Read excel xlsx format file in unity
![[deep learning]: day 6 of pytorch introduction to project practice: multi-layer perceptron (including code)](/img/19/18d6e94a1e0fa4a75b66cf8cd99595.png)
[deep learning]: day 6 of pytorch introduction to project practice: multi-layer perceptron (including code)

Unity shader transparent effect
随机推荐
Brother Ali teaches you how to correctly understand the problem of standard IO buffer
Unity3d simple implementation of water surface shader
Huawei mate 40 series exposure: large curvature hyperboloid screen, 5nm kylin 1020 processor! There will also be a version of Tianji 1000+
2019年全球移动通信基站市场:爱立信、华为、诺基亚分列前三
Global mobile communication base station market in 2019: Ericsson, Huawei and Nokia ranked in the top three
总数据量超万亿行,玉溪卷烟厂通过正确选择时序数据库轻松应对
Binary representation of negative integers and floating point numbers
【深度学习】:《PyTorch入门到项目实战》:简洁代码实现线性神经网络(附代码)
阿里大哥教你如何正确认识关于标准IO缓冲区的问题
Ugui learning notes (VI) get the information of the clicked UI
leetcode70假设你正在爬楼梯。需要 n 阶你才能到达楼顶。每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢?
[deep learning]: day 8 of pytorch introduction to project practice: weight decline (including source code)
Leetcode9. Palindromes
我该如何理解工艺
智慧园区是未来发展的趋势吗?
【深度学习】:《PyTorch入门到项目实战》第八天:权重衰退(含源码)
kubenertes 1.16集群部署问题总结
Alibaba cloud MSE supports go language traffic protection
It is said that NVIDIA has held talks with Softbank and will offer more than US $32billion to acquire arm
Call DLL file without source code