题目一:E. Infinite Inversions 这个题目没什么思维量,还比较简单,就是离散化要加上每一个值的后面一个值,然后每一个值放进去的不是1 ,而是这个值与下一个点的差值. 因为这个数代表了一堆数,然后每一次的找到了的逆序对都要乘以这个num. #include <cstdio> #include <cstdlib> #include <cstring> #include <queue> #include <vector> #incl…
E. Physical Education Lessons time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output This year Alex has finished school, and now he is a first-year student of Berland State University. For him it…
Mayor's posters 转载自:http://blog.csdn.net/winddreams/article/details/38443761 [题目链接]Mayor's posters [题目类型]线段树+离散化 &题意: 给出一面墙,给出n张海报贴在墙上,每张海报都覆盖一个范围,问最后可以看到多少张海报 &题解: 海报覆盖的范围很大,直接使用数组存不下,但是只有最多10000张海报,也就是说最多出现20000个点,所以可以使用离散化,将每个点离散后,重新对给出控制的区间,这样…
/* poj 2528 Mayor's posters 线段树 + 离散化 离散化的理解: 给你一系列的正整数, 例如 1, 4 , 100, 1000000000, 如果利用线段树求解的话,很明显 会导致内存的耗尽.所以我们做一个映射关系,将范围很大的数据映射到范围很小的数据上 1---->1 4----->2 100----->3 1000000000----->4 这样就会减少内存一些不必要的消耗 建立好映射关系了,接着就是利用线段树求解 */ #include<ios…
线段树 + 离散化 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at all places at their whim. The city council has finally decided to build an electoral…
题目链接:http://acm.uestc.edu.cn/#/problem/show/1059 普通线段树+离散化,关键是……离散化后建树和查询都要按照基本法!!!RE了不知道多少次………………我真是个沙茶…… /* ━━━━━┒ギリギリ♂ eye! ┓┏┓┏┓┃キリキリ♂ mind! ┛┗┛┗┛┃\○/ ┓┏┓┏┓┃ / ┛┗┛┗┛┃ノ) ┓┏┓┏┓┃ ┛┗┛┗┛┃ ┓┏┓┏┓┃ ┛┗┛┗┛┃ ┓┏┓┏┓┃ ┛┗┛┗┛┃ ┓┏┓┏┓┃ ┃┃┃┃┃┃ ┻┻┻┻┻┻ */ #include <a…
poj 2528 Mayor's posters 题目链接: http://poj.org/problem?id=2528 思路: 线段树+离散化技巧(这里的离散化需要注意一下啊,题目数据弱看不出来) 假设给出: 1~10 1~4 7-10 最后可以看见三张海报 如果离散化的时候不注意,就会变成 1 4 7 10(原始) 1 2 3 4 (离散化) 转化为: 1~4 1~2 3~4 这样的话最后只能看见两张海报 解决办法,如果原数据去重排序后相互之间差值大于1,则在他们之间再插入一个数值,使得大…
BZOJ_4653_[Noi2016]区间_线段树+离散化+双指针 Description 在数轴上有 n个闭区间 [l1,r1],[l2,r2],...,[ln,rn].现在要从中选出 m 个区间,使得这 m个区间共同包含至少一个位置.换句话说,就是使得存在一个 x,使得对于每一个被选中的区间 [li,ri],都有 li≤x≤ri. 对于一个合法的选取方案,它的花费为被选中的最长区间长度减去被选中的最短区间长度.区间 [li,ri] 的长度定义为 ri−li,即等于它的右端点的值减去左端点的值…
题目: The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at all places at their whim. The city council has finally decided to build an electoral wall for placing…
题面:Rmq Problem / mex 题解: 先离散化,然后插一堆空白,大体就是如果(对于以a.data<b.data排序后的A)A[i-1].data+1!=A[i].data,则插一个空白叫做A[i-1].data+1, 开头和最尾也要这么插,意义是如果取不了A[i-1]了,最早能取的是啥数.要把这些空白也离散化然后扔主席树里啊. 主席树维护每个数A[i]出现的最晚位置(tree[i].data),查询时查询root[R]的树中最早的data<L的节点(这意味着该节点的下标离散化前代…
题目链接 CF915E Physical Education Lessons 题解 动态开点线段树 代码 /* 动态开点线段树 */ #include<cstdio> #include<cstring> #include<algorithm> inline int read() { int x = 0,f = 1; char c = getchar() ; while(c < '0' || c > '9')c = getchar(); while(c <…
http://acm.hdu.edu.cn/showproblem.php?pid=5124 Problem Description John has several lines. The lines are covered on the X axis. Let A is a point which is covered by the most lines. John wants to know how many lines cover A.   Input The first line con…
[题目]E. Physical Education Lessons [题意]10^9范围的区间覆盖,至多3*10^5次区间询问. [算法]线段树 [题解]每次询问至多增加两段区间,提前括号分段后线段树. #include<cstdio> #include<cctype> #include<set> #include<algorithm> using namespace std; int read(){ ,t=; ; +c-';}while(isdigit(c…
题意: 给你n个矩形,输入每个矩形的左上角坐标和右下角坐标. 然后求矩形的总面积.(矩形可能相交). 题解: 前言: 先说说做这道题的感受: 刚看到这道题顿时就懵逼了,几何 烂的渣渣.后来从网上搜题解.才知道用到线段树+离散化+扫描线.不过这是我第一次接触扫描线,根本不知道什么鬼啊.后来各种博客和论文看了一天才真正理解. 不过一想到网上的博客和论文,就来气.都什么啊,代码注释少的很而且说不明白什么意思,比如线段树怎么存每个节点的数据?为什么这么存?每个节点的数据变量都什么意思?更新的时候怎么更新…
[POJ 2482] Stars in Your Window(线段树+离散化+扫描线) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11294   Accepted: 3091 Description Fleeting time does not blur my memory of you. Can it really be 4 years since I first saw you? I still remembe…
Physical Education Lessons CodeForces - 915E This year Alex has finished school, and now he is a first-year student of Berland State University. For him it was a total surprise that even though he studies programming, he still has to attend physical…
E. Physical Education Lessons 题目:一段长度为n的区间初始全为1,每次成段赋值0或1,求每次操作后的区间总和.(n<=1e9,q<=3e5) 题意:用线段树做的话,没什么思维量,主要是空间复杂度的问题.因此采用动态开点的办法,即需要用到的节点,在使用前分配内存,没有用到的就虚置.这样每次操作新增的节点约logn个.则q次修改需要的空间大约是qlogn.但是,在这个数量级上尽可能开的再大一些,防止RE. #include<bits/stdc++.h> #…
Mayor's posters Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at all places at their whim. The city council has finally decided to build an ele…
原题传送门 我承认,比赛的时候在C题上卡了好久(最后也不会),15min水掉D后(最后还FST了..),看到E时已经只剩15min了.尽管一眼看出是离散化+线段树的裸题,但是没有时间写,实在尴尬. 赛后先照习惯码出线段树,提交上去WA4???看了好久没看出问题,怎么调都不对.这时TJW忽悠我:"我写的可持久化线段树啊,不用离散化了啊."我信了,码出主席树(实话说确实不用想那么多了,无脑动态开点就行了),提交上去TLE18???回头一问TJW:"我FST了啊."我:(…
题意: Alex高中毕业了,他现在是大学新生.虽然他学习编程,但他还是要上体育课,这对他来说完全是一个意外.快要期末了,但是不幸的Alex的体育学分还是零蛋! Alex可不希望被开除,他想知道到期末还有多少天的工作日,这样他就能在这些日子里修体育学分.但是在这里计算工作日可不是件容易的事情: 从现在到学期结束还有 n 天(从 1 到 n 编号),他们一开始都是工作日.接下来学校的工作人员会依次发出 q 个指令,每个指令可以用三个参数 l,r,k 描述: 如果 k=1,那么从 l 到 r (包含端…
题目描述 This year Alex has finished school, and now he is a first-year student of Berland State University. For him it was a total surprise that even though he studies programming, he still has to attend physical education lessons. The end of the term i…
原题传送门:CF915E Physical Education Lessons 前置芝士:珂朵莉树 窝博客里对珂朵莉树的介绍 没什么好说的自己看看吧 这道题很简单啊 每个操作就是区间赋值,顺带把总和修改一下,这样会快多了,所以我又成了洛咕最优解第二(好像比23forever dalao快,玄学???) #pragma GCC optimize("O3") #include <bits/stdc++.h> #define IT set<node>::iterato…
Atlantis Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21734   Accepted: 8179 Description There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some of these texts even include maps of parts of…
Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 59683   Accepted: 17296 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral post…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3743 Frosh Week Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submission(s) : 5   Accepted Submission(s) : 1 Font: Times New Roman | Verdana | Georgia Font Size: …
求矩形面积并,离散化加线段树. 扫描线法: 用平行x轴的直线扫,每次ans+=(下一个高度-当前高度)*当前覆盖的宽度. #include<algorithm> #include<cstdio> #include<cstring> #define dd double #define ll long long #define N 201 using namespace std; struct P{dd s,e,h;int f;}p[N]; struct Tree{dd s…
题目 给定每张海报的覆盖区间,按顺序覆盖后,最后有几张海报没有被其他海报完全覆盖.离散化处理完区间端点,排序后再给相差大于1的相邻端点之间再加一个点,再排序.线段树,tree[i]表示节点i对应区间是哪张海报,如果是-1代表对应区间不是一张海报(0或多张).每贴一张海报,就用二分查找出覆盖的起点和终点对应的离散后的下标,然后更新区间.线段树的区间更新可以加上懒惰标记(或延迟标记,但是这题可以不用另外标记. #include<cstdio> #include<cstring> #in…
题意:在墙上贴一堆海报(只看横坐标,可以抽象成一线段),新海报可以覆盖旧海报.求最后能看到多少张海报 sol:线段树成段更新.铺第i张海报的时候更新sg[i].x~sg[i].y这一段为i. 然而坐标范围有点大,还是加上离散化更靠谱些. 注意每组数据要清空数组,因为忘了清空WA了两发,太可惜了-_-|| #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> usin…
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 51175 Accepted: 14820 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters…
题目大意:给n个区间,有的区间可能覆盖掉其他区间,问没有完全被其他区间覆盖的区间有几个?区间依次给出,如果有两个区间完全一样,则视为后面的覆盖前面的. 题目分析:区间可能很长,所以要将其离散化.但离散化之后区间就变成了连续的,不再是离散的.也就是叶子由左右端点为u.u变成了左右端点为u-1.u,左右儿子有(l,mid)和(mid+1,r)变成了(l,mid)和(mid,r).所以离散化之后要以长度为1的区间为叶子节点建立线段树,而不是以1.2.3...为叶子节点建线段树. 代码如下: # inc…