程序代码:
#include <stdio.h>
int main( void )
{
// 队列
unsigned queue[100000];
size_t queue_begin = 0;
size_t queue_end = 0;
// [0,1000]中每个数字的数量
unsigned count[1001] = { 0 };
// 有多少种不同的数字
unsigned variety = 0;
unsigned n;
scanf( "%u", &n );
while( n-- )
{
unsigned action;
scanf( "%u", &action );
switch( action )
{
case 1:
printf( "%u\n", variety );
break;
case 2:
{
unsigned push;
scanf( "%u", &push );
queue[queue_end++] = push;
if( count[push] == 0 )
++variety;
++count[push];
}
break;
case 3:
{
unsigned pop = queue[queue_begin++];
--count[pop];
if( count[pop] == 0 )
--variety;
}
break;
}
}
}