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. 1.4 isAlive()方法

    方法isAlive()是判断当前线程是否处于活动状态. 线程代码: public class TestThread extends Thread{ @Override public void run( ...

  2. keepalive安装和配置

    1.下载安装包并解压 sudo wget http://www.keepalived.org/software/keepalived-1.2.13.tar.gz tar zxvf keepalived ...

  3. virtual judge(专题一 简单搜索 C)

    Description Farmer John has been informed of the location of a fugitive cow and wants to catch her i ...

  4. Oracle数据库安全性设计

    一.什么是安全的系统 安全性建设是一个长期并且卓绝的工作.作为一个符合标准的企业级系统,我们认为税务系统应该具备以下的安全性特点: ◆高可用性 ◆对敏感数据的访问控制能力. ◆监测用户行为的审计能力. ...

  5. 转载:Android应用的自动更新模块

    软件的自动更新一般都与Splash界面绑定在一起, 由于需要维护的软件界面很复杂, 一个Activity中嵌入ViewPager, 并且逻辑比较复杂, 索性重新写一个Activity, 现在的软件都很 ...

  6. mongodb 修改操作

    $addToSet与$each结合完成批量数组更新 db.text.update({_id:1000},{$addToSet:{books:{$each:["js","d ...

  7. [原创]SQL表值函数:返回自定义时间段的日期数据

    跟以往类似,我依旧介绍一个我日常开发遇到的知识点,谨此记录一下,也希望能帮助到一些朋友. 这次我要介绍的是通过SQL函数返回你输入的两个时间点内的日期数据. 效果图如下: 执行函数:SELECT * ...

  8. Spring IOC 少

    控制反转好处 IOC:控制反转也叫依赖注入,IOC利用java反射机制,AOP利用代理模式.所谓控制反转是指,本来被调用者的实例是有调用者来创建的,这样的缺点是耦合性太强,IOC则是统一交给sprin ...

  9. pig入门教程(2)

    本文可以让刚接触pig的人对一些基础概念有个初步的了解. 本文的大量实例都是作者Darran Zhang(website: codelast.com)在工作.学习中总结的经验或解决的问题,并且添加了较 ...

  10. 关于login/interactive/no-interactive shell和profile/bash_profile/bashrc

    login shell:第一次登录进系统时的shell,一般是指本机启动时的控制台shell或者ssh远程登录时的shell. interactive shell:登录以后,再打开控制台时运行的she ...