[HDU] Mayor's posters (line segment tree interval problem)

Source: Internet
Author: User

Discretization is required, and the interval of the Line Segment tree is modified.

Note that when discretization is performed, special processing is required because the given number is a unit length (because the coverage of a line segment is different from that of a point)

For example)

After discretization, values 1, 4, 6, and 10 are discrete to 1, 2, 3, and 4 respectively.

Overwrite 1 4, overwrite 1 2, overwrite 2 3, and the result is 2.

But it should actually be 3

13450359 201301052100 2528 Accepted 1140 K 985 Ms C ++ 1960b 15:42:33

985ms insurance.

# Include <cstdio> # include <cstring> # include <iostream> # include <algorithm> # include <vector> # include <queue> # include <map> using namespace STD; typedef long ll; const int maxn = 11111; int n, m, ans; bool vis [maxn]; int arr [maxn <2]; int arr_l [maxn]; int arr_r [maxn]; int tr [maxn <4]; void Update (int l, int R, int value, int L, int R, int POS) {If (L <= L & R <= r) {tr [POS] = value; return;} If (TR [POS]! =-1) {tr [POS <1] = tr [POS]; tr [(Pos <1) | 1] = tr [POS]; tr [POS] =-1;} int M = (L + r)> 1; if (L <= m) Update (L, R, value, L, M, pos <1); If (r> m) Update (L, R, value, m + 1, R, (Pos <1) | 1); return ;} void query (int l, int R, int POS) {If (TR [POS]! =-1) {int e = tr [POS]; If (! Vis [e]) {vis [e] = true; ans ++;} return;} If (L = r) return; int M = (L + r)> 1; query (L, M, POS <1); query (m + 1, R, (Pos <1) | 1); return;} int main () {int t; scanf ("% d", & T); While (t --) {memset (VIS, false, sizeof (VIS); memset (TR,-1, sizeof (TR); scanf ("% d", & M); int size = 0; For (INT I = 0; I <m; I ++) {scanf ("% d", & arr_l [I], & arr_r [I]); arr [size ++] = arr_l [I]; arr [size ++] = arr_r [I];} Sort (ARR, arr + size); n = unique (ARR, arr + size)-Arr; // deduplicated for (INT I = n-1; I> 0; I --) // convert the interval to a vertex if (ARR [I]! = Arr [I-1] + 1) Arr [n ++] = arr [I-1] + 1; sort (ARR, arr + n); ans = 0; for (INT I = 0; I <m; I ++) {int L = find (ARR, arr + N, arr_l [I])-Arr; // Binary Search int r = find (ARR, arr + N, arr_r [I])-Arr; // Binary Search Update (L, R, I, 0, n-);} query (0, N-); printf ("% d \ n", ANS);} return 0 ;}

[HDU] Mayor's posters (line segment tree interval problem)

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.