fork download
  1. #include <bits/stdc++.h>
  2. using namespace std ;
  3.  
  4. #define ll long long
  5. #define ull unsigned long long
  6. #define fastio ios_base::sync_with_stdio(0)
  7.  
  8. ll n, m, k, x[15], y[15], u[15], v[15], X, Y, U, V, kq = 0, mod = 1e9 + 7 ;
  9. bool b[15] ;
  10.  
  11. ll f(ll l, ll r) {
  12. return ((r * (r + 1) / 2) % mod - (l * (l - 1) / 2) % mod + mod) % mod ;
  13. }
  14.  
  15. ll sum(ll x, ll y, ll u, ll v) {
  16. return f(x, u) * f(y, v) ;
  17. }
  18.  
  19. bool intersect(ll x1, ll y1, ll u1, ll v1, ll x2, ll y2, ll u2, ll v2) {
  20. if(u1 < x2 || u2 < x1) return 0 ;
  21. if(v1 < y2 || v2 < y1) return 0 ;
  22. X = max(x1, x2) ;
  23. U = min(u1, u2) ;
  24. Y = max(y1, y2) ;
  25. V = min(v1, v2) ;
  26. return 1 ;
  27. }
  28.  
  29. void kt() {
  30. X = 1, Y = 1, U = n, V = m ;
  31. ll cnt = 0 ;
  32. for(ll i = 1; i <= k; i ++) {
  33. if(b[i] == 0) continue ;
  34. cnt ++ ;
  35. if(!intersect(x[i], y[i], u[i], v[i], X, Y, U, V)) return ;
  36. }
  37. ll t = sum(X, Y, U, V) % mod ;
  38. if(cnt % 2 == 1) kq = ((kq - t) % mod + mod) % mod ;
  39. else kq = (kq + t) % mod ;
  40. }
  41.  
  42. void dequy(ll i) {
  43. if(i > k) kt() ;
  44. else {
  45. dequy(i + 1) ;
  46. b[i] = 1 ;
  47. dequy(i + 1) ;
  48. b[i] = 0 ;
  49. }
  50. }
  51.  
  52. int main() {
  53. cin >> n >> m >> k ;
  54. for(ll i = 1; i <= k; i ++) cin >> x[i] >> y[i] >> u[i] >> v[i] ;
  55. dequy(1) ;
  56. cout << kq ;
  57. }
Success #stdin #stdout 0.01s 5584KB
stdin
3 3 2
1 2 3 3
3 1 3 2
stdout
3