提交时间:2022-07-19 14:53:39
运行 ID: 52624
#include <bits/stdc++.h> #define int long long using namespace std; int m,k,a,b,c,n,t,s,q[2000010],h[50000010],l[50000010],r[50000010]; vector <int> v[2000010]; int f(int x,int y) { if(!(x & 1)) { int sum = 0,ret = 0; for(int i = x; i <= y; i++) { sum += q[i]; if((i - x) & 1) { ret ^= sum; sum = 0; } } ret ^= sum; return ret; } else { int ret = q[x],yh = 0; for(int i = x + 1; i <= y; i++) { yh ^= q[i]; if(!((i - x) & 1)) { ret += yh; yh = 0; } } ret += yh; return ret; } } signed main() { scanf("%lld",&k); scanf("%lld%lld%lld",&m,&l[0],&r[0]); scanf("%lld%lld%lld",&a,&b,&c); n = (1 << k); for(int i = 0; i < n; i++) v[i].push_back(i); for(int i = k - 1; i >= 0; i--) { t = (1 << i); s = (1 << (k - i - 1)); for(int j = 1; j <= t; j++) for(int w = s - 1; w >= 0; w--) v[t - j].push_back(v[t + j - 1][w]); } for(int i = 0; i < n; i++) q[i] = v[0][i]; for(int i = 1; i <= m; i++) { h[i] = ((h[i - 1] ^ l[i - 1] ^ r[i - 1] ^ f(l[i - 1],r[i - 1])) + c) % 1000000007; l[i] = ((l[i - 1] ^ a ^ h[i]) % (n + 1)) % n; r[i] = ((r[i - 1] ^ b ^ h[i]) % (n - l[i])) + l[i]; } printf("%lld\n",h[m]); return 0; }