zoukankan      html  css  js  c++  java
  • 【SSLOJ1467】U

    题目

    思路

    对于一个将左上角为 \((1,1)\),边长为 3 的直角三角形,那么我们可以通过如下方式,每次修改只需 \(O(1)\) 即可。

    所以每次修改直接修改 4 个值,最终查询时再做若干遍差分即可。
    时间复杂度 \(O(q+n^2)\)

    代码

    #include <bits/stdc++.h>
    using namespace std;
    
    const int N=1010;
    long long n,Q,ans,a[N][N],b[N][N],c[N][N];
    
    int main()
    {
    	scanf("%lld%lld",&n,&Q);
    	while (Q--)
    	{
    		int r,c,l,s;
    		scanf("%lld%lld%lld%lld",&r,&c,&l,&s);
    		a[r][c]+=s;
    		if (r+l<=n) b[r+l][c]-=s;
    		if (r+l<=n && c+l<=n) a[r+l][c+l]-=s;
    		if (r+l<=n && c+l<=n) b[r+l][c+l]+=s;
    	} 
    	for (int i=1;i<=n;i++)
    		for (int j=1;j<=n;j++)
    		{
    			a[i][j]+=a[i-1][j-1];
    			b[i][j]+=b[i][j-1];
    			c[i][j]=a[i][j]+b[i][j]+c[i-1][j];
    			ans^=c[i][j];
    			//printf("%d ",c[i][j]);
    		}
    	printf("%lld",ans);
    	return 0;
    }
    
  • 相关阅读:
    js5
    js4
    js(3)
    JS内容(2)
    html复习
    js介绍及内容(1)
    定位2
    position定位
    CSS
    列表及行块转变
  • 原文地址:https://www.cnblogs.com/stoorz/p/13492790.html
Copyright © 2011-2022 走看看