URAL 1220. Stacks

19 篇文章 0 订阅

我那个神><。。。

看起来是水题。。卡内存啊啊啊啊啊啊!!!!我用了无数的方法!!!

神马multimap,神马模拟链表,神马vector,神马stack数组!!!

总共提交了22次。。。囧啊。。STL熟了不少!!!结果还是MLE!!

看discuss提示用俩数组,用了,类似链表,找前驱。。需要一个存储地址的10W数组。。

用int显然超内存啊,看了别人的提示才想到的,用unsigned int,借用存值的那个数组的最高位,标记是否大于65535.。。很神奇吧。

#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <string.h>
#include <string>
#include <algorithm>
#define MID(x,y) ( ( x + y ) >> 1 )
#define L(x) ( x << 1 )
#define R(x) ( x << 1 | 1 )
#define FOR(i,s,t) for(int i=(s); i<(t); i++)
#define BUG puts("here!!!")
#define STOP system("pause")
#define file_r(x) freopen(x, "r", stdin)
#define file_w(x) freopen(x, "w", stdout)

const long long M = 1ll<<32;
int a[1000];
int b[100000];
unsigned short pre[100000];
int main()
{
	char op[10];
	int n, stk, val;
	
	scanf("%d", &n);
	
	FOR(i, 0, n)
	{
		scanf("%s", op);
		if( op[1] == 'U' )
		{
			scanf("%d%d", &stk, &val);
			stk--;
			b[i] = val;
			if( a[stk] > 65535 )
			{
				pre[i] = a[stk] - 65535;
				b[i] = -b[i];
			}
			else
				pre[i] = a[stk];
			a[stk] = i;
		}
		else
		{
			scanf("%d", &stk);
			stk--;
			printf("%d\n", abs(b[a[stk]]));
			if( b[a[stk]] < 0 )
				a[stk] = pre[a[stk]] + 65535;
			else
				a[stk] = pre[a[stk]];
		}
	}

return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值