题目大意: n个矩形,将一个大矩形分成 n+1 块.矩形之间不重合,可是包括.求这n+1个矩形的面积 思路分析: 用线段树记录他们之间的父子关系.然后dfs 计算面积. 当给出的矩形上边的时候,就要记录到该矩形的父亲去. #include <cstdio> #include <iostream> #include <cstring> #include <algorithm> #define lson num<<1,s,mid #define rs…
319. Kalevich Strikes Back Time limit per test: 0.5 second(s)Memory limit: 65536 kilobytes input: standardoutput: standard And yet again the Berland community can see that talent is always multi-sided. The talent is always seeking new ways of self-ex…
D. Slalom time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Little girl Masha likes winter sports, today she's planning to take part in slalom skiing. The track is represented as a grid comp…
题目链接:http://codeforces.com/contest/522/problem/D 题目大意:  给你一个长度为n的序列,然后有m次查询,每次查询输入一个区间[li,lj],对于每一个查询,输出在这个区间内的两个相等的数的最短距离,如果没有相等的则输出-1. 线段树+扫描线,线段树维护的值是区间的最小值,从后往前扫,然后每次要做的事有两个: 1.判断当前这个位置 i 的数刚刚是不是出现过,假设刚刚出现的位置是 l ,如果出现过,则在线段树中把l这个位置的值更新为 l - i,同时更…
Stars in Your Window Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11706   Accepted: 3183 Description Fleeting time does not blur my memory of you. Can it really be 4 years since I first saw you? I still remember, vividly, on the beaut…
题意: 有三种颜色的矩形n个,不同颜色的矩形重叠会生成不同的颜色,总共有R,G,B,RG,RB,GB,RGB 7种颜色,问7种颜色每种颜色的面积. 解法: 很容易想到线段树扫描线求矩形面积并,但是如何维护每种颜色的长度着实让我伤透了脑筋.后来看了一位朋友的题解,才幡然醒悟. 开始想到了用二进制表示颜色,R用001表示,G用010表示,B用100表示.那么就可以用十进制1~7表示7种不同颜色了. 维护 cov[rt][1~3] 表示此区间内3种原色各有多少个, Len[rt][i]表示每种颜色的长…
3228: [Sdoi2008]棋盘控制 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 23 Solved: 9 [Submit][Status][Discuss] Description 在一个N * M的棋盘上,摆放着K个棋子,一个棋子占据一个格子(可能有多个棋子占据同一个格子),控制棋盘上所有与它相距不超过R的格子.两个格子(X1,Y1).(X2,Y2)间的距离定义为|X1-X2|+|Y1-Y2|. 试设计一个算法,计算出K个棋子控制的格子…
看数据范围像是个暴力,而且理论复杂度似乎可行,然后被卡了两个点...然后来了个乱搞的线段树+扫描线.. 3225: [Sdoi2008]立方体覆盖 Time Limit: 2 Sec Memory Limit: 128 MB Submit: 102 Solved: 64 [Submit][Status][Discuss] Description A君近日为准备省队选拔,特意进行了数据结构的专项训练.训练过程中就遇到了"矩形面积并"这道经典问题,即:给出N个各边与坐标轴平行(垂直)的矩形…
上海邀请赛的一道题目,看比赛时很多队伍水过去了,当时还想了好久却没有发现这题有什么水题的性质,原来是道成题. 最近学习了下线段树扫描线才发现确实是挺水的一道题. hdu5091 #include <iostream> #include <stdio.h> #include <string.h> #include <math.h> #include <algorithm> #include <string> #include <q…
/* 线段树+扫描线+离散化 求多个矩形的面积 */ #include<stdio.h> #include<string.h> #include<stdlib.h> #include<algorithm> #include<iostream> #include<queue> #include<stack> #include<math.h> #include<map> using namespace…