--- title: "棋盘" created: 2025-11-28 tags: - 算法 --- # 棋盘 ## 题目 [棋盘](https://www.acwing.com/problem/content/description/5399/) ![[image-1952f098.png]] ## 思路分析 裸题 直接二维差分 因为最后状态是01 所以可以用奇偶数模二得到 所谓翻转可以直接在某一段++ 最后把结果处理成01形式即可 ## 代码实现 ```cpp #include using namespace std; #define endl '\n' const int N=2010; int b[N][N],s[N][N]; int n,m; void insert(int x1,int y1,int x2,int y2){ b[x1][y1]+=1; b[x2+1][y1]-=1; b[x1][y2+1]-=1; b[x2+1][y2+1]+=1; } int main() { ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); cin>>n>>m; while(m--){ int x1,y1,x2,y2;cin>>x1>>y1>>x2>>y2; insert(x1,y1,x2,y2); } for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+b[i][j]; cout<