fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. using ll = long long;
  5.  
  6. void solve() {
  7. int n, m, D, k; cin >> n >> m >> D >> k;
  8. vector<int> r(k + 5), c(k + 5), s(k + 5);
  9. vector<vector<int>> a(n + 5, vector<int>(m + 5, -1));
  10. for (int i = 0; i < k; i++) {
  11. cin >> r[i] >> c[i] >> s[i];
  12. a[r[i]][c[i]] = s[i];
  13. }
  14. vector<vector<int>> h(n + 5, vector<int>(m + 5, 0));
  15. for (int i = 1; i <= n; i++)
  16. for (int j = 1; j <= m; j++)
  17. if (a[i][j] != -1) {
  18. h[i][j + 1] = (a[i][j] - h[i][j]) % D;
  19. if (h[i][j + 1] < 0) h[i][j + 1] += D;
  20. }
  21. for (int i = 0; i < k; i++)
  22. cout << h[r[i]][c[i]] << ' ' << 0 << ' ' << h[r[i]][c[i] + 1] << ' ' << 0 << '\n';
  23. }
  24.  
  25. int main() {
  26. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  27.  
  28. #define TASK "GAME"
  29. if (fopen(TASK".INP", "r")) {
  30. freopen(TASK".INP", "r", stdin);
  31. freopen(TASK".OUT", "w", stdout);
  32. }
  33.  
  34. int tests = 1; // cin >> tests;
  35. while (tests--) solve();
  36.  
  37. return 0;
  38. }
  39.  
Success #stdin #stdout 0.01s 5280KB
stdin
2 3 3 5
1 1 0
1 2 1
2 1 1
2 2 2
2 3 1
stdout
0 0 0 0
0 0 1 0
0 0 1 0
1 0 1 0
1 0 0 0