POJ 2155 Matrix two-dimensional line segment tree

Source: Internet
Author: User

There are many points on a two-dimensional coordinate axis. The point is either 0 or 1. Then there are two more operations.

C: change to (x1, y1) as the top left vertex (x2, y2). Change to 0 for each vertex in the lower right vertex.

Q: Output A [x] [y]

Then, each change gets an exception or this means that the number of times it is changed to an odd number, and the number of times it is changed.

 

#include <iostream>#include <cstdio>#include <algorithm>#define maxn 1005#define lson num<<1,s,mid#define rson num<<1|1,mid+1,eusing namespace std;bool tree[maxn<<2][maxn<<2];int n,ans;void buildy(int num,int s,int e,int rt){    tree[rt][num]=0;    if(s==e)return;    int mid=(s+e)>>1;    buildy(lson,rt);    buildy(rson,rt);}void buildx(int num,int s,int e){    buildy(1,1,n,num);    if(s==e)return;    int mid=(s+e)>>1;    buildx(lson);    buildx(rson);}void updatey(int num,int s,int e,int l,int r,int rt){    if(l<=s && r>=e)    {        tree[rt][num]^=1;        return ;    }    int mid=(s+e)>>1;    if(r>mid)updatey(rson,l,r,rt);    if(l<=mid)updatey(lson,l,r,rt);}void updatex(int num,int s,int e,int l,int r,int u,int d){    if(l<=s && r>=e)    {        updatey(1,1,n,u,d,num);        return;    }    int mid=(s+e)>>1;    if(r>mid)    updatex(rson,l,r,u,d);    if(l<=mid)    updatex(lson,l,r,u,d);}void queryy(int num,int s,int e,int y,int rt){    ans^=tree[rt][num];    if(s==e)return;    int mid=(s+e)>>1;    if(y<=mid)queryy(lson,y,rt);    else if(y>mid)queryy(rson,y,rt);}void queryx(int num,int s,int e,int x,int y){    queryy(1,1,n,y,num);    if(s==e)    {        return;    }    int mid=(s+e)>>1;    if(x>mid)queryx(rson,x,y);    else if(x<=mid)queryx(lson,x,y);}int main(){    int T;    scanf("%d",&T);    while(T--)    {        int op;        scanf("%d%d",&n,&op);        buildx(1,1,n);        while(op--)        {            char p[10];            scanf("%s",p);            if(p[0]=='C')            {                int x1,x2,y1,y2;                scanf("%d%d%d%d",&x1,&y1,&x2,&y2);                updatex(1,1,n,x1,x2,y1,y2);            }            else            {                int a,b;                scanf("%d%d",&a,&b);                ans=0;                queryx(1,1,n,a,b);                printf("%d\n",ans);            }        }        puts("");    }    return 0;}

 

Related Article

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.