1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
| #include <bits/stdc++.h> using namespace std; int n, m, cnt = 0, ans = 0; array<array<int, 104>, 104> R, C, I; void add(int r, int c){ bool ok; I[r][c] = 1; cnt++; if(C[r][c] || R[r][c]) cnt--; C[r][c] = R[r][c] = 0; ok = 0; for(int i = r + 1; i < n; i++){ if(I[i][c]) ok = 1; } if(ok){ for(int i = r + 1; i < n; i++){ if(I[i][c] || R[i][c]) break; R[i][c]++; cnt += C[i][c] == 0; } } ok = 0; for(int i = r - 1; i >= 0; i--){ if(I[i][c]) ok = 1; } if(ok){ for(int i = r - 1; i >= 0; i--){ if(I[i][c] || R[i][c]) break; R[i][c]++; cnt += C[i][c] == 0; } } ok = 0; for(int i = c + 1; i < m; i++){ if(I[r][i]) ok = 1; } if(ok){ for(int i = c + 1; i < m; i++){ if(I[r][i] || C[r][i]) break; C[r][i]++; cnt += R[r][i] == 0; } } ok = 0; for(int i = c - 1; i >= 0; i--){ if(I[r][i]) ok = 1; } if(ok){ for(int i = c - 1; i >= 0; i--){ if(I[r][i] || C[r][i]) break; C[r][i]++; cnt += R[r][i] == 0; } } } void pull(int r, int c){ I[r][c] = 0; cnt--; for(int i = r + 1; i < n; i++){ if(!R[i][c]) break; R[i][c]--; cnt -= C[i][c] == 0; } for(int i = r - 1; i >= 0; i--){ if(!R[i][c]) break; R[i][c]--; cnt -= C[i][c] == 0; } for(int i = c + 1; i < m; i++){ if(!C[r][i]) break; C[r][i]--; cnt -= R[r][i] == 0; } for(int i = c - 1; i >= 0; i--){ if(!C[r][i]) break; C[r][i]--; cnt -= R[r][i] == 0; } } signed main(){ int h, r, c, t; cin >> n >> m >> h; while(h--){ cin >> r >> c >> t; if(t){ pull(r, c); }else{ add(r, c); } ans = max(ans, cnt); } cout << ans << "\n" << cnt; return 0; }
|