E. Parking Lot
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

A parking lot in the City consists of n parking spaces, standing in a line. The parking spaces are numbered from 1 to n from left to right.

When a car arrives at the lot, the operator determines an empty parking space for it. For the safety's sake the chosen place should be located as far from the already occupied places as possible. That is, the closest occupied parking space must be as far away as possible. If there are several such places, then the operator chooses the place with the minimum index from them. If all parking lot places are empty, then the car gets place number 1.

We consider the distance between the i-th and the j-th parking spaces equal to 4·|i - j| meters.

You are given the parking lot records of arriving and departing cars in the chronological order. For each record of an arriving car print the number of the parking lot that was given to this car.

Input

The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 2·105) — the number of parking places and the number of records correspondingly.

Next m lines contain the descriptions of the records, one per line. The i-th line contains numbers tiidi (1 ≤ ti ≤ 2; 1 ≤ idi ≤ 106). If tiequals 1, then the corresponding record says that the car number idi arrived at the parking lot. If ti equals 2, then the corresponding record says that the car number idi departed from the parking lot.

Records about arriving to the parking lot and departing from the parking lot are given chronologically. All events occurred consecutively, no two events occurred simultaneously.

It is guaranteed that all entries are correct:

  • each car arrived at the parking lot at most once and departed from the parking lot at most once,
  • there is no record of a departing car if it didn't arrive at the parking lot earlier,
  • there are no more than n cars on the parking lot at any moment.

You can consider the cars arbitrarily numbered from 1 to 106, all numbers are distinct. Initially all places in the parking lot are empty.

Output

For each entry of an arriving car print the number of its parking space. Print the numbers of the spaces in the order, in which the cars arrive to the parking lot.

Examples
input
7 11
1 15
1 123123
1 3
1 5
2 123123
2 15
1 21
2 3
1 6
1 7
1 8
output
1
7
4
2
7
4
1
3

思路:区间合并;搓代码;

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
const int N=2e5+,M=1e6+,inf=1e9+,mod=1e9+;
const ll INF=1e18+;
map<int,int>mp;
int n,m;
struct is
{
int llen;
int rlen;
int l,r,ans;
}tree[N<<];
int getmaxx(int l,int r)
{
if(l==)
return r;
if(r==n)
return r-l+;
return (r+l)/-l+;
}
void build(int l,int r,int pos)
{
tree[pos].l=l;
tree[pos].r=r;
tree[pos].llen=tree[pos].rlen=(r-l+);
tree[pos].ans=getmaxx(l,r);
if(l==r)return;
int mid=(l+r)>>;
build(l,mid,pos<<);
build(mid+,r,pos<<|);
}
void pushup(int pos,int l,int r)
{
int mid=(l+r)>>;
tree[pos].llen=tree[pos<<].llen;
tree[pos].rlen=tree[pos<<|].rlen;
if(tree[pos<<].ans==&&tree[pos<<|].ans==)
{
tree[pos].ans=;
}
else if(tree[pos<<].ans>=tree[pos<<|].ans&&tree[pos<<].ans>=getmaxx(mid-tree[pos<<].rlen+,mid+tree[pos<<|].llen))
{
tree[pos].l=tree[pos<<].l;
tree[pos].r=tree[pos<<].r;
tree[pos].ans=getmaxx(tree[pos].l,tree[pos].r);
if(tree[pos<<].ans==getmaxx(mid-tree[pos<<].rlen+,mid+tree[pos<<|].llen)&&tree[pos<<].l>=mid-tree[pos<<].rlen+)
{
tree[pos].l=mid-tree[pos<<].rlen+;
tree[pos].r=mid+tree[pos<<|].llen;
tree[pos].ans=getmaxx(tree[pos].l,tree[pos].r);
}
}
else if(getmaxx(mid-tree[pos<<].rlen+,mid+tree[pos<<|].llen)>=tree[pos<<|].ans)
{
tree[pos].l=mid-tree[pos<<].rlen+;
tree[pos].r=mid++tree[pos<<|].llen-;
tree[pos].ans=getmaxx(tree[pos].l,tree[pos].r);
}
else
{
tree[pos].l=tree[pos<<|].l;
tree[pos].r=tree[pos<<|].r;
tree[pos].ans=getmaxx(tree[pos].l,tree[pos].r);
}
if(tree[pos<<].llen==mid-l+)
tree[pos].llen+=tree[pos<<|].llen;
if(tree[pos<<|].rlen==r-(mid+)+)
tree[pos].rlen+=tree[pos<<].rlen;
}
void update(int p,int c,int l,int r,int pos)
{
if(l==p&&r==p)
{
if(!c)
{
tree[pos].llen=tree[pos].rlen=tree[pos].ans=;
}
else
{
tree[pos].llen=tree[pos].rlen=tree[pos].ans=;
tree[pos].l=p;
tree[pos].r=p;
}
return;
}
int mid=(l+r)>>;
if(p<=mid)
update(p,c,l,mid,pos<<);
else
update(p,c,mid+,r,pos<<|);
pushup(pos,l,r);
}
int main()
{
scanf("%d%d",&n,&m);
build(,n,);
while(m--)
{
int flag,x;
scanf("%d%d",&flag,&x);
if(flag==)
{
int pos=(tree[].l+tree[].r)>>;
if(tree[].l==)
pos=;
else if(tree[].r==n)
pos=n;
update(pos,,,n,);
printf("%d\n",pos);
mp[x]=pos;
}
else
{
update(mp[x],,,n,);
mp[x]=;
}
}
return ;
}

Codeforces Round #135 (Div. 2) E. Parking Lot 线段数区间合并的更多相关文章

  1. 树形DP Codeforces Round #135 (Div. 2) D. Choosing Capital for Treeland

    题目传送门 /* 题意:求一个点为根节点,使得到其他所有点的距离最短,是有向边,反向的距离+1 树形DP:首先假设1为根节点,自下而上计算dp[1](根节点到其他点的距离),然后再从1开始,自上而下计 ...

  2. 构造 Codeforces Round #135 (Div. 2) B. Special Offer! Super Price 999 Bourles!

    题目传送门 /* 构造:从大到小构造,每一次都把最后不是9的变为9,p - p MOD 10^k - 1,直到小于最小值. 另外,最多len-1次循环 */ #include <cstdio&g ...

  3. 贪心 Codeforces Round #135 (Div. 2) C. Color Stripe

    题目传送门 /* 贪心:当m == 2时,结果肯定是ABABAB或BABABA,取最小改变量:当m > 2时,当与前一个相等时, 改变一个字母 同时不和下一个相等就是最优的解法 */ #incl ...

  4. Codeforces Round #603 (Div. 2) E. Editor(线段树)

    链接: https://codeforces.com/contest/1263/problem/E 题意: The development of a text editor is a hard pro ...

  5. Codeforces Round #135 (Div. 2)

    A. k-String 统计每个字母出现次数即可. B. Special Offer! Super Price 999 Bourles! 枚举末尾有几个9,注意不要爆掉\(long\ long\)的范 ...

  6. Codeforces Round #135 (Div. 2) D. Choosing Capital for Treeland dfs

    D. Choosing Capital for Treeland time limit per test 3 seconds memory limit per test 256 megabytes i ...

  7. Codeforces Round #135 (Div. 2)---A. k-String

    k-String time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...

  8. Codeforces Round #135 (Div. 2) D - Choosing Capital for Treeland(两种树形DP)

  9. Codeforces Round #135 (Div. 2) D. Choosing Capital for Treeland

    time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standa ...

随机推荐

  1. TI CC2541的GPIO引脚设置.

    P1SEL寄存器, 0xF4, 功能选择用的, 0表示GPIO口, 1表示外设.

  2. 关于Quartus II 13.0对应开发NIOS II软件程序时报错Symbol 'NULL' could not be resolved问题的解决方法

    关于Quartus II 13.0对应开发NIOS II软件程序时报错Symbol 'NULL' could not be resolved问题的解决方法 近期在评估使用NIOS II处理器进行项目的 ...

  3. Centos7下使用ELK(Elasticsearch + Logstash + Kibana)搭建日志集中分析平台

    日志监控和分析在保障业务稳定运行时,起到了很重要的作用,不过一般情况下日志都分散在各个生产服务器,且开发人员无法登陆生产服务器,这时候就需要一个集中式的日志收集装置,对日志中的关键字进行监控,触发异常 ...

  4. 教你ECSHOP去版权与标志(新增272版)

    前台部分: 1:去掉头部TITLE部分的ECSHOP演示站 Powered by ecshop 前者在后台商店设置 - 商店标题修改 后者打开includes/lib_main.php $page_t ...

  5. Oracle中左右外连接详解

    数据表的连接有:  1.内连接(自然连接): 只有两个表相匹配的行才能在结果集中出现 2.外连接: 包括 (1)左外连接(左边的表不加限制) (2)右外连接(右边的表不加限制) (3)全外连接(左右两 ...

  6. android5.0 编译

    android5.0编译需要jdk1.7版本,将来本地可能需要同时维护两套jdk版本,请参考: 在线安装openjdk1.7 sudo apt-get install openjdk-7-jre op ...

  7. 20150618_Andriod _set Dialog_弹出式菜单

    参考地址: http://blog.csdn.net/zhyl8157121/article/details/8169172                   http://blog.csdn.ne ...

  8. Unity胶囊体的碰撞检测实现

    可选是否打开矩阵变换,支持xyz三种朝向 using UnityEngine; using System.Collections; using System.Collections.Generic; ...

  9. 栈——PowerShell版

    上一篇讲过队列(queue),队列就像是居民楼里的垃圾管道,从楼道的垃圾管道的入口处将垃圾扔进去,清洁工会从一楼垃圾管道的出口处将垃圾拿走.每一层的垃圾通道入口与一楼的垃圾管道出口之间都形成了一个队列 ...

  10. Spark系列之二——一个高效的分布式计算系统

    1.什么是Spark? Spark是UC Berkeley AMP lab所开源的类Hadoop MapReduce的通用的并行计算框架,Spark基于map reduce算法实现的分布式计算,拥有H ...