Advertisement
GerONSo

Untitled

Nov 24th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. /*
  2. --┬-- | | --┬-- | |
  3. | |\ | | | |
  4. | | \ | | -----> | |
  5. | | \ | | | |
  6. | | \ | | | |
  7. --┴-- | \| | └---- └----
  8.  
  9. */
  10.  
  11. // #define pragma
  12.  
  13. #ifdef pragma
  14. #pragma GCC optimize("Ofast")
  15. #pragma GCC optimize("no-stack-protector")
  16. #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  17. #pragma GCC optimize("unroll-loops")
  18. #pragma GCC diagnostic ignored "-Wunused-result"
  19. #endif // pragma
  20.  
  21. #include<bits/stdc++.h>
  22. #include <ext/pb_ds/assoc_container.hpp>
  23. #include <ext/pb_ds/tree_policy.hpp>
  24.  
  25. #define ll long long
  26. #define all(x) begin(x), end(x)
  27. #define pb push_back
  28. // #define x first
  29. // #define y second
  30. #define int long long
  31. #define zero(x) memset(x, 0, sizeof(x))
  32.  
  33. using namespace std;
  34. using namespace __gnu_pbds;
  35.  
  36.  
  37. typedef vector<int> vi;
  38. typedef vector<bool> vb;
  39. typedef pair<int, int> pii;
  40. typedef long double ld;
  41. typedef vector<vi> matrix;
  42. typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
  43.  
  44. const int INF = 1e9 + 7;
  45. const ld EPS = 1e-9;
  46. const ld PI = atan2(0, -1);
  47.  
  48. void seriy() {
  49. ios::sync_with_stdio(0);
  50. cin.tie(0);
  51. cout.tie(0);
  52. cout << fixed << setprecision(7);
  53. cerr << fixed << setprecision(7);
  54. #if 1
  55. freopen("input", "r", stdin);
  56. freopen("output", "w", stdout);
  57. #endif
  58. }
  59.  
  60. int x, y, x2, y2, x3, y3, x4, y4;
  61.  
  62. bool incb(int l, int r, int d, int u) {
  63. if(l >= x3 && l <= x4 && r >= x3 && r <= x4 && d >= y3 && d <= y4 && u >= y3 && u <= y4) {
  64. return 1;
  65. }
  66. return 0;
  67. }
  68.  
  69. bool incw(int l, int r, int d, int u) {
  70. if(l >= x && l <= x2 && r >= x && r <= x2 && d >= y && d <= y2 && u >= y && u <= y2) {
  71. return 1;
  72. }
  73. return 0;
  74. }
  75.  
  76. int p(int l, int r, int d, int u) {
  77. int cnt1, cnt2, ans;
  78. if(d % 2) {
  79. if(l % 2) {
  80. cnt1 = (r - l + 1) / 2 + (r - l + 1) % 2;
  81. cnt2 = (r - l + 1) / 2;
  82. }
  83. else {
  84. cnt1 = (r - l + 1) / 2;
  85. cnt2 = (r - l + 1) / 2 + (r - l + 1) % 2;
  86. }
  87. ans = ((u - d + 1) / 2) * cnt1 + ((u - d + 1) / 2) * cnt2 + ((u - d + 1) % 2) * cnt1;
  88. }
  89. else {
  90. if(l % 2) {
  91. cnt1 = (r - l + 1) / 2;
  92. cnt2 = (r - l + 1) / 2 + (r - l + 1) % 2;
  93. }
  94. else {
  95. cnt1 = (r - l + 1) / 2 + (r - l + 1) % 2;
  96. cnt2 = (r - l + 1) / 2;
  97. }
  98. ans = ((u - d + 1) / 2) * cnt1 + ((u - d + 1) / 2) * cnt2 + ((u - d + 1) % 2) * cnt1;
  99. }
  100. return ans;
  101. }
  102.  
  103. signed main() {
  104. seriy();
  105. int n, m;
  106. cin >> n >> m;
  107. cin >> x >> y >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
  108. vi xs = {x, x2, x3, x4};
  109. vi ys = {y, y2, y3, y4};
  110. sort(all(xs));
  111. sort(all(ys));
  112. int ans = 0;
  113. for(int i = 0; i < 3; i++) {
  114. for(int j = 0; j < 3; j++) {
  115. int l = xs[i], r = xs[i + 1];
  116. int d = ys[j], u = ys[j + 1];
  117. if(incb(l, r, d, u)) {
  118. ans += (r - l + 1) * (u - d + 1);
  119. }
  120. else if(incw(l, r, d, u)) {
  121. continue;
  122. }
  123. else {
  124. ans += p(l, r, d, u);
  125. }
  126. }
  127. }
  128. cerr << ans;
  129. ans += p(1, xs[0], 1, n);
  130. ans += p(xs[3], m, 1, n);
  131. ans += p(xs[0], xs[3], 1, ys[0]);
  132. ans += p(xs[0], xs[3], ys[3], n);
  133. cout << ans;
  134. return 0;
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement