[bzoj 1208]STL水过
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1208
看网上的题解都用的手写数据结构……然而直接用set的lower_bound就水过去了……
#include<bits/stdc++.h>
using namespace std; const int md=;
set<int> pet,people; int main()
{
int n;
scanf("%d",&n);
int ans=;
while (n--)
{
int op,x;
scanf("%d%d",&op,&x);
if (op==)
{
if (people.empty())
{
pet.insert(x);
}
else
{
set<int>::iterator it = people.lower_bound(x);
if (it==people.begin())
{
ans=(ans+abs(*it-x))%md;
}
else if (it==people.end())
{
--it;
ans=(ans+abs(*it-x))%md;
}
else
{
set<int>::iterator it2=--it;
++it;
if (abs(*it2-x)<=abs(*it-x)) --it;
ans=(ans+abs(*it-x))%md;
}
people.erase(it);
}
}
else
{
if (pet.empty())
{
people.insert(x);
}
else
{
set<int>::iterator it = pet.lower_bound(x);
if (it==pet.begin())
{
ans=(ans+abs(*it-x))%md;
}
else if (it==pet.end())
{
--it;
ans=(ans+abs(*it-x))%md;
}
else
{
set<int>::iterator it2=--it;
++it;
if (abs(*it2-x)<=abs(*it-x)) --it;
ans=(ans+abs(*it-x))%md;
}
pet.erase(it);
}
}
}
printf("%d\n",ans);
return ;
}
[bzoj 1208]STL水过的更多相关文章
- bzoj 1208 宠物收养所--splay
		
这个题也是单点维护,不管来的是人还是狗,只要num=0就插入,否则就删除. // File Name: ACM/bzoj/1208.cpp // Author: Zlbing // Created T ...
 - BZOJ 1208 宠物收养所 | 平衡树模板题
		
BZOJ 1208 宠物收养所 我犯过的错误:删除一个节点后没有update新的根节点,导致size错了! #include <cstdio> #include <cmath> ...
 - 【BZOJ】初级水题列表——献给那些想要进军BZOJ的OIers(自用,怕荒废了最后的六月考试月,刷刷水题,水水更健康)
		
BZOJ初级水题列表——献给那些想要进军BZOJ的OIers 代码长度解释一切! 注:以下代码描述均为C++ RunID User Problem Result Memory Time Code_Le ...
 - BZOJ 1208: [HNOI2004]宠物收养所 SET的妙用
		
1208: [HNOI2004]宠物收养所 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 4902 Solved: 1879 题目连接 http:/ ...
 - BZOJ 1208: [HNOI2004]宠物收养所
		
1208: [HNOI2004]宠物收养所 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 7514 Solved: 2982[Submit][Sta ...
 - hdu4585 STL水题
		
题意: 成立少林寺,刚开始有一个大师,id是1,攻击力是10E,现在陆续来人,每个人有自己的id,和自己的攻击力,但是每一个新来的要和之前的和尚pk,他必须选择和他攻击力差值最小的那个,如 ...
 - bzoj 1208: [HNOI2004]宠物收养所  set
		
1208: [HNOI2004]宠物收养所 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 7328 Solved: 2892[Submit][Sta ...
 - BZOJ 1208 宠物收养所
		
Description 最近,阿Q开了一间宠物收养所.收养所提供两种服务:收养被主人遗弃的宠物和让新的主人领养这些宠物.每个领养者都希望领养到自己满意的宠物,阿Q根据领养者的要求通过他自己发明的一个特 ...
 - BZOJ 1208: [HNOI2004]宠物收养所(BST)
		
本来想先用set写一遍,再自己写个splay或treap,不过用set过了之后就懒得去写了....以后有空再来写吧..(不会有空的吧= = ------------------------------ ...
 
随机推荐
- uva 540 - Team Queue(插队队列)
			
首发:https://mp.csdn.net/mdeditor/80294426 例题5-6 团体队列(Team Queue,UVa540) 有t个团队的人正在排一个长队.每次新来一个人时,如果他有队 ...
 - 线程基础三 使用C#中的lock关键词
			
C#中lock关键字主要是为确保当一个线程使用某些资源时,同时无法其他线程无法使用该资源.下面我们看看下面的小例子. static void Main(string[] args) { var c = ...
 - ubuntu配置机器学习环境(一) ubuntu安装
			
第一部分:Ubuntu14.04安装 Step :安装Ubuntu Step 1.1:准备安装U盘 首先到官网下载Ubuntu的镜像,我使用的是Ubuntu 14.04.3的ISO. 然后使用Ultr ...
 - 带你认识Xmanager
			
XManager是一款小巧.便捷的浏览远端X窗口系统的工具.在工作中经常使用Xmanager来登录远端的Solaris系统,在X窗口系统上作图形化的操作.但是,Xmanager默认并不提供对于中文的支 ...
 - C#的特性Attribute
			
一.什么是特性 特性是用于在运行时传递程序中各种元素(比如类.方法.结构.枚举.组件等)的行为信息的声明性标签,这个标签可以有多个.您可以通过使用特性向程序添加声明性信息.一个声明性标签是通过放置在它 ...
 - 新版IdFTP解决中文乱码问题
			
用XE10后开发FTP客户端,发现有中文乱码问题.这里也主要是编码的问题,在connect链接后,需要设置编码方可. 注意: IndyTextEncoding_OSDefault; 该代码可能需 ...
 - pxe无人值守安装linux机器笔记----摘抄
			
1. 基建工作 1.关闭防火墙 a)service iptables stop b)service ip6tables stop c)chkconfig iptables off d)chkconfi ...
 - Returning Values from Bash Functions
			
转自:https://www.linuxjournal.com/content/return-values-bash-functions Bash functions, unlike function ...
 - Linux中java应用程序的部署,使其开机自动启动
			
初步需求:将在Windows/MyEclipse中开发的java应用程序部署到Linux服务器上,使其运行 针对需求,可以参考下面这些文章,但是这些文章很多东西没有提及到,我自己尝试部署运行 在lin ...
 - MySQL用户权限控制一例
			
Preface I supposed we are encountering a situation that there's an anonymous user has connec ...