POJ1389 Area of Simple Polygons 线段树】的更多相关文章

POJ1389 给定n个整数点矩形,求面积并. 显然ans必然是整数. 记录若干个事件,每个矩形的左边的竖边记为开始,右边的竖边记为结束. 进行坐标离散化后用线段树维护每个竖的区间, 就可以快速积分了. #include<stdio.h> #include<stdlib.h> #include<cstring> #include<math.h> #include<algorithm> #include<vector> using na…
http://poj.org/problem?id=1389 题面描述在二维xy平面中有N,1 <= N <= 1,000个矩形.矩形的四边是水平或垂直线段.矩形由左下角和右上角的点定义.每个角点都是一对两个非负整数,范围从0到50,000,表示其x和y坐标. 求出所有矩形的面积(重叠部分只算一次) 示例:考虑以下三个矩形: 矩形1:<(0,0)(4,4)>, 矩形2:<(1,1)(5,2)>, 矩形3:<(1,1)(2,5)>. 所有由这些矩形构造的简单多…
离散化后,[1,10]=[1,3]+[6,10]就丢了[4,5]这一段了. 因为更新[3,6]时,它只更新到[3,3],[6,6]. 要么在相差大于1的两点间加入一个值,要么就让左右端点为l,r的线段树节点表示到x[l]到x[r+1]的区间. 这样tree[l,r]=tree[l,m]+tree[m+1,r]=[x[l],x[m+1]]+[x[m+1],x[r+1]] #include<iostream> #include<algorithm> #include<cstdio…
---恢复内容开始--- LINK 题意:同POJ1151 思路: /** @Date : 2017-07-19 13:24:45 * @FileName: POJ 1389 线段树+扫描线+面积并 同1151.cpp * @Platform: Windows * @Author : Lweleth (SoungEarlf@gmail.com) * @Link : https://github.com/ * @Version : $Id$ */ #include <stdio.h> #incl…
poj1389:http://poj.org/problem?id=1389 题意:求矩形面积的并题解:扫描线加线段树 同poj1389 #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> using namespace std; ; int num; struct Node{ int l; int r; int tp; int y; bool operator…
E. A Simple Task 题目连接: http://www.codeforces.com/contest/558/problem/E Description This task is very simple. Given a string S of length n and q queries each query is on the format i j k which means sort the substring consisting of the characters from…
题目链接: http://codeforces.com/problemset/problem/558/E E. A Simple Task time limit per test5 secondsmemory limit per test512 megabytes 问题描述 This task is very simple. Given a string S of length n and q queries each query is on the format i j k which mea…
This task is very simple. Given a string S of length n and q queries each query is on the format i j k which means sort the substring consisting of the characters from i to j in non-decreasing order if k = 1 or in non-increasing order if k = 0. Outpu…
这个题lba等神犇说可以不用离散化,但是我就是要用. 题干: Description There are N, <= N <= , rectangles -D xy-plane. The four sides of a rectangle are horizontal or vertical line segments. Rectangles are defined by their lower-left and upper-right corner points. Each corner p…
E. A Simple Task time limit per test5 seconds memory limit per test512 megabytes inputstandard input outputstandard output This task is very simple. Given a string S of length n and q queries each query is on the format i j k which means sort the sub…
题目链接:http://codeforces.com/contest/558/problem/E 题意:有一串字符串,有两个操作:1操作是将l到r的字符串升序排序,0操作是降序排序. 题解:建立26棵线段树,类似计数排序思想. #include <bits/stdc++.h> using namespace std; ; struct SegTree { ], sum[], l, r; }T[N << ]; ][N]; void pushup(int p, int c) { T[p…
题目链接:http://codeforces.com/problemset/problem/558/E 给一个字符串,每次对一个区间内的子串进行升序或者降序的排列,问最后字符串什么样子. 对于字符串排序,计数排序是比一般的排序要快的,但是仍然不能解决本问题. 建立26个线段树,用于统计某个字符在某个区间的情况. 那么如果对[L,R]排序,则先统计所有字符在其中的情况,并且清空该区间,根据每个字符的数量,从a到z去填充应该在的小区间. #include <iostream> #include &…
原题 线段树+扫描线 对于这样一个不规则图形,我们要求他的面积有两种方法,割和补. 补显然不行,因为补完你需要求补上去的内部分不规则图形面积-- 那么怎么割呢? 像这样: 我们就转化成了无数个矩形的和.要想求这些矩形的面积,也就是底成高.因为我们并不懂什么二维线段树,所以我们就用"扫描线"(从左到右的更新计算). 不妨把y轴当做一个线段树,然后维护哪些位置被覆盖了,直到下一条更新,所增加的面积就是被覆盖位置(高)和这两个距离的差(底)的乘积. Eg: 我们第一次更新建了第一条边的树,第…
这道题好猥琐啊啊啊啊啊啊 写了一个上午啊啊啊啊 没有在update里写pushup啊啊啊啊 题目大意: 给你一个字符串s,有q个操作 l r 1 :把sl..rsl..r按升序排序 l r 0 :把sl..rsl..r按降序排序 Solution: 我们考虑建26棵线段树,第i棵线段树的[x,y]表示在[x,y]中一共有多少个字母'a'+i-1 至于修改时我们可以以升序为例,从a至z按顺序往前丢,记得要清空区间 同理,降序反过来就是了 Code: 我们可以用sort啊啊,只不过会TLE #pra…
题目链接 题意较为简单. 思路: 由于仅仅有26个字母,所以用26棵线段树维护就好了,比較easy. #include <iostream> #include <string> #include <vector> #include <cstring> #include <cstdio> #include <map> #include <queue> #include <algorithm> #include &…
链接 题意:给定一个长度不超过 \(10^5\) 的字符串(小写英文字母),和不超过5000个操作. 每个操作 L R K 表示给区间[L,R]的字符串排序,K=1为升序,K=0为降序. 最后输出最终的字符串. 题解 发现只有小写英文字母,26个,直接建26棵线段树,排序的时候,直接统计每个字母的个数暴力安排即可 好像见过值域 \(10^9\) 的,不过不知道在哪了,先留个坑,等看到了或者记起来了再补 #include<bits/stdc++.h> #define REP(i,a,b) for…
请戳此处 #include<cstdio> #include<algorithm> #include<cstring> #define N 1010 #define LEN 60010 using namespace std; struct Edge { int l,r,h,f; bool operator < (const Edge &a) const { if (h==a.h) return f<a.f; return h<a.h; } }…
Atlantis Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 14378    Accepted Submission(s): 5931 Problem Description There are several ancient Greek texts that contain descriptions of the fabled i…
题目 Source http://codeforces.com/problemset/problem/558/E Description This task is very simple. Given a string S of length n and q queries each query is on the format i j k which means sort the substring consisting of the characters from i to j in non…
A Simple Problem with Integers [题目链接]A Simple Problem with Integers [题目类型]线段树 成段增减+区间求和 &题解: 线段树 成段增减+区间求和 模板题 这种题真的应该理解并且可以流畅的独立码出来了 [时间复杂度]\(O(nlogn)\) &代码: #include <iostream> #include <cstdio> #include <cstring> using namespa…
Area Coverage Time Limit: 10000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit users: 16, Accepted users: 12 Problem 12884 : No special judgement Problem description In this day and age, a lot of the spying on other countries is done…
A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 58269   Accepted: 17753 Case Time Limit: 2000MS Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of…
A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 92127   Accepted: 28671 Case Time Limit: 2000MS 描述 You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operatio…
E. A Simple Task Problem's Link: http://codeforces.com/problemset/problem/558/E Mean: 给定一个字符串,有q次操作,每次操作将(l,r)内的字符升序或降序排列,输出q次操作后的字符串. analyse: 基本思想是计数排序. 所谓计数排序,是对一个元素分布较集中的数字集群进行排序的算法,时间复杂度为O(n),但使用条件很苛刻.首先对n个数扫一遍,映射出每个数字出现的次数,然后再O(n)扫一遍处理出:对于数字ai,…
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 53169 Accepted: 15897 Case Time Limit: 2000MS Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of ope…
A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 92632   Accepted: 28818 Case Time Limit: 2000MS Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of…
A Simple Problem with Integers Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a given interval. The other is to ask for the sum of…
题目:http://poj.org/problem?id=3468   A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 85851   Accepted: 26685 Case Time Limit: 2000MS Description You have N integers, A1, A2, ... , AN. You need to deal with…
A Simple Problem with Integers   Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a given interval. The other is to ask for the sum o…
A Simple Problem with Integers Time Limit:5000MS   Memory Limit:131072K Case Time Limit:2000MS Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each…