比赛 NOIP水题赛2 评测结果 AAAAAAAAAA
题目名称 AACA(无题面) 最终得分 100
用户昵称 胡嘉兴 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2018-11-03 15:59:45
显示代码纯文本
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5+7, p = 998244353;
ll m;
void add(ll & a, ll b)
{
	a += b;
	a %= p;
	return;
}
ll lowbit(ll x)
{
	return (x&-x);
}
ll get_ans(ll t)
{
	return t >= 0 ? t/m+1 : 0;
}
ll calc(ll a, ll b)
{
    ll ret = 0;
	for(ll i = a; i; i -= lowbit(i))
	{
		for(ll j = b; j; j -= lowbit(j))
		{
			ll x = lowbit(i);
			ll y = lowbit(j);
			ll l = (i^j^x^y);
			l &= (~(max(x, y)-1));
			ll r = l+max(x, y)-1;
			ret = (ret+(get_ans(r)-get_ans(l-1))%p*(min(x, y)%p))%p;
		}
	}
	return ret;
}
int main()
{
	ll l1, r1, l2, r2;
	freopen("AACA.in", "r", stdin);
    freopen("AACA.out", "w", stdout);
	scanf("%lld%lld%lld%lld%lld", &l1, &r1, &l2, &r2, &m);
	printf("%lld\n", (calc(r1+1, r2+1)+calc(l1, l2)-calc(r1+1, l2)-calc(l1, r2+1)+(ll)p*p)%p);
}