POJ 2155 Matrix Two-dimensional line segment Tree + tag permanent?

Source: Internet
Author: User

Test Instructions:Link Method:Two-dimensional segment tree + tag Persistence parsing:Test instructions is relatively clear, calculate the memory 4000^2 is also acceptable, so began to yy two-dimensional line segment tree? For the first-level X-segment tree, each node opens a whole tree of Y-segments. A two-dimensional array is implemented? But found a problem ah, this question how pushdown Ah, Mark can't pass to go ah. If you give X a mark, then how do you know the passage of y? So I learned something new? Tag persistence. The subject is a single point of query, it should be a permanent mark should be the corresponding interval directly or not to go down? What about the query? All you need to do is make sure that all the intervals passing through that point are different or up at the time of the query. Looks pretty simple, too? Is the application of the tag permanence the time when the mark cannot be hit? Looks like it. In addition, the problem has a pit, different groups of data between the line, for this also PE once. Code:
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define Lson l,mid,rt<<1#define Rson mid+1,r,rt<<1|1#define N 1010using namespace STD;intT,n,q,ans;Chars[5];intsum[n<<2][n<<2];voidUpdate2 (intLintRintLintRintRtxintRty) {if(L&LT;=L&AMP;&AMP;R&LT;=R) {sum[rtx][rty]^=1;return; }intMid= (l+r) >>1;if(L>mid) Update2 (l,r,mid+1,r,rtx,rty<<1|1);Else if(R<=mid) Update2 (l,r,l,mid,rtx,rty<<1);Else{Update2 (l,mid,l,mid,rtx,rty<<1); Update2 (mid+1, r,mid+1,r,rtx,rty<<1|1); }}voidUpdateintX1,intX2,intY1,intY2,intLintRintRT) {if(X1&LT;=L&AMP;&AMP;R&LT;=X2) {Update2 (Y1,y2,1, N,rt,1);return; }intMid= (l+r) >>1;if(x1>mid) update (X1,x2,y1,y2,rson);Else if(x2<=mid) update (X1,x2,y1,y2,lson);Else{Update (X1,mid,y1,y2,lson); Update (mid+1, X2,y1,y2,rson); }}voidQuery2 (intY1,intLintRintRtxintRty) {Ans^=sum[rtx][rty];if(L==R) {return; }intMid= (l+r) >>1;if(Y1<=mid) Query2 (y1,l,mid,rtx,rty<<1);ElseQuery2 (y1,mid+1,r,rtx,rty<<1|1);}voidQueryintX1,intY1,intLintRintRT) {Query2 (y1,1, N,rt,1);if(L==R) {return; }intMid= (l+r) >>1;if(x1<=mid) query (x1,y1,l,mid,rt<<1);ElseQuery (x1,y1,mid+1,r,rt<<1|1);}intMain () {scanf("%d", &t); while(t--) {memset(Sum,0,sizeof(sum));scanf("%d%d", &n,&q); for(intI=1; i<=q;i++) {scanf('%s ', s);if(s[0]==' C ')            {intX1,y1,x2,y2;scanf("%d%d%d%d", &x1,&y1,&x2,&y2); Update (X1,x2,y1,y2,1N1); }Else{ans=0;intX1,y1;scanf("%d%d", &x1,&y1); Query (X1,y1,1N1);printf("%d\n", ans); }        }printf("\ n"); }}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

POJ 2155 Matrix Two-dimensional line segment Tree + tag permanent?

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.