喵哈哈村的冒菜店
发布时间: 2017年3月19日 16:00 最后更新: 2017年3月19日 16:01 时间限制: 1000ms 内存限制: 128M
喵哈哈村的冒菜店开张了,这里的冒菜特别好吃。
星星同学听闻后,就准备去吃冒菜。
星星同学开着自己才花了几十万买的宝马X5,就开进了冒菜店的停车场。
就在她停车的过程中,她发现一个有趣的现象,喵哈哈村的人们总是喜欢停车停在离别人车最远的地方,具体来说就是停在离所有车的距离最小值最大的位置,如果有多个,他们就喜欢停在编号小的位置上。
现在星星同学有一个疑问了:
这个停车场可以看做是拥有一排的停车位,这些停车位编号为1~n,初始都是空的。
如果有若干个汽车进进出出这停车场,那么这些汽车会停在哪些位置呢?
第一行两个整数n,m,表示停车场大小和操作数。
接下来m行,每行两个整数F和x。
F是1表示编号为x的车进停车场。
F是2表示编号为x的车出停车场。
保证操作合法。
满足n,m<=200000,x<=1000000
对于所有操作1,输出一个整数,表示该车车位的编号。
复制
7 11 1 15 1 123123 1 3 1 5 2 123123 2 15 1 21 2 3 1 6 1 7 1 8
1 7 4 2 7 4 1 3
题目:http://qscoj.cn/problem/48/
题解:http://www.cnblogs.com/qscqesze/p/6580390.html
#include<stdio.h>
typedef struct
{
int x, y;
int v, id;
}Tree;
Tree s[888888];
int car[1000005];
void Atonce(int p)
{
if(s[p*2].x>0)
s[p].x = s[p*2].x;
else
s[p].x = s[p*2+1].x;
if(s[p*2+1].y>0)
s[p].y = s[p*2+1].y;
else
s[p].y = s[p*2].y;
s[p].v = s[p*2].v, s[p].id = s[p*2].id;
if(s[p*2].y>0 && s[p*2+1].x>0 && (s[p*2+1].x-s[p*2].y)/2>s[p].v)
s[p].v = (s[p*2+1].x-s[p*2].y)/2, s[p].id = (s[p*2+1].x+s[p*2].y)/2;
if(s[p*2+1].v>s[p].v)
s[p].v = s[p*2+1].v, s[p].id = s[p*2+1].id;
}
void Update(int l, int r, int loc, int p, int type)
{
int m;
m = (l+r)/2;
if(l==r)
{
s[p].x = s[p].y = type*r;
return;
}
if(loc<=m)
Update(l, m, loc, p*2, type);
else
Update(m+1, r, loc, p*2+1, type);
Atonce(p);
}
int main(void)
{
int n, m, t, k;
scanf("%d%d", &n, &m);
while(m--)
{
scanf("%d%d", &t, &k);
if(t==1)
{
if(s[1].x==0)
car[k] = 1;
else
{
if(s[1].x-1>=s[1].v && s[1].x-1>=n-s[1].y)
car[k] = 1;
else if(s[1].v>=n-s[1].y)
car[k] = s[1].id;
else
car[k] = n;
}
printf("%d\n", car[k]);
Update(1, n, car[k], 1, 1);
}
else
Update(1, n, car[k], 1, 0);
}
return 0;
}