int curInc;
HashMap<Integer, Integer> incMap;
Stack<Integer> stack; public SuperStack() {
this.curInc = 0;
this.incMap = new HashMap<Integer, Integer>();
this.stack = new Stack<Integer>();
} private void push(int val) {
this.stack.push(val);
} private int pop() {
if (incMap.containsKey(stack.size())) {
curInc += incMap.get(stack.size());
}
int ret = stack.pop() + curInc;
return ret;
} private void inc(int index, int inc) {
if (incMap.containsKey(index)) {
incMap.put(index, incMap.get(index) + inc);
} else {
incMap.put(index, inc);
}
}

Normal Solution

private void push(int val) {
list.addLast(val);
} private int pop() {
return list.pollLast();
} private void inc(int a, int b) {
for (int i = 0; i < a; i++) {
list.set(i, list.get(i) + b);
}
}

PowerStack的更多相关文章

随机推荐

  1. ubuntu 恢复gnome-panel

    Ubuntu重启panel 的方法首先进入终端, 依次输入以下命令1.gconftool --recursive-unset /apps/panel2.rm -rf ~/.gconf/apps/pan ...

  2. C语言 宏/macor/#define/

    C语言 宏/macor/#define 高级技巧 1.在进行调试的时候,需要进行打印/PRINT,可以通过define进行自定义.例如,自己最常用的DEBUG_PRINT() #define DEBU ...

  3. ASCII Table/ASCII表

    ASCII Table/ASCII表 参考: 1.Table of ASCII Characters

  4. [LCA & RMQ] [NOIP2013] 货车运输

    首先看到这题, 由于要最大, 肯定是求最大生成树 那么 o(n2) dfs 求任意点对之间的最小边是可以想到的 但是看看数据范围肯定TLE 于是暴力出来咯, 不过要注意query的时候判断的时候要 m ...

  5. Menu bar missing from ClearCase Explorer

    See following links: Menu bar missing from ClearCase Explorer Understanding the Rational ClearCase E ...

  6. Hibernate3.3 小记

    //----------------事务(修改.删除.保存) Session s=getSession(); Transaction t=s.beginTransaction(); getSessio ...

  7. html元素li移动动态效果

    在日常工作当中遇到了一个问题,平铺型列表修改单个内容设置排序时列表排序应与之对应.一下是一个小小的例子:简单的解决了此类问题,以浮动的形式改变当前的数据的显示顺序.有不足之处欢迎指点,后期还会做一个更 ...

  8. USB初始化

    //USB初始化void CFileManagerDlg::usbinit(){ #define BUFFER_SIZE 64 struct usb_bus *bus; struct usb_devi ...

  9. Asp.net自带导出方法

    ///datatable数据源 filename绝对路径 如:E:\\***.xls DataTable.WriteXml(fileName)

  10. PHP学习心得(二)——实用脚本

    <?php 来表示 PHP 标识符的起始,然后放入 PHP 语句并通过加上一个终止标识符 ?> 来退出 PHP 模式 调用函数phpinfo(),将会看到很多自己系统的信息,以及预定义变量 ...