QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#385200#3768. 矩形并秦始皇派蒙恬还原神舟十二 (Jiancong Wen, Chu Jin, Zekai Zhang)AC ✓4ms3700kbC++171.4kb2024-04-10 16:22:462024-04-10 16:22:47

Judging History

This is the latest submission verdict.

  • [2024-04-10 16:22:47]
  • Judged
  • Verdict: AC
  • Time: 4ms
  • Memory: 3700kb
  • [2024-04-10 16:22:46]
  • Submitted

answer

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#define Buff ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;

inline ll Qpower(ll x, ll y)
{
	ll z = 1;
	while(y > 0)
	{
		if(y & 1)
			z = (z * x) % mod;
		y >>= 1;
		x = (x * x) % mod;
	}
	return z;
}



inline ll C(ll n, ll m)
{
	static ll md = Qpower(2, mod - 2);
	ll n1 = n + 1;
	ll n2 = (n1 % mod) * (n % mod) % mod;
	n2 *= md;
	n2 %= mod;

	ll m1 = m + 1;
	ll m2 = (m1 % mod) * (m % mod) % mod;
	m2 *= md;
	m2 %= mod;

	m2 = n2 * m2 % mod;
	return m2;
}

void solve()
{
	ll a, b, x1, x2, y1, y2;

	while(cin >> a >> b >> x1 >> x2 >> y1 >> y2)
	{
		ll ans = C(a, b);

		ans = (ans + ((a * b % mod) * (x2 - x1) % mod * (y2 - y1) % mod)) % mod;

		if(x1 < a && y1 < b)
		{
			ll x = a - x1;
			ll y = b - y1;
			ll d = C(x, y);
			ans = (ans - d + mod) % mod;
			if(a > x2)
			{
				ll xx = a - x2;
				ll d1 = C(xx, y);
				ans = (ans + d1) % mod;
			}
			if(b > y2)
			{
				ll yy = b - y2;
				ll d2 = C(x, yy);
				ans = (ans + d2) % mod;
				if(a > x2)
				{
					ll x3 = a - x2;
					ll d3 = C(x3, yy);
					ans = (ans - d3 + mod) % mod;
				}
			}
		}
		cout << ans << "\n";
	}
}

int main()
{
	Buff;
	int N = 1;
	//cin >> N;
	while(N--)
		solve();
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 4ms
memory: 3700kb

input:

1 1
2 3 2 3
10 10
1 5 1 5
1000000000 1000000000
1 1000000000 1 1000000000
1 2
2 5 1 4
2 5
1 5 2 4
1 4
3 4 1 5
2 3
1 4 2 4
5 3
1 4 1 2
5 2
3 5 4 5
3 2
3 5 1 4
5 3
4 5 1 3
5 5
1 5 2 5
4 4
1 5 2 5
1 2
1 5 3 5
3 4
3 4 1 2
2 2
1 4 1 3
3 1
1 4 1 4
2 4
1 5 2 5
4 2
2 3 3 5
1 3
1 2 1 2
2 4
1 3 1 5
5 2
2 3 2 ...

output:

2
3725
2793
21
120
26
53
117
65
54
117
465
274
19
72
32
33
123
46
9
88
65
36
252
83
159
17
330
261
186
84
26
45
34
75
34
65
30
88
107
12
105
38
46
15
85
29
55
78
55
96
17
39
60
20
17
56
45
5
18
96
30
25
108
146
114
65
19
192
51
17
42
54
132
110
75
42
75
66
150
7
7
173
33
95
75
294
45
247
25
35
110
2...

result:

ok 10000 lines