C. Glass Carving
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a rectangular wmm  ×  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 y or V x. In the first case Leonid makes the horizontal cut at the distance y millimeters (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.

Sample test(s)
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

题意:给出一个n*m的矩阵,然后按照要求切线,问每切一条线分割后的最大矩形面积是多少?
分析:开4个set关联容器,其中sh存的是垂直线上的子区间长度,sw存的是水平线上的子区间长度,qh存的是划分的高度上的切割点,qw存的是划分宽度上的切割点,然后每次加入一条直线,先从q里面找出它的左右相邻的点,把该区间分割,然后用s维护子区间长度,每次把水平线上最大的子区间长度和垂直线上的最大子区间长度相乘即可
#include"cstdio"
#include"cstring"
#include"cstdlib"
#include"cmath"
#include"string"
#include"map"
#include"cstring"
#include"algorithm"
#include"iostream"
#include"set"
#include"queue"
#include"stack"
#define inf 0x3f3f3f3f
#define M 200009
#define LL __int64
#define eps 1e-8
#define mod 1000000007
using namespace std;
int w[M],h[M];
int main()
{
int W,H,n;
while(scanf("%d%d%d",&W,&H,&n)!=-)
{
set<int>sw,sh;
set<int>qw,qh;
sw.clear();
sh.clear();
memset(w,,sizeof(w));
memset(h,,sizeof(h));
sw.insert(W);
sw.insert(-W);
sh.insert(H);
sh.insert(-H);
qw.insert();
qw.insert(W);
qw.insert(-W);
qh.insert();
qh.insert(H);
qh.insert(-H);
w[W]++;
h[H]++;
char ch[];
int x;
while(n--)
{
scanf("%s%d",ch,&x);
if(ch[]=='H')
{
qh.insert(x);
qh.insert(-x);
int r=*(qh.upper_bound(x));
int l=-*(qh.upper_bound(-x));
if(h[r-l])//记录该长度出现的次数
h[r-l]--;
if(!h[r-l])
{
sh.erase(r-l);
sh.erase(l-r);
} sh.insert(x-l);
h[x-l]++;
sh.insert(r-x);
h[r-x]++;
sh.insert(l-x);
sh.insert(x-r);
}
else
{
qw.insert(x);
qw.insert(-x);
int r=*(qw.upper_bound(x));
int l=-*(qw.upper_bound(-x));
if(w[r-l])
w[r-l]--;
if(!w[r-l])
{
sw.erase(r-l);
sw.erase(l-r);
} sw.insert(x-l);
w[x-l]++;
sw.insert(r-x);
w[r-x]++;
sw.insert(l-x);
sw.insert(x-r);
}
set<int>::iterator r1,r2;
r1=sh.begin();
r2=sw.begin();
printf("%I64d\n",(LL)(*r1)*(*r2));
}
}
return ;
}
 #include"cstdio"
#include"cstring"
#include"cstdlib"
#include"cmath"
#include"string"
#include"map"
#include"cstring"
#include"algorithm"
#include"iostream"
#include"set"
#include"queue"
#include"stack"
#define inf 0x3f3f3f3f
#define M
#define LL __int64
#define eps 1e-8
#define mod
using namespace std;
int w[M],h[M];
int main()
{
int W,H,n;
while(scanf("%d%d%d",&W,&H,&n)!=-1)
{
set<int>sw,sh;
set<int>qw,qh;
sw.clear();
sh.clear();
memset(w,,sizeof(w));
memset(h,,sizeof(h));
sw.insert(W);
sw.insert(-W);
sh.insert(H);
sh.insert(-H);
qw.insert();
qw.insert(W);
qw.insert(-W);
qh.insert();
qh.insert(H);
qh.insert(-H);
w[W]++;
h[H]++;
char ch[];
int x;
while(n--)
{
scanf("%s%d",ch,&x);
if(ch[]=='H')
{
qh.insert(x);
qh.insert(-x);
int r=*(qh.upper_bound(x));
int l=-*(qh.upper_bound(-x));
if(h[r-l])//记录该长度出现的次数
h[r-l]--;
if(!h[r-l])
{
sh.erase(r-l);
sh.erase(l-r);
} sh.insert(x-l);
h[x-l]++;
sh.insert(r-x);
h[r-x]++;
sh.insert(l-x);
sh.insert(x-r);
}
else
{
qw.insert(x);
qw.insert(-x);
int r=*(qw.upper_bound(x));
int l=-*(qw.upper_bound(-x));
if(w[r-l])
w[r-l]--;
if(!w[r-l])
{
sw.erase(r-l);
sw.erase(l-r);
} sw.insert(x-l);
w[x-l]++;
sw.insert(r-x);
w[r-x]++;
sw.insert(l-x);
sw.insert(x-r);
}
set<int>::iterator r1,r2;
r1=sh.begin();
r2=sw.begin();
printf("%I64d\n",(LL)(*r1)*(*r2));
}
}
return ;
}

codeforces-Glass Carving(527C)std::set用法的更多相关文章

  1. Codeforces 527C Glass Carving

    vjudge 上题目链接:Glass Carving 题目大意: 一块 w * h 的玻璃,对其进行 n 次切割,每次切割都是垂直或者水平的,输出每次切割后最大单块玻璃的面积: 用两个 set 存储每 ...

  2. Codeforces 527C Glass Carving(Set)

    意甲冠军  片w*h玻璃  其n斯普利特倍  各事业部为垂直或水平  每个分割窗格区域的最大输出 用两个set存储每次分割的位置   就能够比較方便的把每次分割产生和消失的长宽存下来  每次分割后剩下 ...

  3. Glass Carving CodeForces - 527C (线段树)

    C. Glass Carving time limit per test2 seconds memory limit per test256 megabytes inputstandard input ...

  4. [codeforces 528]A. Glass Carving

    [codeforces 528]A. Glass Carving 试题描述 Leonid wants to become a glass carver (the person who creates ...

  5. Codeforces Round #296 (Div. 2) C. Glass Carving [ set+multiset ]

    传送门 C. Glass Carving time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  6. codeforces 527 C Glass Carving

    Glass Carving time limit per test 2 seconds Leonid wants to become a glass carver (the person who cr ...

  7. Codeforces Round #296 (Div. 1) A. Glass Carving Set的妙用

    A. Glass Carving time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  8. CF #296 (Div. 1) A. Glass Carving 线段树

    A. Glass Carving time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  9. 【CF527C】Glass Carving

    [CF527C]Glass Carving 题面 洛谷 题解 因为横着切与纵切无关 所以开\(set\)维护横着的最大值和纵着的最大值即可 #include <iostream> #inc ...

随机推荐

  1. delphi 高版本可执行程序减小的办法

    选菜单里的 Project -> Options.. (Shift+Ctrl+F11)出现Project Options for Project1.exe窗口,在左边选 Packages出现如下 ...

  2. mysql查询昨天本周上周上月

    昨天 $yestoday = date("Y-m-d 00:00:00",strtotime('-1day'));$today = date("Y-m-d 00:00:0 ...

  3. 【转】javascript中this的四种用法

    在函数执行时,this 总是指向调用该函数的对象.要判断 this 的指向,其实就是判断 this 所在的函数属于谁. 在<javaScript语言精粹>这本书中,把 this 出现的场景 ...

  4. 蓝牙4.0(包含BLE)简介

    1. BLE   (低功耗蓝牙)简介 国际蓝牙联盟( BT-SIG,TI  是 企业成员之一)通过的一个标准蓝牙无线协议. 主要的新特性是在蓝牙标准版本上添加了4.0 蓝牙规范 (2010 年6 月 ...

  5. docker squid---but git proxy should specify by git config --global http.proxy http:...

    Usage of loopback devices is strongly discouraged for production use. Either use `--storage-opt dm.t ...

  6. 转: PE rva to raw 虚拟偏移地址和文件物理偏移地址

    +---------+---------+---------+---------+---------+---------+| 段名称 虚拟地址 虚拟大小 物理地址 物理大小 标志 |+-------- ...

  7. css实现三角箭头

    像下面的向右三角箭头,只有纯css不需要图片就可以实现了. width:0px;height:0px;border-width:0px 16px 20px 16px; border-style:sol ...

  8. Cure---hdu5879(打表+找规律)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5879 题意:给你一个n ,求∑(1/k2), k from 1 to n; n的范围是不知道的,所以可 ...

  9. PresentViewController切换界面(一些系统自带的页面切换动画)

    视图切换,没有NavigationController的情况下,一般会使用presentViewController来切换视图并携带切换时的动画, 其中切换方法如下: – presentViewCon ...

  10. HTML标签的改变

    /*这些都是前端面试中经常考到的内容,必须要掌握的*/ 一.新的文档类型声明(DTD) 1.HTML5的DTD声明为:<!doctype html>或者<!DOCTYPE html& ...