E. Height All the Same

### 题目大意

• 选择相邻的两个方格并在每个方格上面放置一个立方体
• 选择一个人方格并在这个方格上放置两个立方体

### 解题思路

• 如果$$n * m$$是奇数，那么奇数和偶数中一定有一个的数量是偶数，答案直接就是 $$(R - L + 1)^{n * m}$$
• 如果是偶数，则需要计算，利用组合数学得出$$\sum_{i = 0}^{n * m} C_{n * m}^i * x^i * y^{(n * m - i)} * [i \% 2 = 0]$$

$$(x + y)^{n*m} = \sum_{i = 0}^{n * m} C_{n * m}^{i} x^i * y^{(n *m - i)}$$

$$n *m$$是奇数时，$$ans = (R - L + 1)^{n * m}$$

### Code

#include <bits/stdc++.h>
#define ll long long
#define qc ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define fi first
#define se second
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define pb push_back
#define V vector
using namespace std;
const int N = 2e5 + 7;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll mod = 998244353;

inline char nc() {
static char buf[1000000], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++;
}
template <typename _Tp> inline void read(_Tp&sum) {
char ch = nc(); sum = 0;
while (!(ch >= '0'&&ch <= '9')) ch = nc();
while (ch >= '0'&&ch <= '9') sum = (sum << 3) + (sum << 1) + (ch - 48), ch = nc();
}

ll n,m,l,r;

ll ksm(ll x,ll y)
{
ll p = 1;
while(y)
{
if(y & 1)p = p * x % mod;
x = x * x % mod;
y >>= 1;
}
return p;
}

void solve(){
if((n * m) & 1){
printf("%lld\n",ksm((r - l + 1), n * m));
}else{
ll x = 0, y = 0;
if((l & 1) && (r & 1)){
x = (r - l) / 2;
y = (r - l) / 2 + 1;
}else if(!(l & 1) && !(r & 1)){
x = (r - l) / 2 + 1;
y = (r - l) / 2;
}else{
x = y = (r - l + 1) / 2;
}
printf("%lld\n",((ksm(abs(x - y), n * m) + ksm(x + y, n * m)) % mod) * ksm(2ll, mod - 2) % mod);
}
}

int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif

int T = 1;
// scanf("%d",&T);
while(T--){
solve();
}
return 0;
}

Code will change the world !