fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
  5. #define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
  6.  
  7. using ll = long long;
  8.  
  9. template<typename X, typename Y>
  10. bool chmax(X& a, Y b) { return (a < b) ? a = b, 1 : 0; }
  11. template<typename X, typename Y>
  12. bool chmin(X& a, Y b) { return (a > b) ? a = b, 1 : 0; }
  13.  
  14. int M, N, Q;
  15. vector<vector<int>> A;
  16.  
  17. void solve() {
  18. cin >> M >> N >> Q;
  19. A.assign(M + 5, vector<int>(N + 5, 0));
  20. while (Q--) {
  21. int x, y, u, v; cin >> x >> y >> u >> v;
  22. A[x][y] ^= 1; A[u + 1][v + 1] ^= 1;
  23. A[x][v + 1] ^= 1; A[u + 1][y] ^= 1;
  24. }
  25. int ans = 0;
  26. FOR(r, 1, M) FOR(c, 1, N) {
  27. A[r][c] ^= A[r - 1][c] ^ A[r][c - 1] ^ A[r - 1][c - 1];
  28. ans += A[r][c];
  29. }
  30. cout << ans << "\n";
  31. }
  32.  
  33. int main() {
  34. ios_base::sync_with_stdio(false); cin.tie(NULL);
  35.  
  36. // freopen("LIGHT.INP", "r", stdin);
  37. // freopen("LIGHT.OUT", "w", stdout);
  38.  
  39. int tests = 1; // cin >> tests;
  40. while (tests--) solve();
  41.  
  42. #ifdef LOCAL
  43. cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  44. #endif
  45. return 0;
  46. }
  47.  
Success #stdin #stdout 0.01s 5296KB
stdin
2 2 2
1 1 2 2
2 2 2 2
stdout
3