标签:mes using const mit get pac string sts 方向
化成了一维。然后就是逆元预处理的话会快一倍。
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
const ll NN = 1e7 + 99;
const ll N = 2e6 + 99;
const ll mod = 1e9 + 7;
const ll maxn = 1e7;
ll fac[N];
ll inv_fac[N];
ll q_pow(ll a, ll k) {
ll ret = 1;
ll x = a;
while (k) {
if (k & 1) (ret *= x) %= mod;
k >>= 1;
(x *= x) %= mod;
}
return ret;
}
ll inv(ll a) { return (q_pow(a, mod - 2) % mod + mod) % mod; }
void init() {
fac[0] = 1;
inv_fac[0] = 1;
fac[1] = 1;
for (ll i = 1; i < N; i++) {
fac[i] = fac[i - 1] * i % mod;
inv_fac[i] = inv(fac[i]);
}
}
ll C(ll n, ll m) { return fac[n] * inv_fac[m] % mod * inv_fac[n - m] % mod; }
void solve() {
ll sum = 0;
ll c1, c2, r1, r2;
cin >> r1 >> c1 >> r2 >> c2;
for (int i = r1; i <= r2; i++) {
sum = (sum +
((C(i + 1 + c2, i + 1) - C(i + c1, i + 1)) % mod + mod) % mod) %
mod;
}
cout << sum % mod << endl;
}
signed main() {
ios::sync_with_stdio(0);
init();
ll t = 1;
while (t--) solve();
return 0;
}
AT5295 [ABC154F] Many Many Paths
标签:mes using const mit get pac string sts 方向
原文地址:https://www.cnblogs.com/Xiao-yan/p/14603314.html