QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#751237#7785. Three Rectangleszhenghanyun#TL 579ms3660kbC++143.9kb2024-11-15 17:40:302024-11-15 17:40:30

Judging History

你现在查看的是最新测评结果

  • [2024-11-15 17:40:30]
  • 评测
  • 测评结果:TL
  • 用时:579ms
  • 内存:3660kb
  • [2024-11-15 17:40:30]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;

ll T, W, H, ans, a[3], b[3], c[3], d[4];

inline void addmod(ll &x) {
	(x >= mod) && (x -= mod);
}

bitset <20> tmp[20];
vector <int> vec;

int a1[3], a2[3], b1[3], b2[3];

inline bool check() {
	for (int i = 0; i < 20; ++i) {
		tmp[i].reset();
	}
	for (int i = 0; i < 3; ++i) {
		a1[i] = 0, b1[i] = 0;
		a2[i] = 0, b2[i] = 0;
		if (c[i] == 1) {
			a1[i] = 0, b1[i] = 0;
			a2[i] = a[i], b2[i] = b[i];
		}
		if (c[i] == 2) {
			a1[i] = W - a[i], b1[i] = 0;
			a2[i] = W, b2[i] = b[i];
		}
		if (c[i] == 3) {
			a1[i] = 0, b1[i] = H - b[i];
			a2[i] = a[i], b2[i] = H;
		}
		if (c[i] == 4) {
			a1[i] = W - a[i], b1[i] = H - b[i];
			a2[i] = W, b2[i] = H;
		}
		vec.emplace_back(a1[i]);
		vec.emplace_back(a2[i]);
		vec.emplace_back(b1[i]);
		vec.emplace_back(b2[i]);
	}
	vec.emplace_back(0);
	vec.emplace_back(H);
	vec.emplace_back(W);
	sort(vec.begin(), vec.end());
	vec.resize(unique(vec.begin(), vec.end()) - vec.begin());
	for (int i = 0; i < 3; ++i) {
		a1[i] = lower_bound(vec.begin(), vec.end(), a1[i]) - vec.begin();
		b1[i] = lower_bound(vec.begin(), vec.end(), b1[i]) - vec.begin();
		a2[i] = lower_bound(vec.begin(), vec.end(), a2[i]) - vec.begin();
		b2[i] = lower_bound(vec.begin(), vec.end(), b2[i]) - vec.begin();
	}
	int w = lower_bound(vec.begin(), vec.end(), W) - vec.begin();
	int h = lower_bound(vec.begin(), vec.end(), H) - vec.begin();
	for (int i = 0; i < 3; ++i) {
		for (int j = a1[i]; j < a2[i]; ++j) {
			for (int k = b1[i]; k < b2[i]; ++k) {
				tmp[j][k] = 1;
			}
		}
	}
	for (int i = 0; i < w; ++i) {
		for (int j = 0; j < h; ++j) {
			if (!tmp[i][j]) {
				return false;
			}
		}
	}
	return true;
}

inline void calc() {
	ll t = 1;
	for (int i = 0; i < 3; ++i) {
		if (!c[i]) {
			t = t * d[i] % mod;
		}
	}
	if (check()) {
		addmod(ans += t);
	}
}

inline void dfs(int u) {
	if (u == 3) {
		calc();
		return;
	}
	if (a[u] == W) {
		for (auto p: {0, 1, 3}) {
			c[u] = p;
			dfs(u + 1);
		}
	} else if (b[u] == H) {
		for (auto p: {0, 1, 2}) {
			c[u] = p;
			dfs(u + 1);
		}
	} else {
		for (auto p: {0, 1, 2, 3, 4}) {
			c[u] = p;
			dfs(u + 1);
		}
	}
}

inline void calc1(int x, int y, int z) {
	if (b[x] + b[z] >= H) {
		addmod(ans += H - 1 - b[y]);
	} else {
		int l = max(2ll, H - b[z] - b[y] + 1), r = min(H - b[y], b[x] + 1);
		if (l <= r) {
			addmod(ans += r - l + 1);
		}
	}
}

inline void calc2(int x, int y, int z) {
	if (max(b[x], b[y]) + b[z] >= H) {
		addmod(++ans);
	}
}

