数据结构维护二维平面

首先横着切与竖着切是完全没有关联的,

简单贪心,最大子矩阵的面积一定是最大长*最大宽

此处有三种做法

1.用set来维护,每次插入操作寻找这个点的前驱和后继,并维护一个计数数组,来维护最大值

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstring>
#include <set>
using namespace std;
const int MAXN = 400005;
int init() {
int rv = 0, fh = 1;
char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') fh = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
rv = (rv<<1) + (rv<<3) + c - '0';
c = getchar();
}
return fh * rv;
}
int w, h, n, maw, mah, cnt1[MAXN], cnt2[MAXN];
set <int> s1, s2;
set <int> :: iterator u, v;
int main() {
freopen("in.txt", "r", stdin);
w = init(); h = init(); n = init();
mah = h; maw = w;
cnt1[mah]++; cnt2[maw]++;
s1.insert(h);s2.insert(0);s2.insert(w);s1.insert(0); //要提前把这两个点加上
for(int i = 1 ; i <= n ; i++) {
char c;
scanf(" %c ", &c);
int t = init();
if(c == 'H'){
s1.insert(t);
u = v =s1.find(t);
u--; v++;
cnt1[*v - *u]--;
cnt1[*v - t]++; cnt1[t - *u]++;
while(!cnt1[mah]) mah--; //此处因为mah是不增的,所以这个操作的总复杂度是O(h)
}else {
s2.insert(t);
u = v =s2.find(t);
u--; v++;
cnt2[*v - *u]--;
cnt2[*v - t]++; cnt2[t - *u]++;
while(!cnt2[maw]) maw--;
}
printf("%lld\n", (long long)maw * mah);
}
fclose(stdin);
return 0;
}
  1. 平衡树,与set类似

  2. 线段树,用 \(01\) 序列表示某条边哪里被切割,本题就变成了维护最长连续0

    区间需要维护: 区间左右开始连续0的长度, 区间最长连续0的长度, 区间是否全为0

CF 527C Glass Carving的更多相关文章

  1. Codeforces 527C Glass Carving

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

  2. Codeforces 527C Glass Carving(Set)

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

  3. Codeforces 527C Glass Carving (最长连续0变形+线段树)

    Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glas ...

  4. CodeForces 527C. Glass Carving (SBT,线段树,set,最长连续0)

    原题地址:http://codeforces.com/problemset/problem/527/C Examples input H V V V output input H V V H V ou ...

  5. 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 ...

  6. C. Glass Carving (CF Round #296 (Div. 2) STL--set的运用 &amp;&amp; 并查集方法)

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

  7. CF # 296 C Glass Carving (并查集 或者 multiset)

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

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

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

  9. [codeforces 528]A. Glass Carving

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

随机推荐

  1. (八)mybatis之映射器

    映射器 映射器是由Java接口和XML文件(或注解)共同组成的,作用如下: ①   定义参数类型. ②   描述缓存. ③   描述SQL语句. ④   定义查询结果和POJO的映射关系. 以下用两种 ...

  2. 使用memcached缓存 替代solr中的LRUCache缓存

    前沿 在搜索引擎中,缓存被当做是不可缺少的部分,但是很多情况下,将缓存的实现过度依赖于分发服务器及webserver会很大程度上加重webserver 的负担,具体表现就是经常性的假死,拒绝服务,因此 ...

  3. Error:(3, 32) java: 程序包org.springframework.boot不存在

     解决方案一: 找同事传一份D:\maven_repository\org\springframework\boot  ,如图所示的位置,添加进去立刻就不报红.我也可以给你发....  解决方案二: ...

  4. LeetCode 字符串的排列

    给定两个字符串 s1 和 s2,写一个函数来判断 s2 是否包含 s1 的排列. 换句话说,第一个字符串的排列之一是第二个字符串的子串. 示例1: 输入: s1 = "ab" s2 ...

  5. hihoCoder-1109-堆优化的Prim

    优先队列是由堆组成的,所以当我们使用优先队列对Prim进行优化时,就把这种优化叫做堆优化. 它的算法核心思想就是每次向后找边,每个pair存的都是下一个点,以及边权.我们对于已经走过的点就避开,这样就 ...

  6. xadmin下设置“use_bootswatch = True”无效的解决办法

    环境: python 2.7 django 1.9 xadmin采用源代码的方式引入到项目中 问题: 在xadmin使用的过程中,设置“use_bootswatch = True”,企图调出主题菜单, ...

  7. (42)zabbix使用IT services 了解服务器SLA整体情况

    什么是IT Services 服务器或者某项服务.业务的可用率,不懂技术的上级领导会过问最近服务器可用率如何.所有api的状况怎么样? 通常一些技术人员会说负载怎么样,哪些cpu使用率怎么样,硬盘使用 ...

  8. 《零基础入门学习Python》【第一版】视频课后答案第006讲

    python中被看作假:FALSE  none 0  ‘ ’  " "  ( ) [ ] { },其他一切都被解释为真 测试题答案: 0.Python 的 floor 除法现在使用 ...

  9. Codeforces C. Sonya and Problem Wihtout a Legend(DP)

    Description Sonya was unable to think of a story for this problem, so here comes the formal descript ...

  10. Handler处理器和自定义Opener

    Handler处理器 和 自定义Opener opener是 urllib2.OpenerDirector 的实例,我们之前一直都在使用的urlopen,它是一个特殊的opener(也就是模块帮我们构 ...