【题目链接】:http://codeforces.com/contest/527/problem/C

【题意】



让你切割一个长方形;

只能横切或竖切;

让你实时输出切完之后最大的长方形的面积;

【题解】



这里最大的长方形的面积对应的就是最大的竖线间隔*最大的横线间隔;

我们先把所有的边读入->存起来

然后分成横线和竖线两类;

按照位置从小到大排个序;

然后先求出第n个询问的答案

也即这个时候竖线的最大间隔和横线的最大间隔;

然后离线处理;

逆序删掉第i条线

然后维护这个时候最大的横线和竖线间隔;

因为只会删掉一条边,

所以只要考虑这条边左边最靠近它的线和它右边最靠近它的线;

看看它们俩的差值能不能更新横线或者是竖线的最大间隔;

用一个类似链表的东西模拟删除的过程就好;



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define ps push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x) typedef pair<int, int> pii;
typedef pair<LL, LL> pll; const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 2e5+100; struct abc
{
LL pos;
int l,r;
}; LL w, h,x,gap_heng,gap_shu, pp[N];
int n,sshu,sheng;
char p[N][5];
vector <abc> shu, heng;
vector <LL> ans;
abc temp; bool cmp(abc a, abc b)
{
return a.pos < b.pos;
} int main()
{
//freopen("F:\\rush.txt", "r", stdin);
rel(w), rel(h), rei(n);
rep1(i, 1, n)
{
scanf("%s", p[i]); rel(pp[i]);
temp.pos = pp[i];
if (p[i][0] == 'V')
shu.ps(temp);
else
heng.ps(temp);
}
temp.pos = 0; shu.ps(temp); heng.ps(temp);
temp.pos = w; shu.ps(temp); temp.pos = h, heng.ps(temp);
sort(shu.begin(), shu.end(),cmp),sort(heng.begin(), heng.end(),cmp);
sshu = shu.size();
rep1(i, 1, sshu - 2)
{
shu[i].l = i - 1;
shu[i].r = i + 1;
}
rep1(i, 1, sshu - 1)
{
gap_shu = max(gap_shu, shu[i].pos - shu[i - 1].pos);
} sheng = heng.size();
rep1(i, 1, sheng - 2)
{
heng[i].l = i - 1;
heng[i].r = i + 1;
}
rep1(i, 1, sheng - 1)
{
gap_heng = max(gap_heng, heng[i].pos - heng[i - 1].pos);
} rep2(i, n, 1)
{
ans.ps(gap_heng*gap_shu);
if (p[i][0] == 'V')
{
temp.pos = pp[i];
int pos = lower_bound(shu.begin(), shu.end(), temp,cmp) - shu.begin();
int l = shu[pos].l, r = shu[pos].r;
gap_shu = max(gap_shu, shu[r].pos - shu[l].pos);
shu[l].r = r;
shu[r].l = l;
}
else
{
temp.pos = pp[i];
int pos = lower_bound(heng.begin(), heng.end(), temp,cmp) - heng.begin();
int l = heng[pos].l, r = heng[pos].r;
gap_heng = max(gap_heng, heng[r].pos - heng[l].pos);
heng[l].r = r;
heng[r].l = l;
}
}
rep2(i, n - 1, 0)
{
printf("%lld\n", ans[i]);
}
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}

【codeforces 527C】Glass Carving的更多相关文章

  1. 【CF527C】Glass Carving

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

  2. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  3. [codeforces 528]A. Glass Carving

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

  4. 【15.07%】【codeforces 625A】Guest From the Past

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  5. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  6. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  7. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  8. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  9. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

随机推荐

  1. PCB CS架构(工程系统)实现单点登入方法

    社会的不断进步发展,分工也越来越细了.而我们工作接触的范围也越来越狭小了,但这不是倒退了,而是分工之细让人们在各个方面深耕细作.PCB企业软件系统发展路线同样也如此,随着我们PCB企业发展不断壮大,软 ...

  2. PCB SQL Server 代码创建DbLink

    代码如下: ) ) ) ) ) SET @serverName = 'DbLinkName' --db链接名 SET @ip = '120.79.36.65' --需连接服务器的IP SET @dbN ...

  3. php验证手机号是否合法

    用正则匹配手机号码的时候, 我们先分析一下手机号码的规律: 1. 手机号通常是11位的 2. 经常是1开头 3. 第二个数字通常是34578这几个数字, 2014.5.5日170号段的手机号开卖所以这 ...

  4. php中strlen,mb_strlen,count之区别

    转自 http://www.cnblogs.com/mo-beifeng/archive/2011/08/09/2133039.html 这不是一个固定的数字.本文简要说明一下限制规则. strlen ...

  5. VUE element-ui下拉列表获取label值

    有这样一个场景,当我们往后台数据传的是id时,我们却想在前台获取列表显示的值,这时候可以用下面的方法来获取你想要的label值 let obj = {}; obj = this.arr.find((i ...

  6. 数塔问题mod 100(orz)

    看一下题目 和普通的数字三角形看似没啥区别(区别很大) 然后去想:DP方程 DP[i][j]=Max(DP[i-][j],DP[i-][j-])+a[i][j] ans=Max(DP[n][..n]) ...

  7. python 生成器函数.推导式.生成器表达式

    一.生成器 什么是生成器,生成器的实质就是迭代器 在python中有三种方式来获取生成器: 1.通过生成器函数 2.通过各种推导式来实现生成器 3.通过数据的转换也可以获取生成器 1 def func ...

  8. [转]linux grep命令

    转自:http://www.cnblogs.com/end/archive/2012/02/21/2360965.html 1.作用Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表 ...

  9. activity间传递参数

    传递值对象 值对象可以理解为自定义的数据类型对象. 为了完成这个知识点的讲解,先来创建一个User类型的类,它有name和age两个属性,然后请添加getter/setter方法,构造方法等基本方法. ...

  10. android shape stroke只绘制一边或者某几边

    <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android=" ...