T1 81101noip simulation competition T1

Source: Internet
Author: User

Tag: getchar score + = STD-optimized RET fine space GETC

 

Ideas:

We can see this question, and we can think of one-dimensional difference at a glance.

However, this complexity is O (NQ), and obviously t

So how to optimize it?

We will find that in the difference ~ Within the L-1 range

The values added by the difference are the same as the X-axis, and the y-axis increases progressively.

The abscissa and ordinate values of the reduced values increase with 1 as the tolerances.

Then, we can divide the difference Array

Mark (R, c) (R, C + 1), (R + L, c) (R + L, C + l) each time.

Code:
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#define rii register int i#define rij register int j#define int long long using namespace std;int cf1[2005][2005],cf2[2005][2005],x[2005][2005];int n,q,r,c,l,s;inline int rd(){    int y=0,f=1;char ch=getchar();    while(!isdigit(ch)) {f=ch==‘-‘?0:1;ch=getchar();}    while(isdigit(ch))  {y=(y<<1)+(y<<3)+ch-‘0‘;ch=getchar();}    return f?y:-y;}signed main(){    freopen("u.in","r",stdin);    freopen("u.out","w",stdout);    n=rd(),q=rd();    for(rii=1;i<=q;i++)    {        r=rd(),c=rd(),l=rd(),s=rd();        cf1[r][c]+=s;        cf1[r+l][c]-=s;        cf2[r][c+1]+=s;        cf2[r+l][c+l+1]-=s;    }    for(rij=1;j<=n;j++)    {        for(rii=1;i<=n;i++)        {            cf1[i][j]+=cf1[i-1][j];        }    }    for(rii=1;i<=n;i++)    {        for(rij=1;j<=n;j++)        {            cf2[i][j]+=cf2[i-1][j-1];        }    }    for(rii=1;i<=n;i++)    {        for(rij=1;j<=n;j++)        {            x[i][j]+=x[i][j-1]+cf1[i][j]-cf2[i][j];        }    }    int ans=0;    for(rii=1;i<=n;i++)    {        for(rij=1;j<=n;j++)        {            ans^=x[i][j];        }    }    printf("%lld",ans);    return 0;}

 

T1 81101noip simulation competition T1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.