Codeforces Round #296 (Div. 2) C. Glass Carving [ set+multiset ]
2 seconds
256 megabytes
standard input
standard output
Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a rectangular w mm × h mm sheet of glass, a diamond glass cutter and lots of enthusiasm. What he lacks is understanding of what to carve and how.
In order not to waste time, he decided to practice the technique of carving. To do this, he makes vertical and horizontal cuts through the entire sheet. This process results in making smaller rectangular fragments of glass. Leonid does not move the newly made glass fragments. In particular, a cut divides each fragment of glass that it goes through into smaller fragments.
After each cut Leonid tries to determine what area the largest of the currently available glass fragments has. Since there appear more and more fragments, this question takes him more and more time and distracts him from the fascinating process.
Leonid offers to divide the labor — he will cut glass, and you will calculate the area of the maximum fragment after each cut. Do you agree?
The first line contains three integers w, h, n (2 ≤ w, h ≤ 200 000, 1 ≤ n ≤ 200 000).
Next n lines contain the descriptions of the cuts. Each description has the form H y or V x. In the first case Leonid makes the horizontal cut at the distance y millimeters (1 ≤ y ≤ h - 1) from the lower edge of the original sheet of glass. In the second case Leonid makes a vertical cut at distance x (1 ≤ x ≤ w - 1) millimeters from the left edge of the original sheet of glass. It is guaranteed that Leonid won't make two identical cuts.
After each cut print on a single line the area of the maximum available glass fragment in mm2.
4 3 4
H 2
V 2
V 3
V 1
8
4
4
2
7 6 5
H 4
V 3
V 5
H 2
V 1
28
16
12
6
4
Picture for the first sample test:
Picture for the second sample test:
10344839 | 2015-03-19 07:09:30 | njczy2010 | C - Glass Carving | GNU C++ | Accepted | 389 ms | 12556 KB |
题解:用两个set记录割点位置,用两个multiset记录割出来的块的大小
#include <cstdio>
#include <cstring>
#include <stack>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <set> #define ll long long
int const N = ;
int const M = ;
int const inf = ;
ll const mod = ; using namespace std; ll w,h,n;
set<ll> x;
set<ll> y;
multiset<ll> xp;
multiset<ll> yp;
ll xmax,ymax; void out(); void ini()
{
x.clear();y.clear();xp.clear();yp.clear();
x.insert();x.insert(w);
y.insert();y.insert(h);
xp.insert(w);yp.insert(h);
xmax=w;ymax=h;
// out();
} void solve()
{
ll i;
char s[];
ll v;
ll r,l;
ll le;
set<ll>::iterator it;
set<ll>::iterator it1;
set<ll>::iterator it2;
multiset<ll>::iterator it3;
for(i=;i<=n;i++){
scanf("%s%I64d",s,&v);
//printf(" i=%I64d s=%s v=%I64d\n",i,s,v);
if(s[]=='V'){
x.insert(v);
it=x.find(v);
it1=it2=it;
it1--;it2++;
l=*it1;
r=*it2;
le=r-l;
xp.erase(xp.find(le));
xp.insert(v-l);
xp.insert(r-v);
it3=xp.end();
it3--;
xmax=*it3;
//printf(" l=%I64d v=%I64d r=%I64d xmax=%I64d\n",l,v,r,xmax);
}
else{
y.insert(v);
it=y.find(v);
// printf(" *it=%I64d\n",*it);
it1=it2=it;
it1--;it2++;
l=*it1;
r=*it2;
le=r-l;
// printf(" *it1=%I64d *it2=%I64d le=%I64d\n",*it1,*it2,le);
yp.erase(yp.find(le));
yp.insert(v-l);
yp.insert(r-v);
it3=yp.end();
it3--;
ymax=*it3;
// printf(" *it3=%I64d\n",*it3);
// printf(" l=%I64d v=%I64d r=%I64d ymax=%I64d\n",l,v,r,ymax);
}
out();
}
} void out()
{
//printf(" xmax=%I64d ymax=%I64d\n",xmax,ymax);
printf("%I64d\n",xmax*ymax );
} int main()
{
//freopen("data.in","r",stdin);
//scanf("%d",&T);
//for(cnt=1;cnt<=T;cnt++)
while(scanf("%I64d%I64d%I64d",&w,&h,&n)!=EOF)
{
ini();
solve();
// out();
}
}
Codeforces Round #296 (Div. 2) C. Glass Carving [ set+multiset ]的更多相关文章
- 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 ...
- Codeforces Round #296 (Div. 1) C. Data Center Drama 欧拉回路
Codeforces Round #296 (Div. 1)C. Data Center Drama Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xx ...
- 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 ...
- CodeForces Round #296 Div.2
A. Playing with Paper 如果a是b的整数倍,那么将得到a/b个正方形,否则的话还会另外得到一个(b, a%b)的长方形. 时间复杂度和欧几里得算法一样. #include < ...
- Codeforces Round #296 (Div. 1) E. Triangles 3000
http://codeforces.com/contest/528/problem/E 先来吐槽一下,一直没机会进div 1, 马力不如当年, 这场题目都不是非常难,div 2 四道题都是水题! 题目 ...
- 字符串处理 Codeforces Round #296 (Div. 2) B. Error Correct System
题目传送门 /* 无算法 三种可能:1.交换一对后正好都相同,此时-2 2.上面的情况不可能,交换一对后只有一个相同,此时-1 3.以上都不符合,则不交换,-1 -1 */ #include < ...
- 水题 Codeforces Round #296 (Div. 2) A. Playing with Paper
题目传送门 /* 水题 a或b成倍的减 */ #include <cstdio> #include <iostream> #include <algorithm> ...
- Codeforces Round #296 (Div. 2) A. Playing with Paper
A. Playing with Paper One day Vasya was sitting on a not so interesting Maths lesson and making an o ...
- Codeforces Round #296 (Div. 2) A B C D
A:模拟辗转相除法时记录答案 B:3种情况:能降低2,能降低1.不能降低分别考虑清楚 C:利用一个set和一个multiset,把行列分开考虑.利用set自带的排序和查询.每次把对应的块拿出来分成两块 ...
随机推荐
- Math.net,.net上的科学计算利器
F#在科学计算领域的应用,包括部分语法介绍. Math.net,.net上的科学计算利器 摘要: .net上科学计算个人觉得首选numpy和scipy for dotnet.因为这两个库用户数量已经非 ...
- SpringBoot学习 (一) Eclipse中创建新的SpringBoot项目
1. Eclipse中安装STS插件 (1)在线安装 Help--Eclipse Marketplace... 搜索“STS”,点击“install”安装 (2)本地安装 打开网页 http:/ ...
- ios水果风暴游戏源码项目下载
这是一款ios水果风暴游戏源码下载,介绍给大家一下,喜欢的朋友可以下载学习一下吧.应用介绍:这是一个以获得高分和挑战更高难度为目的的游戏.游戏中有九种不同的卡通水果,您可以交换屏幕中两个相邻水果的位置 ...
- find、filter、map的区别
1.find 查询数组中符合条件的第一个元素,如果没有符合条件的元素则返回空数组 ,,,,,,] ) var men=[ {name:',sex:'女'}, {name:',sex:'nan'}, { ...
- 【转】C#的版本
这年头啥东东都喜欢过段时间整个啥新版本出来.汽车,手机如此,软件就更是如此了啊.比如啥Iphone 4,Iphone 5,Windows 8,Oracle 12C,SQL Server 2010. 版 ...
- sqlserver 分页问题
1.top 主要是在sql server 2000中使用,效率较差 2.row_number函数 这种方法是sql server 2005以后,支持了row_number函数后,才开始使用的. dec ...
- Sql Server 中锁的概念(1)
Sql Server 中锁的概念 锁的概述 一. 为什么要引入锁 多个用户同时对数据库的并发操作时会带来以下数据不一致的问题: 丢失更新A,B两个用户读同一数据并进行修改,其中一个用户的修改结果破 ...
- sleep 和wait的差别
基本的差别 1.sleep 是Thread 类的方法,wait 是Object类中定义的方法 2.sleep()方法可以在任何地方使用 3.wait()方法只能在synchronized方法中使用,或 ...
- 485. Max Consecutive Ones@python
Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [1, ...
- 11scrapy
一. Scrapy基础概念 Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架,我们只需要实现少量的代码,就能够快速的抓取.Scrapy 使用了 Twisted异步网络框架,可以加快我 ...