(STL之set与multiset)SPOJ
来源:互联网 发布:幼儿园虐童 知乎 编辑:程序博客网 时间:2024/05/22 15:55
ADAFIELD - Ada and Field
Ada the Ladybug owns a beautiful field where she grows vegetables. She often visits local Farmers Market, where she buys new seeds. Since two types of vegetable can't share same field, she always divide the field, by either vertical or horizontal line (she is very precise, so the width of line is negligible). Since she visits Farmers Market almost every day, she has already made a lot of such lines, so she needs your help with finding out the area of biggest field.
Input
The first line will contain 0 < T ≤ 200, the number of test-cases.
Then T test-cases follow, each beginning with three integers 1 ≤ N,M ≤ 2*109, 1 ≤ Q ≤ 105, top right corner of field (field goes from [0,0] to [N,M]) and number of field divisions.
Afterward Q lines follows:
0 x (0 ≤ x ≤ N), meaning that line was made vertically, on coordinate x
1 y (0 ≤ y ≤ M), meaning that line was made horizontally, on coordinate y
Sum of Q over all test-cases won't exceed 106
Output
Print Q lines, the area of biggest field after each line was made.
Example Input
210 10 50 50 81 11 91 510 10 50 51 41 61 80 5
Example Output
50504540205030202020
解析:
不了解set与multiset的话会感到有些无从下手,使用之后问题就变得简单。
分别建立set维护行列中线的位置,以及multiset记录行间距、列间距。
每次最大面积就是行间距最大值*列间距最大值(注意这个可能超过int范围)
以插入新的一行为例(显然,列同理)
如果之前没有插入过这一行:
利用lower_bound找到第一个比它高的行(由于初始化时将边界都insert进去,所以必定存在)之前行间距记录的是这一行及比其低的第一行的间距,要更新为插入的这一行与它们的行间距。只要erase原本的行间距,插入新的两个行间距即可。
如果之前插入过:
无需进行任何操作。
#include<bits/stdc++.h>using namespace std;set<int>hang,lie;multiset<int>hlen,llen;long long an;typedef long long ll;int t,n,m,Q;int len,zuo,you;int tem,num;set<int>::iterator p;multiset<int>::iterator q;int main(){ cin>>t; while(t--) { cin>>n>>m>>Q; hang.clear(); lie.clear(); hlen.clear(); llen.clear(); hang.insert(0); hang.insert(n); hlen.insert(n); lie.insert(0); lie.insert(m); llen.insert(m); while(Q--) { scanf("%d%d",&tem,&num); if(tem==1) { if(lie.find(num)==lie.end()) { p=lie.lower_bound(num); you=*p; p--; zuo=*p; q=llen.find(you-zuo); llen.erase(q); len=you-num; llen.insert(len); len=num-zuo; llen.insert(len); lie.insert(num); } } else { if(hang.find(num)==hang.end()) { p=hang.lower_bound(num); you=*p; p--; zuo=*p; q=hlen.find(you-zuo); hlen.erase(q); len=you-num; hlen.insert(len); len=num-zuo; hlen.insert(len); hang.insert(num); } } q=llen.end(); q--; an=(ll)(*q); q=hlen.end(); q--; an*=(ll)(*q); cout<<an<<endl; } }}
- (STL之set与multiset)SPOJ
- STL学习之路二(set与multiset)
- STL之Set与Multiset(转)
- STL-------set与multiset
- STL之set&multiset容器(笔记)
- STL之set/multiset(二)
- STL中的set与multiset
- stl库之set、multiset
- STL之set和multiset
- STL容器之Set,MultiSet
- STL容器之set/multiset
- STL之set/multiset容器
- STL之set和multiset
- C++之STL(5)之 set 与 multiset
- STL学习之set与multiset操作练习
- STL 之set和multiset(江南烟雨)
- STL 之 初识set multiset(map multimap)
- 第20章STL set与multiset
- 获取Crash信息、分包
- MyEclipse集成PMD代码检测插件自定义规则配置文件
- 《PHP中添加文字水印函数封装》
- 100. Same Tree
- Window下ActiveMQ报错 LifecycleProcessor not initialized
- (STL之set与multiset)SPOJ
- 图解Linux命令之--join命令
- 常用端口号及对应服务
- Linux Tomcat日志查看实用命令
- spring mvc错误收集
- Mapped Statements collection does not contain value for com.china.bill.java.dao.UserDao.addUser
- c++实现单例模式--单线程环境
- 学习Javascript闭包(Closure)阮一峰
- 输出某年某月某日某时某分某秒的下一秒的时间:年、月、时、分、秒