527C. Glass Carving【平衡二叉树】
来源:互联网 发布:华悦网络下载 编辑:程序博客网 时间:2024/04/28 23:49
Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a rectangularw 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 formH y or V x. In the first case Leonid makes the horizontal cut at the distancey 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 distancex (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 4H 2V 2V 3V 1
8442
7 6 5H 4V 3V 5H 2V 1
28161264
Picture for the first sample test:
#include<iostream>#include<cstdio>#include<cstring>#include<ctime>#include<algorithm>#include <map>#include <queue>#include <set>using namespace std;//527C 红黑二叉排序树int main(){ int w,h,n; cin>>w>>h>>n; set<int >W,H; set<int >::iterator i,j; multiset <int >A,B; multiset <int >::iterator e1,e2; W.insert(0),W.insert(w); H.insert(0),H.insert(h); A.insert(h),B.insert(w); char ch; int a; while(n--) { cin>>ch>>a; if(ch=='H') { i=j=H.lower_bound(a); i--; H.insert(a); A.insert((*j)-a); A.insert(a-(*i)); A.erase(A.find((*j)-(*i))); } else { i=j=W.lower_bound(a); i--; W.insert(a); B.insert((*j)-a); B.insert(a-(*i)); B.erase(B.find((*j)-(*i))); } e1=A.end(),e2=B.end(); e1--,e2--; long long int ans=((long long int)(*e1)*(*e2)); cout<<ans; } return 0;}
平衡二叉检索树使用中序遍历算法,检索效率高于vector、deque和list等容器,另外使用中序遍历可将键值按照从小到大遍历出来。
构造set集合主要目的是为了快速检索,不可直接去修改键值。
- 527C. Glass Carving【平衡二叉树】
- Codeforces 527C Glass Carving
- CodeForces 527C Glass Carving
- codeforces 527C Glass Carving
- CF 527C Glass Carving
- Codeforces 527C Glass Carving 线段树区间合并
- Codeforces 527C Glass Carving(Set)
- Codeforces 527C Glass Carving (set+multiset)
- Codeforces 527 C Glass Carving----瞎搞
- CodeForces 527C Glass Carving(multiset)
- Codeforces 527C Glass Carving【思维+模拟】
- CF 527C Glass Carving 思路
- Codeforces 527C Glass Carving (set+multiset)
- C. Glass Carving
- CodeForces 527C. Glass Carving (SBT/线段树/std::set)
- CodeForces 527C - Glass Carving set multiset 二分
- CodeForces 527C:Glass Carving (set与multiset应用)
- CF 296 div2 C. Glass Carving (线段树)
- iOS NSNotificationCenter详解
- Nice Patterns Strike Back(位运算dp+大数矩阵快速幂)
- nyoj 506 洗澡
- 数控车床机械结构_02
- Sicily 11158. Numbers and Words
- 527C. Glass Carving【平衡二叉树】
- 10个诀窍助你成为牛逼的远程开发人员
- uva 11762
- Sicily 1501. Minimal Backgammon
- nyoj312 20岁生日
- Linux内核开发的特点
- 判断输入字符是否为数字
- uva 10285 Longest Run on a Snowboard (记忆化搜索)
- 开博客地一天