http://codeforces.com/problemset/problem/527/C

这题总体思路就是,每画一条线,然后就找到x间距的最max值和y间距的最max值,相乘就是当前的ans

那么我需要维护这样的一个数列,每次往里面添加一个元素,然后查询相邻两个元素的差值的最大值。

倒着做比较简单,首先把所有元素插上去,然后最大值直接暴力算一次。然后后来只有删除操作,这个操作只会让最大值变大。

每次删除后,检查上面和下面的新间距,和最大值比较一下就好。

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;
set<int> ss[];
LL ans[ + ];
struct Node {
char op;
int val;
}node[ + ];
void fuck(int id) {
if (node[id].op == 'H') {
ss[].erase(node[id].val);
} else ss[].erase(node[id].val);
}
void work() {
int w, h, n;
cin >> w >> h >> n;
ss[].insert(); ss[].insert(w);
ss[].insert(); ss[].insert(h);
set<int> :: iterator it1, it2;
for (int i = ; i <= n; ++i) {
char str[];
int val, flag = false;
scanf("%s%d", str, &val);
if (str[] == 'H') {
ss[].insert(val);
} else ss[].insert(val);
node[i].op = str[];
node[i].val = val;
}
int mx1 = ; // v
it2 = ss[].begin();
it2++;
for (it1 = ss[].begin(); it2 != ss[].end(); ++it2, ++it1) {
mx1 = max(mx1, *it2 - *it1);
}
int mx2 = -inf;
it2 = ss[].begin();
it2++;
for (it1 = ss[].begin(); it2 != ss[].end(); ++it2, ++it1) {
mx2 = max(mx2, *it2 - *it1);
}
ans[n] = 1LL * mx1 * mx2;
// cout << mx1 << " " << mx2 << endl;
fuck(n);
mx1 = ; // v
it2 = ss[].begin();
it2++;
for (it1 = ss[].begin(); it2 != ss[].end(); ++it2, ++it1) {
mx1 = max(mx1, *it2 - *it1);
}
mx2 = ;
it2 = ss[].begin();
it2++;
for (it1 = ss[].begin(); it2 != ss[].end(); ++it2, ++it1) {
mx2 = max(mx2, *it2 - *it1);
}
for (int i = n - ; i >= ; --i) {
if (node[i].op == 'H') {
it1 = ss[].lower_bound(node[i].val);
it2 = it1;
it2++;
mx2 = max(mx2, *it2 - *it1);
it2 = it1;
it1--;
mx2 = max(mx2, *it2 - *it1);
it1++;
} else {
it1 = ss[].lower_bound(node[i].val);
it2 = it1;
it2++;
mx1 = max(mx1, *it2 - *it1);
it2 = it1;
it1--;
mx1 = max(mx1, *it2 - *it1);
it1++;
}
it2 = it1;
it2++;
it1--;
fuck(i);
ans[i] = 1LL * mx1 * mx2;
if (node[i].op == 'H') {
mx2 = max(mx2, *it2 - *it1);
} else mx1 = max(mx1, *it2 - *it1);
}
for (int i = ; i <= n; ++i) {
cout << ans[i] << endl;
}
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
work();
return ;
}

写的很乱,因为是绝杀的。

正着也可以。

用一个multiset来维护当前拥有的差值,一开始是h

然后每添加一条边,可以找出在原数组中的上界和下界,这个差值是要删除的那个差值,然后添加新差值即可。

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;
set<int> x, y;
multiset<int> xx, yy;
void work() {
int w, h, n;
cin >> w >> h >> n;
x.insert(), x.insert(w);
y.insert(), y.insert(h);
xx.insert(w), yy.insert(h);
for (int i = ; i <= n; ++i) {
char str[];
int pos;
cin >> str >> pos;
if (str[] == 'H') {
auto it1 = y.lower_bound(pos);
int d1 = *it1;
it1--;
int d2 = *it1;
auto del = yy.lower_bound(d1 - d2);
yy.erase(del);
yy.insert(d1 - pos);
yy.insert(pos - d2);
y.insert(pos);
} else {
auto it1 = x.lower_bound(pos);
int d1 = *it1;
it1--;
int d2 = *it1;
auto del = xx.lower_bound(d1 - d2);
xx.erase(del);
xx.insert(d1 - pos);
xx.insert(pos - d2);
x.insert(pos);
}
auto itx = xx.rbegin(), ity = yy.rbegin();
cout << 1LL * (*itx) * (*ity) << endl;
}
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
IOS;
work();
return ;
}

C. Glass Carving 正着做或者倒着做都可以的更多相关文章

  1. Codeforces 527C Glass Carving

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

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

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

  4. [codeforces 528]A. Glass Carving

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

  5. Codeforces 527C Glass Carving(Set)

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

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

  7. 【CF527C】Glass Carving

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

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

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

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

随机推荐

  1. bzoj 1941 [Sdoi2010]Hide and Seek——KDtree

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1941 第二道KDtree! 枚举每个点,求出距离它的最远和最近距离.O( n * logn ...

  2. WPF如何更改系统控件的默认高亮颜色 (Highlight brush)

    我们在用WPF时, 经常会对系统控件的默认高亮等等颜色进行更改. 以前通常是用controlTemplate来实现. 今天发现一个更合理或者简单的方法: 用系统默认颜色的key, 比如 SystemC ...

  3. css基础知识二

    1.盒模型: 实际宽度:外边距*2+内边距*2+边框*2+内容宽度(注意这点,可解决界面元素轻微浮动问题,如hover有边框,以前没的时候会有轻微浮动) 作用:他规定了网页元素如何显示以及其相互关系 ...

  4. 《Kubernetes权威指南第2版》学习(四)kubernetes基本概念和术语

    1: etcd是干什么的: 键-值存储仓库,用来配置共享和服务发现. k8s把Node, pod,replication controller, Services看做是资源对象,这些资源对象可以通过K ...

  5. ASP.NET MVC 3:缓存功能的设计问题

    今天这一篇文章我来谈一谈在MVC 3项目中的缓存功能,以及针对缓存的一些设计上的考量,给大家参考参考. 为什么需要讨论缓存?缓存是一个中大型系统所必须考虑的问题.为了避免每次请求都去访问后台的资源(例 ...

  6. [解决问题]ubuntu无法virtualenv创建python虚拟环境的解决

    刚有人问我Ubuntu python虚拟环境无法创建问题,报错same file error,防止今后遇到忘记,记录下可能的问题. 1.先在windows上试了下: pip install virtu ...

  7. Java探索之旅(5)——数组

    1.声明数组变量:        double[] array=new double[10];         double array[]=new double[10];       double[ ...

  8. LDA与最小二乘法的关系及其变种详解

    1 LDA与最小二乘法的关联 对于二值分类问题,令人惊奇的是最小二乘法和LDA分析是一致的.回顾之前的线性回归,给定N个d维特征的训练样例(i从1到N),每个对应一个类标签.我们之前令y=0表示一类, ...

  9. 2017 world final

    E 解题关键:二分时注意C函数的单调性. #include<bits/stdc++.h> #define eps 1e-8 #define INF 0x3f3f3f3f using nam ...

  10. 【总结整理】JQuery基础学习---样式篇

    进入官方网站获取最新的版本 http://jquery.com/download/    中文 https://www.jquery123.com/ <!--JQuery:轻量级的JavaScr ...