[ create a new paste ] login | about

Link: http://codepad.org/FAwth2dB    [ raw code | output | fork ]

Python, pasted on Mar 19:
__author__ = 'Zlobober'

w, h, n = map(int, raw_input().split())

T = [None] * n
W = [None] * n

R = [-1] * (w + 1)
L = [-1] * (w + 1)
U = [-1] * (h + 1)
D = [-1] * (h + 1)
R[0] = 0
R[w] = 0
U[0] = 0
U[h] = 0

for i in range(n):
    T[i], W[i] = raw_input().split()
    W[i] = int(W[i])
    if T[i] == 'H':
        U[W[i]] = 0
    else:
        R[W[i]] = 0

ans = [0] * n

mxw = 0
mxh = 0

p = 0
for x in range(1, w + 1):
    if R[x] == 0:
        L[x] = p
        R[p] = x
        mxw = max(mxw, x - p)
        p = x
p = 0
for y in range(1, h + 1):
    if U[y] == 0:
        D[y] = p
        U[p] = y
        mxh = max(mxh, y - p)
        p = y

ans[n - 1] = mxw * mxh
for i in range(n - 1, 0, -1):
    if T[i] == 'H':
        U[D[W[i]]] = U[W[i]]
        D[U[W[i]]] = D[W[i]]
        mxh = max(mxh, U[W[i]] - D[W[i]])
    else:
        R[L[W[i]]] = R[W[i]]
        L[R[W[i]]] = L[W[i]]
        mxw = max(mxw, R[W[i]] - L[W[i]])
    ans[i - 1] = mxw * mxh

for a in ans:
    print(a)


Output:
1
2
3
4
Traceback (most recent call last):
  Line 3, in <module>
    w, h, n = map(int, raw_input().split())
EOFError


Create a new paste based on this one


Comments: