1 条题解

  • 0
    @ 2026-4-1 15:36:07
    #include <bits/stdc++.h>
    using namespace std;
    
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    
        int n, m, q;
        cin >> n >> m >> q;
    
        vector<vector<int>> a(n + 1, vector<int>(m + 1));
    
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                cin >> a[i][j];
            }
        }
    
        while (q--) {
            int op, x1, y1, x2, y2;
            cin >> op >> x1 >> y1 >> x2 >> y2;
    
            if (op == 1) {
                for (int i = x1; i <= x2; i++) {
                    for (int j = y1; j <= y2; j++) {
                        a[i][j] ^= 1; // 0变1,1变0
                    }
                }
            } else {
                int ans = 0;
                for (int i = x1; i <= x2; i++) {
                    for (int j = y1; j <= y2; j++) {
                        ans += a[i][j];
                    }
                }
                cout << ans << '\n';
            }
        }
    
        return 0;
    }
    
    • 1

    信息

    ID
    247
    时间
    1000ms
    内存
    256MiB
    难度
    3
    标签
    (无)
    递交数
    54
    已通过
    29
    上传者