POJ 2528 Mayor ' s Posters (segment tree interval update, discretization) __ Segment Tree

Source: Internet
Author: User

Topic Link: http://poj.org/problem?id=2528


Topic: On the wall to paste ads, advertising suites have a great deal of small, and advertising has successively, the back of the ads will cover the front of the ads to solve the last visible advertising surface, as shown in the following picture:




Two views, and finally the number of ads you can see from front view is 4.

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace
Std
typedef long Long LL;
	struct node{int L, R, M;
ll Val;
};
const int MAXN = 10010;
Node T[MAXN << 4];
int COL[MAXN];
int ans;  
        void pushdown (int rt) {if (T[rt].val!=-1) {t[rt << 1].val = t[rt].val;  
        T[rt << 1 | 1].val = T[rt].val;  
    T[rt].val =-1;
	} void build (int begin, int end, int rt) {T[RT].L = begin;
	T[RT].R = end;
	T[RT].M = (t[rt].l + t[rt].r) >> 1;
	T[rt].val =-1;
	if (begin = = end) return;
	Build (T[RT].L, T[RT].M, RT << 1);
Build (T[RT].M + 1, T[RT].R, RT << 1 | 1);
		} void Update (int l, int R, int num, int rt) {if (L = = T[rt].l && T[RT].R = = R) {t[rt].val = num;
	return;
	} pushdown (RT);  
    if (L > T[RT].M) Update (l, R, num, rt << 1 | 1);  
    else if (r <= t[rt].m) update (L, R, Num, RT << 1); else {update (L, T[RT].M, num, RT << 1);  
    Update (T[RT].M + 1, R, num, rt << 1 | 1);
		} void query (int rt) {if (T[rt].val!=-1) {if (!col[t[rt].val)) ans++;
		Col[t[rt].val] = 1;
	return;
	} if (t[rt].l = = T[RT].R) return;
	Query (RT << 1);
Query (RT << 1 | 1);
int x[maxn<<2], top;
Pair<int, int> Q[MAXN];
	int main () {int t;
	scanf ("%d", &t);
	int n;
	int TL, TR;
		while (t--) {top = 0;
		scanf ("%d", &n);
			for (int i = 0; i < n; i++) {scanf ("%d%d", &q[i].first, &q[i].second);
			x[top++] = Q[i].first;
		x[top++] = Q[i].second;
		Sort (x, x + top);
		int m = 1;
		for (int i = 1; i < top; i++) {if (X[i]!= x[i-1]) x[m++] = X[i];
		for (int i = m-1 i > 0; i--) {if (X[i]-1!= x[i-1]) x[m++] = 1;
		Sort (x, x + m);
		Build (0, M, 1);
			for (int i = 0; i < n; i++) {int L = lower_bound (x, X + M, Q[i].first)-X;
			int r = Lower_bound (x, X + M, q[i].second)-X;
		Update (L, R, I, 1); } memset (Col, 0, sizeof col);
		Ans = 0;
		Query (1);
	printf ("%d\n", ans);
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.