二
【问题描述】
二这个字好像更多的是用来骂人的。如二流子,二楞子,老二……或者是简简单单一个“二”也能让人回味无穷。OI就是一个“二”的竞赛。
当然这里的二必然不是骂人的。二是指OI与二分不开,不仅仅是二进制,二分思想也是OI很重要的组成部分。君不见复杂度里满天飞之log乎?就是二分的功劳。如果信息学没有二分,就……就麻烦了!
所以我们要学二分查找。所谓二分查找就是在一堆有序数里找某个符合要求的数。还记得商品猜价格的游戏么?那就是一个典型的二分查找应用的例子。
当然不是每个人在猜价格的时候都是二分的,因为不是每个人都学过信息学竞赛;主持人也不是总能说对的,因为他们不是电脑。现在给你主持人对一些问题的回答,其中有对的也有错的。请你找出一个答案使其能满足尽量多的回答。注意这里的合法答案必须是正整数。
这里假设猜的人是健忘的,后面猜的数与前面得到的回答没有关系。
【输入文件】
输入文件two.in,第一行包含一个整数n,表示总共的回答数。接下来n行,首先是猜出的数,然后是一个空格,然后是一个符号。如果是“+”说明猜的数比答案大,“-”说明比答案小,“.”说明猜到了答案。
【输出文件】
输出文件two.out应包含一个正整数,最多能满足的回答数。
【样例输入】
4
8 .
10 +
8 .
10 -
【样例输出】
3
【数据规模】
对于20%的数据,N≦1000,题目中所有的数都不大于1000。.
对于100%的数据,N≦100000。猜的数大于0小于maxlongint。
=================================
===================
type
node=record
x:longint;
ch:char;
end;
re=record
x:longint;
flag:longint;
end;
var
n:longint;
a:array[1..100000]of node;
pos:array[1..200000]of re;
pos_S:longint;
procedure init;
begin
assign(input,'two.in');
assign(output,'two.out');
reset(input); rewrite(output);
end;
procedure terminate;
begin
close(input); close(output);
halt;
end;
procedure qsort(s,t:longint);
var
i,j:longint;
x:re;
tem:re;
begin
i:=s; j:=t;
x:=pos[(s+t)shr 1];
repeat
while (x.x<pos[j].x)or((x.x=pos[j].x)and(x.flag<pos[j].flag)) do dec(j);
while (pos[i].x<x.x)or((x.x=pos[i].x)and(pos[i].flag<x.flag)) do inc(i);
if i<=j then
begin
tem:=pos[i];
pos[i]:=pos[j];
pos[j]:=tem;
inc(i); dec(j);
end;
until i>j;
if i<t then qsort(i,t);
if s<j then qsort(s,j);
end;
procedure main;
var
i:longint;
ch:char;
tem:longint;
ans:longint;
begin
readln(n);
//d['-']:=3; d['.']:=2; d['+']:=2;
pos_s:=0;
for i:=1 to n do
begin
readln(a[i].x,ch,a[i].ch);
if a[i].ch='.' then
begin
inc(pos_s);
pos[pos_s].x:=a[i].x;
pos[pos_s].flag:=0;
inc(pos_s);
pos[pos_s].x:=a[i].x;
pos[pos_s].flag:=1;
end;
if a[i].ch='+' then
begin
inc(pos_s);
pos[pos_s].x:=0;
pos[pos_s].flag:=0;
inc(pos_s);
pos[pos_s].x:=a[i].x-1;
pos[pos_s].flag:=1;
end;
if a[i].ch='-' then
begin
inc(pos_s);
pos[pos_s].x:=a[i].x+1;
pos[pos_s].flag:=0;
inc(pos_s);
pos[pos_s].x:=maxlongint;
pos[pos_s].flag:=1;
end;
end;
qsort(1,pos_s);
ans:=0;
tem:=0;
for i:=1 to pos_S do
begin
if pos[i].flag=0 then inc(tem);
if pos[i].flag=1 then dec(tem);
if tem>ans then ans:=tem;
end;
writeln(ans);
end;
begin
init;
main;
terminate;
end.