记录编号 351877 评测结果 AAAAAAAAAA
题目名称 删除他们! 最终得分 100
用户昵称 Gravatarjinqiu 是否通过 通过
代码语言 C++ 运行时间 0.002 s
提交时间 2016-11-16 19:43:31 内存使用 0.31 MiB
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;

int n, m, q, last, ans;

int main() {
	freopen("deleteit.in", "r", stdin);
	freopen("deleteit.out", "w", stdout);
	int i;
	cin >> n >> m >> q;
	ans = n*m;
	for(i = 1; i <= q; i++) {
		int x1, y1, x2, y2;
		int jianshao = 0;
		scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
		if(n >= x1 + 1 && n >= x2 + 1) {
			jianshao = (abs(x2 - x1) + 1)*(abs(y2 - y1) + 1);
			ans -= jianshao;
			n = ans/m;
			last = ans % m;
		}
		else if(n < max(x1 + 1, x2 + 1)) {
			jianshao = abs((n - min(x1, x2)) <= 0 ? 0 : (n - min(x1, x2)))*(abs(y2 - y1) + 1);
			if(min(x1, x2) <= n)
				jianshao += (min(last, max(y1 + 1, y2 + 1)) - min(y2, y1)) > 0 ? (min(last, max(y1 + 1, y2 + 1)) - min(y2, y1)): 0;
			ans -= jianshao;
			n = ans/m;
			last = ans % m;
		}
	}
	cout << ans << "\n";
	return 0;
}