我那个神><。。。
看起来是水题。。卡内存啊啊啊啊啊啊!!!!我用了无数的方法!!!
神马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;
}