【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;如何通过通过数据库内存配置设置提高其性能&#…

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

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

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

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

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第三步&…

【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…

【牛客 - 283E】贪心只能过样例(模拟)

题干&#xff1a; 小西是单身狗&#xff0c;所以她不喜欢看到有CP在秀恩爱&#xff01; 有一天&#xff0c;小西出来闲逛&#xff0c;发现街上的行人都排成了一排&#xff0c;并且可以用这种形式表示&#xff1a; MMFMMFFFMMM 其中M表示男孩子&#xff0c;F表示女装的男孩…

apmserver导入MySQL_mysql数据库导入导出

window下1.导出整个数据库mysqldump -u 用户名 -p 数据库名 > 导出的文件名mysqldump -u dbuser -p dbname > dbname.sql2.导出一个表mysqldump -u 用户名 -p 数据库名 表名> 导出的文件名mysqldump -u dbuser -p dbname users> dbname_users.sql3.导出一个数据库结…

【牛客 - 283C】模拟只会猜题意(简单模拟)

题干&#xff1a; 小西突然觉得回文串是一种非常优雅的东西&#xff0c;她突然想要把身边所有的字符串都变成回文&#xff01; 所谓回文串就是一个倒置后仍与自身相等的字符串&#xff0c;如“gxuacmmcauxg”和“gxuacmcauxg”。 小西不喜欢单身狗&#xff0c;所以小西只会…

sql开启mysql远程连接_SQLServer2008设置开启远程连接

SQLServer2008设置开启INTERNET远程连接 SQL Server 2008默认是不允许远程连接的&#xff0c;sa帐户默认禁用的&#xff0c;如果想要在本地用SSMS连接远程服务器上的SQL Server 2008&#xff0c;需要做两个部分的配置&#xff1a; 使用sa账户登录SQL Server Management Studio(…

【牛客 - 283H】图论一顿套模板(思维转化,Dijkstra)

题干&#xff1a; 由于临近广西大学建校90周年校庆&#xff0c;西大开始了喜闻乐见的校园修缮工程&#xff01; 然后问题出现了&#xff0c;西大内部有许许多多的道路&#xff0c;据统计有N栋楼和M条道路&#xff08;单向&#xff09;&#xff0c;每条路都有“不整洁度”W&…

spss相关性分析看结果_spss相关性分析

当我们想要了解变量的相关程度时,就需要用到相关分析,而相关分析也是回归之前很重要的一步,通常用到的方法是pearson方法。 首先解释一下相关系数,相关系数反应的是两个变量之间变化趋势的方向以及程度,其值范围为-1到+1,正值表示正相关,负值表示负相关,绝对值越大表示…

【牛客 - 283F】出装方案(最小费用最大流)

题干&#xff1a; 众所周知&#xff0c;在各种对抗类游戏里装备都是很重要的一环&#xff0c;不同的出装方案会给玩家带来不同的强度。 dalao手里有N件装备&#xff0c;现在dalao要把装备分给N个队友&#xff0c;每个队友只能分一件装备&#xff0c;而每个队友穿上不同的装…

【CodeForces - 289D】Polo the Penguin and Houses (带标号的无根树,Cayley定理,Prufer编码)

题干&#xff1a; Little penguin Polo loves his home village. The village has n houses, indexed by integers from 1 to n. Each house has a plaque containing an integer, the i-th house has a plaque containing integer pi (1 ≤ pi ≤ n). Little penguin Po…

【CodeForces - 289E 】Polo the Penguin and XOR operation (数学,异或,贪心)

题干&#xff1a; Little penguin Polo likes permutations. But most of all he likes permutations of integers from 0 to n, inclusive. For permutation p  p0, p1, ..., pn, Polo has defined its beauty — number . Expression means applying the operation …

【CodeForces - 922B 】Magic Forest (数学,异或,暴力,水题,三元组问题)

题干&#xff1a; Imp is in a magic forest, where xorangles grow (wut?) A xorangle of order n is such a non-degenerate triangle, that lengths of its sides are integers not exceeding n, and the xor-sum of the lengths is equal to zero. Imp has to count the …

java生产者消费者代码_Java实现Kafka生产者消费者代码实例

Kafka的结构与RabbitMQ类似&#xff0c;消息生产者向Kafka服务器发送消息&#xff0c;Kafka接收消息后&#xff0c;再投递给消费者。生产者的消费会被发送到Topic中&#xff0c;Topic中保存着各类数据&#xff0c;每一条数据都使用键、值进行保存。每一个Topic中都包含一个或多…

【CodeForces - 304B】Calendar (前缀和,水题)

题干&#xff1a; Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendars scheme of le…

java 刷新jtextarea_Java JTextArea不能实时刷新的问题

相信JTextArea用法都了解吧&#xff0c;JTextArea textArea new JTextArea();生成一块空白的区域&#xff0c; 我的需求就是点击发送邮件按钮后&#xff0c;后台的执行日志能输出到textArea中。但是我点击发送按钮的时候&#xff0c;由于邮件的附件要好久&#xff0c;界面一直…

【CodeForces - 312C】The Closest Pair (思维)

题干&#xff1a; Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Excee…

【牛客 - 272A】Phrase String(构造,水题)

题干&#xff1a; 给出v, k&#xff0c;请你找到最小的正整数n&#xff0c;满足&#xff1a; n的二进制表示下存在一个长度为v的回文串&#xff0c;该回文串首尾都是1且n的二进制表示中至少有k个1。保证v,k均为偶数&#xff01; 由于n可能很大&#xff0c;你只需要输出对取模的…