NWU_ACM

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
 1 #include <bits/stdc++.h>
 2 #define _xx ios_base::sync_with_sdtio(0);cin.tie(0);
 3 #define INFS 0x3fffffff
 4 #define INFB 0x3fffffffffffffff
 5 #define printf pf
 6 #define scanf sf
 7 using namespace std;
 8 typedef long long ll;
 9 int orx[25][2];
10 int f, lm, rm, um, dm;
11 ll ans;
12 ll n, m, k;
13 void dfs(int i)
14 {
15 
16     if(i == k)
17     {
18         if(f == 0) return;
19         ll cnt = lm*um*(n - dm + 1)*(m - rm + 1);
20         ans = ans + (f%2 == 1 ? -cnt : cnt);
21         return;
22     }
23     dfs(i + 1);
24     int tlm = lm, trm = rm, tum = um, tdm = dm;
25     lm = min(orx[i][1], lm);
26     um = min(orx[i][0], um);
27     rm = max(orx[i][1], rm);
28     dm = max(orx[i][0], dm);
29     f++;
30     dfs(i + 1);
31     lm = tlm;
32     rm = trm;
33     um = tum;
34     dm = tdm;
35     f--;
36     return;
37 }
38 int main()
39 {
40     int T;
41     cin >> T;
42     while(T--)
43     {
44         cin >> n >> m >> k;
45         for(int i = 0; i < k; i++) cin >> orx[i][0] >> orx[i][1];
46         f = 0;
47         ans = n*(n + 1)*m*(m + 1)/4;
48         lm = m;
49         um = n;
50         rm = 0;
51         dm = 0;
52         dfs(0);
53         cout << ans << endl;
54 
55     }
56 
57     return 0;
58 }
View Code

 

posted on 2017-04-23 22:17  NWU_ACM  阅读(144)  评论(0编辑  收藏  举报