数据结构维护二维平面

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

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

此处有三种做法

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. Django auth权限

    创建超级管理员命令 python manage.py createsuperuser --username hello 检查和校验用户 from django.contrib import auth ...

  2. 测试框架 Mocha 实例教程(转载:来自阮一峰的一篇文章)

    Mocha(发音"摩卡")诞生于2011年,是现在最流行的JavaScript测试框架之一,在浏览器和Node环境都可以使用. 所谓"测试框架",就是运行测试的 ...

  3. blog.yiz96.com

    欢迎访问我的新博客 blog.yiz96.com

  4. Difference between x:Reference and x:Name

    {x:Reference ...} -> returns just a reference of an object it doesn't create that "bridge&qu ...

  5. 安装pycharm 2018.3 Professional Edition

    1.下载pycharm 2018.3 Professional 2.下载破解补丁,Gitee仓库 或 直接下载(Direct download link) ,并放到pycharm目录下的\bin目录( ...

  6. javaEE(14)_文件上传下载

    一.文件上传概述 1.实现web开发中的文件上传功能,需完成如下二步操作: •在web页面中添加上传输入项•在servlet中读取上传文件的数据,并保存到本地硬盘中. 2.如何在web页面中添加上传输 ...

  7. SimpleWeather APP

    参考 iOS 7 Best Practices; A Weather App Case Study: Part 1/2 iOS 7 Best Practices; A Weather App Case ...

  8. Vue构建项目

    构建Vue项目 按照官网教程安装 //先安装脚手架 cnpm i -g vue-cli //查看项目目标列表: webpack browserify pwa 等项目模板 vue list //使用we ...

  9. Fortran学习笔记6(函数、子程序)

    子程序Subroutine 自定义函数Function 全局变量COMMON BLOCK DATA 程序代码中,常常会在不同的地方重复用到某一功能和重复某一代码,这个时候就要使用函数.函数包括内嵌函数 ...

  10. Bzoj 1088: [SCOI2005]扫雷Mine (DP)

    Bzoj 1088: [SCOI2005]扫雷Mine 怒写一发,算不上DP的游戏题 知道了前\(i-1\)项,第\(i\)项会被第二列的第\(i-1\)得知 设\(f[i]\)为第一列的第\(i\) ...