提交时间:2022-07-19 11:51:43

运行 ID: 52286

#include<cstdio> #include<map> using namespace std; typedef long long ll; const ll mod=1e9+7; int k; int m,l0,r0; int a,b,c; ll n,n2; //a[0]=0,a[2^k-1]=1,a[2^(k-1)]=2,a[2^(k-1)-1]=3 //a[2^(k-1)-i]=(i&1)?2*i+1:2*i //a[2^(k-1)+i]=(i&1)?2*i+3:2*i+2 map<ll,ll> mp; inline ll cal(ll x){ if(x==0) return 0; if(x==n-1) return 1; if(x<n2){ ll i=n2-x; return (i&1)?2*i+1:2*i; } else{ ll i=x-n2; return (i&1)?2*i+3:2*i+2; } } inline ll f(ll l,ll r){ if(mp[l*n+r]) return mp[l*n+r]; ll s=0; if(l&1){ s+=cal(l); for(ll i=l+1;i<=r;i+=2){ if(i<r) s+=cal(i)^cal(i+1); else s+=cal(i); } } else{ for(ll i=l;i<=r;i+=2){ if(i<r) s^=cal(i)+cal(i+1); else s^=cal(i); } } if(r-l>=100000) mp[l*n+r]=s; return s; } int main(){ scanf("%d",&k); n=(1ll<<k); n2=(1ll<<(k-1)); // for(int i=0;i<n;++i){ // for(int j=i;j<n;++j) // printf("%3lld ",f(i,j)); // puts(""); // } scanf("%d%d%d",&m,&l0,&r0); scanf("%d%d%d",&a,&b,&c); ll l=l0,r=r0,h=0; for(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\n",h); return 0; }