inline void solve() {
	cin >> W >> H;
	for (int i = 0; i < 3; ++i) {
		cin >> a[i] >> b[i];
	}
	ans = 0;
	for (int i = 0; i < 3; ++i) {
		if (a[i] == W && b[i] == H) {
			ans = 1;
			for (int j = 0; j < 3; ++j) {
				ans = ans * (W - a[j] + 1) % mod * (H - b[j] + 1) % mod;
			}
			cout << ans << "\n";
			return;
		}
	}
	if (b[0] == H && b[1] == H && b[2] == H) {
		swap(H, W);
		swap(a[0], b[0]);
		swap(a[1], b[1]);
		swap(a[2], b[2]);
	}
	if (a[0] == W && a[1] == W && a[2] == W) {
		if (b[0] + b[1] + b[2] < H) {
			cout << "0\n";
			return;
		}
		calc1(0, 1, 2);
		calc1(0, 2, 1);
		calc1(1, 0, 2);
		calc1(1, 2, 0);
		calc1(2, 0, 1);
		calc1(2, 1, 0);
		calc2(0, 1, 2);
		calc2(0, 2, 1);
		calc2(1, 0, 2);
		calc2(1, 2, 0);
		calc2(2, 0, 1);
		calc2(2, 1, 0);
		cout << ans << "\n";
		return;
	}
	for (int i = 0; i < 3; ++i) {
		d[i] = (W - a[i] + 1) % mod * (H - b[i] + 1) % mod;
		if (a[i] == W || b[i] == H) {
			d[i] -= 2;
		} else {
			d[i] -= 4;
		}
	}
	dfs(0);
	cout << ans << "\n";
}

int main() {
	#ifdef LOCAL
		assert(freopen("test.in", "r", stdin));
		assert(freopen("test.out", "w", stdout));
	#endif
	ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	cin >> T;
	while (T--) {
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3660kb

input:

5
2 2
1 1
1 1
1 1
2 2
1 1
1 2
1 2
2 2
1 1
1 2
2 1
2 2
1 2
1 2
1 2
2 2
1 2
1 2
2 1

output:

0
8
4
6
4

result:

ok 5 number(s): "0 8 4 6 4"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3592kb

input:

4
1 3
1 1
1 2
1 3
1 4
1 1
1 2
1 3
1 5
1 1
1 2
1 3
1 6
1 1
1 2
1 3

output:

6
12
14
6

result:

ok 4 number(s): "6 12 14 6"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3652kb

input:

1
1000000000 1000000000
1 1
1 1
1000000000 1000000000

output:

2401

result:

ok 1 number(s): "2401"

Test #4:

score: 0
Accepted
time: 1ms
memory: 3612kb

input:

729
999999999 111111111
111111111 111111111
111111111 111111111
111111111 111111111
999999999 111111111
111111111 111111111
222222222 111111111
111111111 111111111
999999999 111111111
111111111 111111111
111111111 111111111
333333333 111111111
999999999 111111111
111111111 111111111
444444444 111111...

output:

0
0
0
0
0
0
6
777777753
456790164
0
0
0
0
0
6
222222208
555555531
135802502
0
0
0
0
6
222222208
222222208
333333309
814814847
0
0
0
6
222222208
222222208
222222208
111111087
493827185
0
0
6
222222208
222222208
222222208
222222208
888888872
172839523
0
6
222222208
222222208
222222208
222222208
222222...

result:

ok 729 numbers

Test #5:

score: 0
Accepted
time: 119ms
memory: 3660kb

input:

5832
999999999 222222222
111111111 111111111
111111111 111111111
111111111 111111111
222222222 999999999
111111111 111111111
111111111 111111111
111111111 222222222
222222222 999999999
111111111 111111111
111111111 111111111
111111111 333333333
999999999 222222222
111111111 111111111
111111111 11111...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
413046795
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
989330902
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
565615002
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
141899102
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
718183209
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
294467309
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
87...

result:

ok 5832 numbers

Test #6:

score: 0
Accepted
time: 579ms
memory: 3596kb

input:

19683
999999999 333333333
111111111 111111111
111111111 111111111
111111111 111111111
999999999 333333333
111111111 111111111
111111111 111111111
222222222 111111111
999999999 333333333
333333333 111111111
111111111 111111111
111111111 111111111
999999999 333333333
111111111 111111111
444444444 1111...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
239292815
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
477213862
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
715134909
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
953055956
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 19683 numbers

Test #7:

score: -100
Time Limit Exceeded

input:

46656
999999999 444444444
111111111 111111111
111111111 111111111
111111111 111111111
999999999 444444444
111111111 111111111
111111111 111111111
222222222 111111111
444444444 999999999
111111111 333333333
111111111 111111111
111111111 111111111
999999999 444444444
444444444 111111111
111111111 1111...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
935528231
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
599451396
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
263374561
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result: