【CodeForces - 527C】Glass Carving(线段树或者SBT或者set)

题干:

Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a rectangular w mm  ×  h mm sheet of glass, a diamond glass cutter and lots of enthusiasm. What he lacks is understanding of what to carve and how.

In order not to waste time, he decided to practice the technique of carving. To do this, he makes vertical and horizontal cuts through the entire sheet. This process results in making smaller rectangular fragments of glass. Leonid does not move the newly made glass fragments. In particular, a cut divides each fragment of glass that it goes through into smaller fragments.

After each cut Leonid tries to determine what area the largest of the currently available glass fragments has. Since there appear more and more fragments, this question takes him more and more time and distracts him from the fascinating process.

Leonid offers to divide the labor — he will cut glass, and you will calculate the area of the maximum fragment after each cut. Do you agree?

Input

The first line contains three integers w, h, n (2 ≤ w, h ≤ 200 000, 1 ≤ n ≤ 200 000).

Next n lines contain the descriptions of the cuts. Each description has the form H yor V x. In the first case Leonid makes the horizontal cut at the distance ymillimeters (1 ≤ y ≤ h - 1) from the lower edge of the original sheet of glass. In the second case Leonid makes a vertical cut at distance x (1 ≤ x ≤ w - 1) millimeters from the left edge of the original sheet of glass. It is guaranteed that Leonid won't make two identical cuts.

Output

After each cut print on a single line the area of the maximum available glass fragment in mm2.

Examples

Input

4 3 4
H 2
V 2
V 3
V 1

Output

8
4
4
2

Input

7 6 5
H 4
V 3
V 5
H 2
V 1

Output

28
16
12
6
4

Note

Picture for the first sample test:

Picture for the second sample test:

题目大意:

本题给你一个H*V的矩阵,有两种操作,一种是横向切割,一种是纵向切割,每次切割后需要你输出当前状态下的最大矩形的面积是多大。

 

解题报告:

   其实将横纵分开来看就是找到最大的长和最大的宽最后相乘就是答案。可以线段树区间合并,可以set直接维护前驱后继和最大长度,也可以用平衡树去跑一波(不会过程)线段树就是区间最长连续1的个数,也不难在此就不练习了 。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 2e5 + 5;
set<int> h,v;
multiset<int> mh,mv;
set<int> :: iterator sit;
multiset<int> :: iterator musit;
int main()
{int H,V,m,x;char op[15];cin>>V>>H>>m;h.insert(0),h.insert(H);v.insert(0),v.insert(V);mh.insert(H),mv.insert(V);
//	printf("%d\n%d\n",*(--mh.end()),*(--mv.end()));while(m--) {scanf("%s%d",op,&x);if(op[0] == 'H') {h.insert(x);sit = h.find(x);sit++;int up = *sit;sit--;sit--;int low = *sit;musit = mh.find(up-low);mh.erase(musit);mh.insert(x-low);mh.insert(up-x);}else {v.insert(x);sit = v.find(x);sit++;int up = *sit;sit--;sit--;int low = *sit;musit = mv.find(up-low);mv.erase(musit);mv.insert(up-x);mv.insert(x-low);}
//		printf("%d\n%d\n",*(--mh.end()),*(--mv.end()));printf("%lld\n",(ll)(*(--mh.end())) * (*(--mv.end())));}return 0 ;}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441159.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

mysql常驻内存_MySQL的内存和相关问题排查

我们都知道数据库是IO密集型一类应用&#xff0c;为了提高其性能大量使用内存代替文件(交换分区)的IO操作是保证数据库稳定、高效的基本原则。那么数据库是如何使用内存的&#xff0c;我们如何查看数据库内存的占用&#xff0c;如何通过通过数据库内存配置设置提高其性能&#…

【HihoCoder - 1850】字母去重 (字符串,思维)

题干&#xff1a; 给定一个字符串S&#xff0c;每次操作你可以将其中任意一个字符修改成其他任意字符。 请你计算最少需要多少次操作&#xff0c;才能使得S中不存在两个相邻的相同字符。 Input 只包含小写字母的字符串S。 1 ≤ |S| ≤ 100000 Output 一个整数代表答案…

bash mysql count()_【MySQL】性能优化之 count(*) VS count(col)

优化mysql数据库时&#xff0c;经常有开发询问 count(1)和count(primary_key) VS count(*)的性能有何差异&#xff1f;看似简单的问题&#xff0c;估计会有很多人对此存在认知误区&#xff1a;1. 认为count(1) 和 count(primary_key) 比 count(*) 的性能好。2. count(column) 和…

【HihoCoder - 1851】D级上司 (树形图,dfs)

题干&#xff1a; H公司一共有N名员工&#xff0c;编号为1~N&#xff0c;其中CEO的编号是1。除了CEO之外&#xff0c;每名员工都恰好有唯一的直接上司&#xff1b;N名员工形成了一个树形结构。 我们定义X的1级上司是他的直接上司&#xff0c;2级上司是他上司的上司&#xf…

mysql录数据总是错误_MySQL数据库出错

在主库上备份表 t (假设备份快照 GTID 为 aaaa:1-10000)&#xff1b;恢复到从库&#xff1b;启动复制。这里的问题是复制起始位点是 aaaa:101&#xff0c;从库上表 t 的数据状态是领先其他表的。aaaa:101-10000 这些事务中只要有修改表 t 数据的事务&#xff0c;就会导致复制报…

linux安装mysql后怎么进去_linux安装mysql详细步骤

最近买了个腾讯云服务器&#xff0c;搭建环境。该笔记用于系统上未装过mysql的干净系统第一次安装mysql。自己指定安装目录&#xff0c;指定数据文件目录。linux系统版本&#xff1a; CentOS 7.3 64位安装源文件版本&#xff1a;mysql-5.7.21-linux-glibc2.12-x86_64.tar.gzmys…

给各位ACMer,OIer详细介绍一下Codeforces比赛

Codeforces 简称: cf(所以谈论cf的时候经常被误会成TX的那款游戏). 网址: codeforces.com   这是一个俄国的算法竞赛网站,由来自萨拉托夫州立大学、由Mike Mirzayanov领导的一个团队创立和维护,是一个举办比赛、做题和交流的平台.举办比赛和做题就不说了,“交流”指的是自带b…

【CodeForces - 278C 】Learning Languages(并查集,思维)

题干&#xff1a; The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of language…

java短除法获取二进制_Java十四天零基础入门-Java的数据类型介绍

不闲聊&#xff01;&#xff01;&#xff01;不扯淡&#xff01;&#xff01;&#xff01;小UP只分享Java相关的资源干货本章节目标&#xff1a;理解数据类型的作用。Java中包括哪些数据类型&#xff1f;常见的八种基本数据类型都有哪些&#xff1f;会用八种基本数据类型声明变…

【CodeForces - 151C】Win or Freeze (博弈,数学,唯一素数分解)

题干&#xff1a; You cant possibly imagine how cold our friends are this winter in Nvodsk! Two of them play the following game to warm up: initially a piece of paper has an integer q. During a move a player should write any integer number that is a non-tr…

vs怎么把textbox输入的实数放置变量里_方程的计算机处理96(3)_C++vs

计算机语言运用--数值计算9-方程的计算机处理96(3)_Cvs计算机&#xff1a;电子线路组成的计算机器。人与计算机则是通过计算机语言-符号系统说给计算机听而交流。计算机语言有低级语言-机器语言、汇编、高级语言-C/C/C#/VB/PASCAL/LISP/JAVA/PYTHON/……成百上千种之多。作为一…

【CodeForces - 151D】Quantity of Strings (字符串问题,思维推导,有坑)

题干&#xff1a; Just in case somebody missed it: this winter is totally cold in Nvodsk! It is so cold that one gets funny thoughts. For example, lets say there are strings with the length exactly n, based on the alphabet of size m. Any its substring with…

2008r装mysql_mysql5.7.17在win2008R2的64位系统安装与配置实例

安装MySql操作系统&#xff1a;Windows Server 2008 R2 StandardMySql版本&#xff1a;mysql-5.7.17-winx64第一步&#xff1a;解压mysql-5.7.17-winx64.zip到指定位置第二步&#xff1a;安装文件根目录下添加data文件夹&#xff0c;将my-default.ini重命名为my.ini第三步&…

【POJ - 2377】Bad Cowtractors (最大生成树,并查集)

题干&#xff1a; Bessie has been hired to build a cheap internet network among Farmer Johns N (2 < N < 1,000) barns that are conveniently numbered 1..N. FJ has already done some surveying, and found M (1 < M < 20,000) possible connection route…

csv转为utf8编码_读取UTF8编码的CSV并转换为UTF-16

我正在读取具有UTF8编码的CSV文件&#xff1a;ifile open(fname, "r")for row in csv.reader(ifile):name row[0]print repr(row[0])这很好用&#xff0c;并打印出我希望它打印出来的东西; UTF8编码 str &#xff1a;> \xc3\x81lvaro Salazar> \xc3\x89lodie…

【 CodeForces - 799A 】Carrot Cakes(模拟,细节,有坑)

题干&#xff1a; In some game by Playrix it takes t minutes for an oven to bake k carrot cakes, all cakes are ready at the same moment t minutes after they started baking. Arkady needs at least n cakes to complete a task, but he currently dont have any. H…

mysql 递归实现树形_Mysql实现树形递归查询

最近在做项目迁移&#xff0c;Oracle版本的迁到Mysql版本&#xff0c;遇到有些oracle的函数&#xff0c;mysql并没有&#xff0c;所以就只好想自定义函数或者找到替换函数的方法进行改造。Oracle递归查询oracle实现递归查询的话&#xff0c;就可以使用start with ... connect b…

【CH - 1401】 兔子与兔子(字符串哈希)

题干&#xff1a; 描述 很久很久以前&#xff0c;森林里住着一群兔子。有一天&#xff0c;兔子们想要研究自己的 DNA 序列。我们首先选取一个好长好长的 DNA 序列&#xff08;小兔子是外星生物&#xff0c;DNA 序列可能包含 26 个小写英文字母&#xff09;&#xff0c;然后我…

postmain请求中午乱码_完美解决Get和Post请求中文乱码的问题

对于Post请求&#xff0c;只需在Servlet或者jsp中写入如下代码就可以把解决从表单中传入的中文乱码问题request.setCharacterEncoding("utf-8");而对于Get请求&#xff0c;因为请求参数会被附加到地址栏的URL之后&#xff0c;所以不能用上面的处理方法。应该这样&…

【HDU - 5187】zhx's contest (快速幂+ 快速乘,模板)

题干&#xff1a; 2018百度之星复赛晋级名单出炉&#xff08;增加20%晋级名额&#xff09;~ zhxs contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 3779 Accepted Submission(s): 1226 Problem Desc…