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. java web基础知识

    1)TCP三次握手 第一次握手:客户端A将标志位SYN置为1,随机产生一个值为seq=J(J的取值范围为=1234567)的数据包到服务器,客户端A进入SYN_SENT状态,等待服务端B确认: 第二次 ...

  2. 快速实现CentOS7安装python-pip

    1.首先检查linux有没有安装python-pip包,终端执行 pip -V [root@ network-scripts]# pip -V -bash: pip: command not foun ...

  3. Zeppelin的入门使用系列之创建新的Notebook(一)

    不多说,直接上干货! 前期博客 hadoop-2.6.0.tar.gz + spark-1.6.1-bin-hadoop2.6.tgz + zeppelin-0.5.6-incubating-bin- ...

  4. UI面试题(1)

    1.请创建一个数组对象[@“ad”,@“bc”,@“sdf”,@“yu”],并且对该数组对象进行排序(使用冒泡排序); NSMutableArray *array = [NSMutableArraya ...

  5. Hander----使用

    public class MainActivity extends Activity { private EditText UITxt; private Button updateUIBtn; pri ...

  6. Spring的概况

    ----------------siwuxie095 Spring 的简介 Spring 是一个轻量级 控制反转(IoC) 和 面向切面(AOP) 的容器框架 年,它是为了解决企业应用开发的复杂性而诞 ...

  7. sklearn交叉验证法(Cross Validation)

    import numpy as np from sklearn import datasets from sklearn.cross_validation import train_test_spli ...

  8. 阶段2-新手上路\项目-移动物体监控系统\Sprint3-移动监控主系统设计与开发

    移动图像监控系统 去找一些相关开源程序进行移植:百度搜索-linux 移动监控 motion是一套免费开源的移动图像监测程序 前面我们已经使用了很多开源软件,他们的使用方法都是大同小异的 1).先在当 ...

  9. spring-cloud 服务优雅下线

      在集群环境下,zuul后面的api服务一般会有多个实例,当下线某个实例时,如果使用 kill -9 pid 的方式,会造成这个服务在eureka中还存在,请求还会路由到这个服务上面,造成500,所 ...

  10. 【转】solr源码导入eclipse

     http://blog.csdn.net/vltic/article/details/19917377   (1)相应的开发环境准备          (1)jdk1.6+的安装和环境变量配置(命令 ...