The interval of the poj 3225 line segment tree is updated. The interval asks help with intervals.

Source: Internet
Author: User

The interval of the poj 3225 line segment tree is updated. The interval asks help with intervals.
Question:
For some set operations, what is the last set? The START set is empty.
Solution:
It is different from the previous one. I learned how to operate intervals except update intervals.
One operation is used to analyze: (0 and 1 are used to indicate whether a range is included, and-1 is used to indicate whether the range is included or not)
U: overwrite the interval [L, R] to 1.
I: overwrite [-∞, L) (R, ∞] to 0.
D: overwrite the range [L, R] to 0.
C: overwrite [-∞, L) (R, ∞] to 0, and the [L, R] range is 0/1 interchangeable.
S: [L, R] 0/1 Interchange
The segment-based overwrite operation is very simple. The special operation is the 0/1 swap operation. We can call it an exception or operation.
Obviously, we can know this nature: When a range is overwritten, no matter whether it is different or marked before, it makes no sense.
Therefore, when a node is overwritten, the exception or mark is cleared.
When a node gets an exception or mark, first determine the coverage mark. If it is 0 or 1, change the coverage mark directly. Otherwise, change the exception or mark.
Open and closed intervals can be processed by multiplying the number by 2 (even numbers represent endpoints, and odd numbers represent the intervals between vertices at both ends)

/* Pro: 0sol: Date: */# include <iostream> # include <cstdio> # include <algorithm> # include <cstring> # include <cmath> # include <queue> # include <set> # include <vector> # define maxn 131072 # define lson l, m, RT <1 # define rson m + 1, R, RT <1 | 1 # define havem int M = (L + r)> 1 using namespace STD; int cover [maxn <2], XOR [maxn <2]; // The bool variable cannot be different or ..., the output empty setbool hash [maxn]; void build (int l, int R, int RT) {// useless. Because the query is for the entire range, you only need to perform operations on cover1 and xor1 to cover [RT] = XOR [RT] = 0; if (L = r) return; havem; build (lson); Build (rson);} void fxor (int rt) {// 0/1 swap for this node if (cover [RT]! =-1) cover [RT] ^ = 1; else XOR [RT] ^ = 1;} void push_dn (int rt) {If (cover [RT]! =-1) {cover [RT <1] = cover [RT <1 | 1] = cover [RT]; XOR [RT <1] = XOR [RT <1 | 1] = 0; // The father overwrites the son, all previous son's abnormal or invalid cover [RT] =-1;} If (XOR [RT]) // each node is released !!! Fxor (RT <1), fxor (RT <1 | 1), XOR [RT] = 0;} void Update (char op, int L, int R, int L, int R, int RT) {If (L <= L & R <= r) {If (OP = 'U ') {cover [RT] = 1; XOR [RT] = 0;} else if (OP = 'D') {cover [RT] = 0; XOR [RT] = 0;} else if (OP = 'C' | op = 's') fxor (RT); return;} push_dn (RT ); havem; If (L <= m) Update (OP, L, R, lson); else if (OP = 'I' | op = 'C ') cover [RT <1] = XOR [RT <1] = 0; If (R> M) Update (OP, L, R, rson); else if (OP = 'I' | op = 'C ') cover [RT <1 | 1] = XOR [RT <1 | 1] = 0;} void query (int l, int R, int RT) {If (cover [RT] = 1) {for (INT it = L; it <= r; it ++) hash [it] = true; return ;} else if (cover [RT] = 0) return; If (L = r) return; push_dn (RT); havem; query (lson), query (rson );} int main () {char op, L, R; int A, B; // build (1, n, 1); cover [1] = XOR [1] = 0; memset (has H, 0, sizeof (hash); While (~ Scanf ("% C % d, % d % C \ n", & OP, & L, & A, & B, & R )) {// The input is still very powerful... A <= 1; B <= 1; if (L = '(') A ++; // If (r = ') B --; if (A> B ){//???? If (OP = 'C' | op = 'I') cover [1] = XOR [1] = 0;} else Update (OP, A, B, 0, maxn, 1);} query (0, maxn, 1); bool find = false; int S =-1, E; For (INT I = 0; I <= maxn; I ++) {If (hash [I]) {If (S =-1) S = I; E = I ;} else {If (s! =-1) {// If (FIND) printf (""); find = true; printf ("% C % d, % d % C", S & 1? '(': '[', S> 1, (e + 1)> 1, E & 1? ')': ']'); S =-1 ;}} if (! Find) printf ("empty set"); puts (""); Return 0 ;}

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.