提交时间:2022-07-19 12:12:01

运行 ID: 52442

#include<bits/stdc++.h> #define ll long long #define mid (l+r>>1) using namespace std; const ll mod=1e9+7; inline ll read(){ ll x=0,f=1,c=getchar(); while(c<'0'||c>'9')f=(c=='-'?-1:1),c=getchar(); while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar(); return x*f; } ll n; inline ll calc(register ll x){ register ll l=0,r=n-1,resl=0,resr=1,reslmid=3,resrmid=2,ans; while(1){ if(x==mid){ans=reslmid;break;} if(x==(mid+1)){ans=resrmid;break;} if(x==l){ans=resl;break;} if(x==r){ans=resr;break;} if(x<mid)r=mid,resr=reslmid,reslmid=((resl+resr+1)<<1)-resl-1,resrmid=((resl+resr+1)<<1)-resr-1; else if(x>mid) l=mid+1,resl=resrmid,reslmid=((resl+resr+1)<<1)-resl-1,resrmid=((resl+resr+1)<<1)-resr-1; } return ans; } inline ll F(register ll l,register ll r){ if(l%2==1&&r%2==1)return calc(l)+((n-1)*(r-l)>>1); if(l%2==1&&r%2==0)return calc(l)+calc(r)+((n-1)*(r-l-1)>>1); if(l%2==0&&r%2==1)return (((r-l+1)%4)?(n-1):0); if(l%2==0&&r%2==0)return (calc(r)^(((r-l)%4)?(n-1):0)); } int main(){ register ll k=read(),m=read(),l=read(),r=read(),h=0,a=read(),b=read(),c=read(); n=(1ll<<k); for(register int i=1;i<=m;i++){ h=((l^r^h^F(l,r))+c)%mod; l=((l^a^h)%(n+1))%n; r=((r^b^h)%(n-l))+l; } printf("%lld",h); } /* 3 709193 4 5 273035200 65685838 991992535 */