题意:n*m的方格,“0 x”表示x轴在x位置切一刀,“0 y”表示y轴在y位置切一刀,每次操作后输出当前面积最大矩形。

思路:用set分别储存x轴y轴分割的点,用multiset(可重复)储存x轴y轴边,每次输出最大的长和最大的宽的积。题目可能重复切。multiset如果直接erase(13)会把所有的13都删掉,如果只想删一个则erase(multiset.find(13))。第一次知道set自带二分...

这里multiset也可以用map<int, int, greater<int> >,然后用迭代器指向最后一个key就行了

代码:

#include<set>
#include<map>
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn = + ;
const int seed = ;
const int MOD = + ;
const int INF = 0x3f3f3f3f;
set<ll> x, y;
multiset<ll> lenx, leny;
int main(){
int T;
ll n, m, q;
scanf("%d", &T);
while(T--){
scanf("%lld%lld%lld", &n, &m, &q);
x.clear();
y.clear();
lenx.clear();
leny.clear();
x.insert(),x.insert(n),lenx.insert(n);
y.insert(),y.insert(m),leny.insert(m);
set<ll>::iterator it;
while(q--){
ll o, p;
scanf("%lld%lld", &o, &p);
if(o == && x.count(p) == ){
it = x.lower_bound(p);
lenx.insert(*it - p);
int len = *it - *(--it);
lenx.erase(lenx.find(len));
lenx.insert(p - *it);
x.insert(p);
}
else if(o == && y.count(p) == ){
it = y.lower_bound(p);
leny.insert(*it - p);
int len = *it - *(--it);
leny.erase(leny.find(len));
leny.insert(p - *it);
y.insert(p);
}
it = lenx.end();
ll chang = *(--it);
it = leny.end();
ll kuan = *(--it);
printf("%lld\n", chang * kuan);
}
}
return ;
}

SPOJ ADAFIELD Ada and Field(STL的使用:set,multiset,map的迭代器)题解的更多相关文章

  1. STL——容器(Set & multiset)的迭代器

    1.set.insert(elem);     //在容器中插入元素. 2.set.begin();         //返回容器中第一个数据的迭代器. 3.set.end();          / ...

  2. SPOJ - ADAFIELD ,Set+map,STL不会超时!

    ADAFIELD - Ada and Field 这个题,如果用一个字来形容的话:-----------------------------------------------嗯! 题意:n*m的空白 ...

  3. STL笔记(1)map

    STL笔记(1)map STL之map ZZ from http://hi.baidu.com/liyanyang/blog/item/d5c87e1eb3ba06f41bd576cf.html 1. ...

  4. vector源码(参考STL源码--侯捷):空间分配导致迭代器失效

    vector源码1(参考STL源码--侯捷) vector源码2(参考STL源码--侯捷) vector源码(参考STL源码--侯捷)-----空间分配导致迭代器失效 vector源码3(参考STL源 ...

  5. C/C++解题常用STL大礼包 含vector,map,set,queue(含优先队列) ,stack的常用用法

    每次忘记都去查,真难啊 /* C/C++解题常用STL大礼包 含vector,map,set,queue(含优先队列) ,stack的常用用法 */ /* vector常用用法 */ //头文件 #i ...

  6. STL中的Set和Map——入门新手篇

    STL中的Set和Map 先来看一段网络上的文字描述: 上图是一段关于STL中Set集合的描述,同样的,也近似适合Map的描述.上述文字中,描述了最为重要的特征: Set和Map,底层调用了红黑树的结 ...

  7. SPOJ:Ada and Orange Tree (LCA+Bitset)

    Ada the Ladybug lives near an orange tree. Instead of reading books, she investigates the oranges. T ...

  8. [SPOJ 30669] Ada and Trip

    [题目链接] https://www.spoj.com/problems/ADATRIP/ [算法] 直接使用dijkstra堆优化算法即可 [代码] #include<bits/stdc++. ...

  9. @spoj - ADAMOLD@ Ada and Mold

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个长度为 N 的序列 A,将其划分成 K + 1 段,划分 ...

随机推荐

  1. Can you answer these queries?---hdu4027

    题目链接 有n个数:当操作为1时求L到R的和: 当操作为0时更新L到R为原来的平方根: 不过如果仔细演算的话会发现一个2^64数的平方根开8次也就变成了 1,所以也更新不了多少次,所以可以每次更新到底 ...

  2. innodb next-key lock引发的死锁

    innodb的事务隔离级别是可重复读级别且innodb_locks_unsafe_for_binlog禁用,也就是说允许next-key lock CREATE TABLE `LockTest` (  ...

  3. mysql 权限管理 针对库 授权 db.*

    需求 只放行user表 db1库的select权限 mysql> grant select on db1.* to 'mike'@'localhost'; Query OK, rows affe ...

  4. Kafka介绍及安装部署

    本节内容: 消息中间件 消息中间件特点 消息中间件的传递模型 Kafka介绍 安装部署Kafka集群 安装Yahoo kafka manager kafka-manager添加kafka cluste ...

  5. 杀死正在运行的进程: linux

    1:杀死正在运行的进程:使用ps -aux|grep labor   查出进程PID 2:使用kill  PID  将进程杀死.

  6. dfs模板(真心不会深搜)

    栈 #include <stdio.h> #include <string.h> ][]; ][]; ,-, , }; , ,-, }; int Min; void dfs(i ...

  7. Py-apply用法学习【转载】

    转自:https://blog.csdn.net/anshuai_aw1/article/details/82347016 1.Apply Python中apply函数的格式为:apply(func, ...

  8. 非常不错的一个JS分页效果代码

    这里分享一个不错的js分页代码. 代码中cpage是页面计数,应为全局变量,可以随处调用它: totalpage是总页数. 与asp分页代码很类似,也是先取得记录总数,然后实现分页,基本的分页思路与原 ...

  9. Vagrant配置虚拟机

    慕课上学习.需要安装 vagrant  VirtualBox .box文件和.iso文件一样都是镜像文件.可以在官网下载https://www.vagrantup.com/docs/ 点击boxs之后 ...

  10. iOS 建立项目过滤机制 —— 给工程添加忽略文件.gitignore

        目前iOS 项目 主要忽略 临时文件.配置文件.或者生成文件等,在不同开发端这些文件会大有不同,如果 git add .把这些文件都push到远程, 就会造成不同开发端频繁改动和提交的问题. ...