Segment Tree-732. My Calendar III
Implement a MyCalendarThree
class to store your events. A new event can always be added.
Your class will have one method, book(int start, int end)
. Formally, this represents a booking on the half open interval [start, end)
, the range of real numbers x
such that start <= x < end
.
A K-booking happens when K events have some non-empty intersection (ie., there is some time that is common to all K events.)
For each call to the method MyCalendar.book
, return an integer K
representing the largest integer such that there exists a K
-booking in the calendar.
Your class will be called like this: MyCalendarThree cal = new MyCalendarThree();
MyCalendarThree.book(start, end)
Example 1:
MyCalendarThree();
MyCalendarThree.book(10, 20); // returns 1
MyCalendarThree.book(50, 60); // returns 1
MyCalendarThree.book(10, 40); // returns 2
MyCalendarThree.book(5, 15); // returns 3
MyCalendarThree.book(5, 10); // returns 3
MyCalendarThree.book(25, 55); // returns 3
Explanation:
The first two events can be booked and are disjoint, so the maximum K-booking is a 1-booking.
The third event [10, 40) intersects the first event, and the maximum K-booking is a 2-booking.
The remaining events cause the maximum K-booking to be only a 3-booking.
Note that the last event locally causes a 2-booking, but the answer is still 3 because
eg. [10, 20), [10, 40), and [5, 15) are still triple booked.
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <climits>
#include <algorithm>
#include <sstream>
#include <functional>
#include <bitset>
#include <numeric>
#include <cmath>
#include <regex> using namespace std; class MyCalendarThree
{
public:
map<int, int> mmp;
MyCalendarThree()
{ } int book(int start, int end)
{
mmp[start]++;
mmp[end]--;
int maxCount = , sum = ;
for (auto a : mmp)
{
sum += a.second;
if (sum > maxCount)
maxCount = sum;
}
return maxCount;
}
};
Segment Tree-732. My Calendar III的更多相关文章
- 【LeetCode】732. My Calendar III解题报告
[LeetCode]732. My Calendar III解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/my-calendar ...
- 732. My Calendar III (prev)
Implement a MyCalendarThree class to store your events. A new event can always be added. Your class ...
- [LeetCode] 729. My Calendar I 731. My Calendar II 732. My Calendar III 题解
题目描述 MyCalendar主要实现一个功能就是插入指定起始结束时间的事件,对于重合的次数有要求. MyCalendar I要求任意两个事件不能有重叠的部分,如果插入这个事件会导致重合,则插入失败, ...
- LeetCode 732. My Calendar III
原题链接在这里:https://leetcode.com/problems/my-calendar-iii/ 题目: Implement a MyCalendarThree class to stor ...
- Aizu 2450 Do use segment tree 树链剖分+线段树
Do use segment tree Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.bnuoj.com/v3/problem_show ...
- SPOJ 11840. Sum of Squares with Segment Tree (线段树,区间更新)
http://www.spoj.com/problems/SEGSQRSS/ SPOJ Problem Set (classical) 11840. Sum of Squares with Segme ...
- BestCoder#16 A-Revenge of Segment Tree
Revenge of Segment Tree Problem Description In computer science, a segment tree is a tree data struc ...
- [LintCode] Segment Tree Build II 建立线段树之二
The structure of Segment Tree is a binary tree which each node has two attributes startand end denot ...
- [LintCode] Segment Tree Build 建立线段树
The structure of Segment Tree is a binary tree which each node has two attributes start and end deno ...
- Segment Tree Modify
For a Maximum Segment Tree, which each node has an extra value max to store the maximum value in thi ...
随机推荐
- Linux objdump命令
一.简介 objdump命令是用查看目标文件或者可执行的目标文件的构成的gcc工具. 二.选项 http://my.oschina.net/alphajay/blog/7729 http://man. ...
- PhpStorm 2017 激活办法
最新版PhpStorm 2017正式版改进了PHP 7支持,改进代码完成功能.PhpStorm 绝对是PHP开发最好的开发工具. phpstorm已经升级到2017.1,原注册码失效,2017.1.2 ...
- window.name跨域实现
参考:window.name实现的跨域数据传输 有三个页面: a.com/app.html:应用页面. a.com/proxy.html:代理文件,一般是一个没有任何内容的html文件,需要和应用页面 ...
- SQLServerException:将截断字符串或二进制数据的解决方法
SQLServerException:将截断字符串或二进制数据的解决方法: 最近使用JPA进行保存对象到数据库中怎么也添加不进去,始终报错 主要原因就是你增加的数据字段长度超过数据库中字段所定义长度, ...
- 2018.09.09 codeforces280C. Game on Tree(期望dp)
传送门 期望dp经典题. 显然只需要算出每个点被染黑的期望步数. 点i被染黑的期望是1/(1到i这条链上的节点数)" role="presentation" style= ...
- java浅拷贝和深拷贝
转:http://blog.csdn.net/u014727260/article/details/55003402 实现clone的2点: 1,clone方法是Object类的一个方法,所以任何一个 ...
- MATLAB矩阵的一些用法
1.怎样去提取和修改矩阵中的一个元素. (1)创建一个矩阵 >> A=[1,2,3,4;5,6,7,8;9,10,11,12;13,14,15,16]A = 1 2 ...
- redis只加载AOF文件
如果同时配置写AOF和RDB两种文件,但在redis启动时,只会加载AOF,除非配置只写RDB,才会加载RDB文件,也因此AOF文件必须是全量数据,所以会越来越大,这缺点也将是redis优化的一个方向 ...
- 关于Python Package下的Module import方式[转]
2012年有一个目标我没有达成,那就是深入学习和使用Python语言.这个目标被其他学习任务和工作无情的抢占了,当然最主要的原因还是我重视不够^_^. 近期恰逢有一些Python工程的开发工作要做,就 ...
- 下拉菜单 - - css
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...