fork(1) download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define int int64_t
  6.  
  7. void solve() {
  8. int N, M, K;
  9. cin >> N >> M >> K;
  10. map<int, map<int, int>> A;
  11. int ans = 0;
  12. int dx[] = {1, 0, -1, 0};
  13. int dy[] = {0, 1, 0, -1};
  14. while(K--) {
  15. int x, y;
  16. cin >> x >> y;
  17. for(int i = 0; i < 4; i++) {
  18. int nx = x + dx[i];
  19. int ny = y + dy[i];
  20. ans += A[nx][ny] ? -1 : 1;
  21. }
  22. A[x][y] = 1;
  23. }
  24. cout << ans << endl;
  25. }
  26.  
  27. signed main() {
  28. //freopen("input.txt", "r", stdin);
  29. ios::sync_with_stdio(0);
  30. cin.tie(0);
  31. int t;
  32. cin >> t;
  33. while(t--) {
  34. solve();
  35. }
  36. }
  37.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Standard output is empty