数据结构维护二维平面

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

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

此处有三种做法

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. 仿天猫淘宝的ShopNC好商城原生Android 客户端源码项目

    开发环境:Android Studio 2.0 | Gradle 2.0.0最后更新:2016-04-28 简介:基于好商城V4的Android客户端 目前已完成的功能(概述): 1.启动页 -> ...

  2. Hibernate学习之简单应用

    前言:博主在学到Spring的时候,要开始做项目了,突然觉得好像有点虚,之前学过的Hibernate框架的简单应用好像又忘记了.所以返回来,做个小笔记. 简单来讲,Hibernate框架是利用对象-关 ...

  3. iOS7.1企业应用"无法安装应用程序 因为证书无效"的解决方案

    今天升级了iOS7.1后发现通过之前的url无法安装企业应用了,一直提示“无法安装应用程序 因为http://xxx.xxx.xxx证书无效”,折腾了一番,终于在StackOverFlow上找到了答案 ...

  4. vue watch 监听

    1.普通的watch data() { return { frontPoints: 0 } }, watch: { frontPoints(newValue, oldValue) { console. ...

  5. Asp.Net Core 进阶(一) —— 读取appsettings.json

    我们以前在Asp.Net MVC中使用 System.Configuration.ConfigurationManager 来读取web.config文件.但是Asp.Net Core MVC已经没有 ...

  6. 爬虫4_python2

    import urllib2 response = urllib2.urlopen("https://www.baidu.com") print response.read() 构 ...

  7. CPP-基础:关于引用

    1.什么是“引用”?申明和使用“引用”要注意哪些问题? 引用就是某个目标变量的“别名”(alias),对应用的操作与对变量直接操作效果完全相同. 申明一个引用的时候,切记要对其进行初始化. 引用声明完 ...

  8. 数据库-SQL语法:GROUP BY与HAVING

    注意:select 后的字段,必须要么包含在group by中,要么包含在having 后的聚合函数里. 1. GROUP BY 是分组查询, 一般 GROUP BY 是和聚合函数配合使用. grou ...

  9. java在线聊天项目0.5版 解决客户端向服务器端发送信息时只能发送一次问题 OutputStreamWriter DataOutputStream socket.getOutputStream()

    没有解决问题之前客户端代码: package com.swift; import java.awt.BorderLayout; import java.awt.Color; import java.a ...

  10. React初识整理(五)--Redux和Flux(解决状态传递问题)

    Flux 1.引入:在React的应⽤中,状态管理是⼀个⾮常重要的⼯作.我们不会直接对DOM节点进⾏操作,⽽是通过将数据设置给state,由state来同步UI,这种⽅式有个潜在的问题,每个组件都有独 ...