Problem:


Score : 200 points

Problem Statement

There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white.

Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i).

Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows:

If a_i = 1, he painted the region satisfying x < x_i within the rectangle.

If a_i = 2, he painted the region satisfying x > x_i within the rectangle.

If a_i = 3, he painted the region satisfying y < y_i within the rectangle.

If a_i = 4, he painted the region satisfying y > y_i within the rectangle.

Find the area of the white region within the rectangle after he finished painting.

Constraints

1 ≦ W, H ≦ 100

1 ≦ N ≦ 100

0 ≦ x_i ≦ W (1 ≦ i ≦ N)

0 ≦ y_i ≦ H (1 ≦ i ≦ N)

W, H (21:32, added), x_i and y_i are integers.

a_i (1 ≦ i ≦ N) is 1, 2, 3 or 4.

Input

The input is given from Standard Input in the following format:

W H N
x_1 y_1 a_1
x_2 y_2 a_2
:
x_N y_N a_N

Output

Print the area of the white region within the rectangle after Snuke finished painting.

Sample Input 1

5 4 2
2 1 1
3 3 4

Sample Output 1

9

The figure below shows the rectangle before Snuke starts painting.

First, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x < 2 within the rectangle:

Then, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y > 3 within the rectangle:

Now, the area of the white region within the rectangle is 9.

Sample Input 2

5 4 3
2 1 1
3 3 4
1 4 2

Sample Output 2

0

It is possible that the whole region within the rectangle is painted black.

Sample Input 3

10 10 5
1 6 1
4 1 3
6 9 4
9 4 2
3 1 3

Sample Output 3

64



Sample input:
5 4 2
2 1 1
3 3 4


Sample output:
9

Submission status: Accepted

Solution code:
def main():
    w, h, n = map(int, input().split())
    f = [[1 for i in range(w)] for i in range(h)]

    for _ in range(n):
        x, y, a = map(int, input().split())
        if a == 1:
            for i in range(h):
                for j in range(x):
                    if f[i][j] == 1:
                    	f[i][j] = 0
        if a == 2:
            for i in range(h):
                for j in range(x, w):
                	if f[i][j] == 1:
                		f[i][j] = 0
        if a == 3:
            for i in range(h - y, h):
                for j in range(w):
                    if f[i][j] == 1:
                    	f[i][j] = 0
        if a == 4:
            for i in range(h - y):
                for j in range(w):
                    if f[i][j] == 1:
                    	f[i][j] = 0
    

    ans = 0
    for l in f:
        ans += sum(l)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
X = [0, W]
Y = [0, W]
for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        X[0] = max(x, X[0])
    elif a == 2:
        X[1] = min(x, X[1])
    elif a == 3:
        Y[0] = max(y, Y[0])
    else:
        Y[1] = min(y, Y[1])
x = X[1] - X[0]
y = Y[1] - Y[0]
if x < 0:
    x = 0
if y < 0:
    y = 0
print(x*y)

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
li = []
ans = 0
for i in range(h):
  li.append([0]*w)

for i in range(n):
  x, y, a = map(int, input().split())

  if a == 1:
    for i in li:
      for j in range(x):
        i[j] = 1
  elif a == 2:
    for i in li:
      for j in range(x, w):
        i[j] = 1
  elif a == 3:
    for i in range(h - y,h):
      for j in range(w):
        li[i][j] = 1
  elif a == 4:
    for i in range(h - y):
      for j in range(w):
        li[i][j] = 1

for i in li:
  ans += i.count(0)

print(ans)

Submission status: Accepted

Solution code:
W,H,N=map(int, input().split())
w=0
h=0
for i in range(N):
 x,y,a=map(int, input().split())
 if a==1:
  w=max(w,x)
 elif a==2:
  W=min(W,x)
 elif a==3:
  h=max(h,y)
 else:
  H=min(H,y)
print(max(0,(W-w))*max(0,(H-h)))

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
x1, y1, x2, y2 = 0, 0, w, h
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1 :
        x1 = max(x, x1)
    elif a == 2:
        x2 = min(x, x2)
    elif a == 3:
        y1 = max(y, y1)
    else:
        y2 = min(y, y2)
print(max((x2-x1), 0) * max((y2-y1), 0))

Submission status: Accepted

Solution code:
l = list(map(int, input().split()))

w = l[0]
h = l[1]
n = l[2]

minx = 0
maxx = w
miny = 0
maxy = h

for i in range(n):
    l = list(map(int, input().split()))
    x = l[0]
    y = l[1]
    a = l[2]
    if a == 1:
        if minx < x:
            minx = x
    elif a == 2:
        if maxx > x:
            maxx = x
    elif a == 3:
        if miny < y:
            miny = y
    elif a == 4:
        if maxy > y:
            maxy = y
    if maxx - minx <= 0 or maxy - miny <= 0:
        maxx = 0
        minx = 0
        maxy = 0
        miny = 0

cnt = w * h
#print(minx, maxx, miny, maxy)
ans = (maxx-minx) * (maxy-miny)
if ans < 0:
    ans = 0
print(ans)

Submission status: Accepted

Solution code:
W, H, N = [int(n) for n in input().split()]

sx = 0
ex = W
sy = 0
ey = H

for n in range(N):
  x, y, a = [int(w) for w in input().split()]
  if a == 1:
    sx = max(sx, x)
  elif a == 2:
    ex = min(ex, x)
  elif a == 3:
    sy = max(sy, y)
  else:
    ey = min(ey, y)

print(max(0,ex-sx)*max(0,ey-sy))

Submission status: Accepted

Solution code:
W, H, N = [int(i) for i in input().split()]
w, h = 0, 0
for i in range(N):
    x, y, a = [int(i) for i in input().split()]
    if a is 1:
        w = max(w, x)
    elif a is 2:
        W = min(W, x)
    elif a is 3:
        h = max(h, y)
    elif a is 4:
        H = min(H, y)

print(max(0, max(0, W - w) * max(0, H - h)))

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
xya = [list(map(int, input().split())) for i in range(n)]

z = [[0 for i in range(w)] for i in range(h)]  # z =[[0]*w]*hとすると、一つの要素を書き換えたときに同時に他の要素も変更になるのでよくない。
ans = 0

for i in range(n):
    if xya[i][2] == 1:
        for j in range(h):
            z[j][:xya[i][0]] = [1]*xya[i][0]
    elif xya[i][2] == 2:
        for j in range(h):
            z[j][xya[i][0]:] = [1]*(w-xya[i][0])
    elif xya[i][2] == 3:
        z[:xya[i][1]] = [[1]*w]*xya[i][1]
    elif xya[i][2] == 4:
        z[xya[i][1]:] = [[1]*w]*(h-xya[i][1])

for i in range(len(z)):
    ans += z[i].count(0)

print(ans)

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
w = h = 0
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        w = max(w, x)
    elif a == 2:
        W = min(W, x)
    elif a == 3:
        h = max(h, y)
    else:
        H = min(H, y)
print(max(0, (W - w)) * max(0, (H - h)))

Submission status: Accepted

Solution code:
W, H, N = list(map(int, input().split()))
left = 0
right = W
bottom = 0
top = H
for i in range(N):
    x, y, a = list(map(int, input().split()))
    if a == 1:
        left = max(left, x)
    elif a == 2:
        right = min(right, x)
    elif a == 3:
        bottom = max(bottom, y)
    elif a == 4:
        top = min(top, y)
print(max(0, right-left)*max(0, top-bottom))

Submission status: Accepted

Solution code:
W, H, N = map(int,input().split())

X=[]
Y=[]
A=[]


for i in range(N):
    x, y, a = map(int,input().split())
    X.append(x)
    Y.append(y)
    A.append(a)  

yoko1=0
yoko2=W
tate1=0
tate2=H

for j in range(N):
    if A[j]==1:
        if yoko1<X[j]:
            yoko1=X[j]
    
    elif A[j]==2:
        if yoko2>X[j]:
            yoko2=X[j]
        
    elif A[j]==3:
        if tate1<Y[j]:
            tate1=Y[j]

    elif A[j]==4:
        if tate2>Y[j]:
             tate2=Y[j]

ans=(tate2-tate1)*(yoko2-yoko1)

if (tate2-tate1)<0 or (yoko2-yoko1)<0:
    print(0)
else:
    print(ans)

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
arr = []
base_x = 0
base_y = 0
for i in range(n):
    arr.append(list(map(int,input().split())))
    x = arr[i][0]
    y = arr[i][1]
    num = arr[i][2]
    if num == 1:
        base_x = max(base_x,x)
    elif num == 2:
        w = min(w,x)
    elif num == 3:
        base_y = max(base_y,y)
    elif num == 4:
        h = min(h,y)
w2 = w - base_x
h2 = h - base_y
if base_x >= w or base_y >= h:
    print("0")
else:
    print(w2 * h2)

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
n=H
e=0
w=W
s=0
for i in range(N):
  X,Y,A=map(int,input().split())
  if A==1: e=max(e,X)
  elif A==2: w=min(w,X)
  elif A==3: s=max(s,Y)
  else: n=min(n,Y)
if e>=w or s>=n: print(0)
else: print((w-e)*(n-s))

Submission status: Accepted

Solution code:
from collections import defaultdict


def main():
    W, H, N = map(int, input().split())
    field = [[1] * W for _ in range(H)]
    for _ in range(N):
        x, y, a = map(int, input().split())
        y_s, y_e = 0, H
        x_s, x_e = 0, W
        if a == 1:
            x_s, x_e = 0, x
        elif a == 2:
            x_s, x_e = x, W
        elif a == 3:
            y_s, y_e = H - y, H
        elif a == 4:
            y_s, y_e = 0, H - y

        for y in range(y_s, y_e):
            for x in range(x_s, x_e):
                field[y][x] = 0

    print(sum([sum(line) for line in field]))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())

d = 0
u = h
r = w
l = 0

for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        if l <= x:
            l = x
    elif a == 2:
        if r >= x:
            r = x
    elif a == 3:
        if d <= y:
            d = y
    elif a == 4:
        if u >= y:
            u = y
    if u-d <= 0 or r-l <= 0:
        break
ans = (r-l) * (u-d)
if ans <= 0:
    print(0)
else:
    print(ans)

Submission status: Accepted

Solution code:
W, H, N = list(map(int, input().split()))

rect = [0, 0, W, H]

ans = -1

XY_a = []

for i in range(N):
    XY_a.append(list(map(int, input().split())))
    
for i in range(N):
    if XY_a[i][2] == 1:
        rect[0] = max(XY_a[i][0], rect[0])
    elif XY_a[i][2] == 2:
        rect[2] = min(XY_a[i][0], rect[2])
        
    elif XY_a[i][2] == 3:
        rect[1] = max(XY_a[i][1], rect[1])
    elif XY_a[i][2] == 4:
        rect[3] = min(XY_a[i][1], rect[3])
        
    if rect[0] >= rect[2] or rect[1] >= rect[3]:
        ans = 0
        break
        
if ans == 0:
    print(ans)
else :
    ans = (rect[2] - rect[0])*(rect[3] - rect[1])
    print(ans)

Submission status: Accepted

Solution code:
def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def rls(): return list(input())
def pli(a): return "".join(list(map(str, a)))

w,h,n = rli()
xl = 0
xh = w
yl = 0
yh = h
for i in range(n):
    x,y,a = rli()
    if(a == 1):
        xl = max(xl, x)
    elif(a == 2):
        xh = min(xh, x)
    elif(a == 3):
        yl = max(yl, y)
    else:
        yh = min(yh, y)
if(xh < xl or yh < yl):
    print(0)
else:
    print((xh-xl)*(yh-yl))

Submission status: Accepted

Solution code:
def main():
    W, H, N = map(int, input().split())
    P = [tuple(map(int, input().split())) for _ in range(N)]

    x = [0, W]
    y = [0, H]
    for p in P:
        if p[2] == 1 and x[0] < p[0]:
            x[0] = p[0]
        elif p[2] == 2 and x[1] > p[0]:
            x[1] = p[0]
        elif p[2] == 3 and y[0] < p[1]:
            y[0] = p[1]
        elif p[2] == 4 and y[1] > p[1]:
            y[1] = p[1]

    region = [x[1] - x[0], y[1] - y[0]]
    if region[0] <= 0 or region[1] <= 0:
        area = 0
    else:
        area = region[0] * region[1]

    print(area)

main()

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
l = []
for i in range(n):
    x = input().split()
    x[0], x[1], x[2]= map(int, x)
    l.append(x)
originalh = []
originalw = []
for i in range(h):
    originalh.append(1)
for i in range(w):
    originalw.append(1)
for i in l:
    if i[2] == 1:
        for i in range(i[0]):
            originalw[i] = 0
    elif i[2] == 2:
        for i in range(1, w-i[0]+1):
            originalw[-i] = 0
    elif i[2] == 3:
        for i in range(i[1]):
            originalh[i] = 0
    else:
        for i in range(1, h-i[1]+1):
            originalh[-i] = 0
    
r = sum(originalw) * sum(originalh)
print(r)

Submission status: Accepted

Solution code:
W,H,N = map(int, raw_input().split())
l = 0
r = W
d = 0
u = H
for i in range(N):
    x,y,a = map(int, raw_input().split())
    if a == 1:
        l = max(l, x)
    elif a == 2:
        r = min(r, x)
    elif a == 3:
        d = max(d, y)
    else:
        u = min(u, y)
if l >= r or d >= u:
    print 0
else:
    print (r-l) * (u-d)

Submission status: Accepted

Solution code:
W,H,N = [int(i) for i in input().split()]

p1 = [W,H]
p2 = [0,H]
p3 = [0,0]
p4 = [W,0]

g = []
for i in range(N):
    x,y,a = [int(i) for i in input().split()]
    g.append([x,y,a])


for i,j,k in g:
    if(k == 1):
        if(i > p2[0]):
            p2[0] = i
            p3[0] = i
        else:
            continue
    elif(k == 2):
        if(i < p1[0]):
            p1[0] = i
            p4[0] = i
        else:
            continue
    elif(k == 3):
        if(j > p3[1]):
            p3[1] = j
            p4[1] = j
        else:
            continue
    else:
        if(j < p2[1]):
            p1[1] = j
            p2[1] = j
        else:
            continue

w = p1[0] - p2[0]
h = p1[1] - p4[1]

if(w<=0 or h<=0):
    print(0)
else:
    print(w*h)

Submission status: Accepted

Solution code:
import numpy as np
W, H, N = map(int, raw_input().split())
A = np.ones((W, H), dtype=np.int)
for i in range(N):
    x, y, a = map(int, raw_input().split())
    if a == 1:
        A[:x,:] = 0
    elif a == 2:
        A[x:,:] = 0
    elif a == 3:
        A[:,:y] = 0
    elif a == 4:
        A[:,y:] = 0
print np.sum(A)

Submission status: Accepted

Solution code:
maxw, maxh, N = list(map(int, input().split(' ')))
minw, minh = 0, 0

for n in range(N):
    x, y, a = list(map(int, input().split(' ')))
    if a == 1:
        minw = max(minw, x)
    elif a == 2:
        maxw = min(maxw, x)
    elif a == 3:
        minh = max(minh, y)
    elif a == 4:
        maxh = min(maxh, y)

if maxw-minw < 0 or maxh-minh < 0:
    res = 0
else:
    res = (maxw-minw)*(maxh-minh)
print(res)

Submission status: Accepted

Solution code:
w,h,n = map(int, raw_input().split())
mat = [[False for _ in range(w)] for _ in range(h)]
for _ in range(n):
    x,y,a = map(int, raw_input().split())
    if a == 1:
        for i in range(h):
            for j in range(x):
                mat[i][j] = True
    elif a == 2:
        for i in range(h):
            for j in range(x,w):
                mat[i][j] = True
    elif a == 3:
        for i in range(y):
            for j in range(w):
                mat[i][j] = True
    elif a == 4:
        for i in range(y,h):
            for j in range(w):
                mat[i][j] = True
print sum([i.count(False) for i in mat])

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
act = [[0 for j in range(3)] for i in range(N)]
xl = 0 #左端 
xr = W #右端
yd = 0 #上端
yu = H #下端
for i in range(N):
	act[i] = [int(j) for j in input().split()]
for obj in act:
	if(obj[2]==1):
		xl = max(obj[0],xl)
	elif(obj[2]==2):
		xr = min(obj[0],xr)
	elif(obj[2]==3):
		yd = max(obj[1],yd)
	elif(obj[2]==4):
		yu = min(obj[1],yu)
ans = (xr-xl)*(yu-yd)
# print(xr,xl,yu,yd)
if(xr < xl or yu < yd):
	print(0)
else:
	print(ans)

Submission status: Accepted

Solution code:
W, H, N = map(int, raw_input().split())
xya = [map(int, raw_input().split()) for i in xrange(N)]
lx, hx = 0, W
ly, hy = 0, H
for x, y, a in xya:
    if a == 1: lx = max(lx, x)
    if a == 2: hx = min(hx, x) 
    if a == 3: ly = max(ly, y) 
    if a == 4: hy = min(hy, y) 
print max(0, hx - lx)*max(0, hy - ly)

Submission status: Accepted

Solution code:
def paint(b, type, x, y):
    if type == 1:
        b[:, :x] = 0
    elif type == 2:
        b[:, x:] = 0
    elif type == 3:
        b[:y, :] = 0
    else:
        b[y:, :] = 0
    return b

import numpy as np
W, H, N = list(map(int, input().split()))
w = []
for i in range(0, W):
    w.append(1)
b = [w for i in range(0, H)]
board = np.array(b)

for i in range(0, N):
    x, y, type = list(map(int, input().split()))
    board = paint(board, type, x, y)

print(str(np.sum(board)))

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
L,R = 0,W
D,T = 0,H
for i in range(N):
    x,y,a = map(int,input().split())
    if a == 1:
        if R <= x:
            L,R = 0,0
        elif L <= x:
            L = x
    elif a == 2:
        if x <= L:
            L,R = 0,0
        elif x <= R:
            R = x
    elif a == 3:
        if T <= y:
            D,T = 0,0
        elif D <= y:
            D = y
    else:
        if y <= D:
            D,T = 0,0
        elif y <= T:
            T = y
print( ( R - L ) * ( T - D ) )

Submission status: Accepted

Solution code:
import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    W, H, N = map(int, input().split())
    xl, xr, yb, yt = 0, W, 0, H

    for tc in range(N):
        x, y, a = map(int, input().split())

        if a == 1:
            xl = max(xl, x)
            pass
        elif a == 2:
            xr = min(xr, x)
            pass
        elif a == 3:
            yb = max(yb, y)
            pass
        else:
            yt = min(yt, y)
            pass

    if xr > xl and yt > yb:
        ans = (xr - xl) * (yt - yb)
    else:
        ans = 0

    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
xya = [map(int, input().split()) for _ in range(n)]

can = [[1] * w for _ in range(h)]

# for c in can:
#     print(c)

# print()

for x, y, a in xya:
    if a == 1:
        for i in range(h):
            can[i][0:x] = [0] * x
    if a == 2:
        for i in range(h):
            can[i][x:] = [0] * (h - x)
    if a == 3:
        for i in range(h - y, h):
            can[i] = [0] * w
    if a == 4:
        for i in range(h - y):
            can[i] = [0] * w

# for c in can:
#     print(c)

ans = sum([sum(cw) for cw in can])
print(ans)

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
lx,ly,ux,uy=0,0,w,h
for i in range(n):
    x,y,a=map(int,input().split())
    if a == 1:
        lx=max(lx,x)
    elif a == 2:
        ux=min(ux,x)
    elif a == 3:
        ly=max(ly,y)
    else:
        uy=min(uy,y)
if ux < lx or uy < ly: print(0)
else: print((ux-lx)*(uy-ly))

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
import sys
W, H, N = map(int,input().split())
xya = []
W1, W2, H3, H4 = (0, W, 0, H)

for tmp in range(0, N):
    xya.append(list(map(int,input().split())))

for y in range(0, N):

    if xya[y][2] == 1:
        W1 = max(W1, xya[y][0])
    elif xya[y][2] == 2:
        W2 = min(W2, xya[y][0])
    elif xya[y][2] == 3:
        H3 = max(H3, xya[y][1])
    else:
        H4 = min(H4, xya[y][1])

    if W1 >= W2 or H3 >= H4:
        print(0)
        sys.exit()

print((W2 - W1)*(H4 - H3))

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
import sys
W, H, N = map(int,input().split())
xya = []
W1 = 0
W2 = W
H3 = 0
H4 = H
for tmp in range(0, N):
    xya.append(list(map(int,input().split())))

for y in range(0, N):
    if xya[y][2] == 1:
        W1 = max(W1, xya[y][0])
    elif xya[y][2] == 2:
        W2 = min(W2, xya[y][0])
    elif xya[y][2] == 3:
        H3 = max(H3, xya[y][1])
    else:
        H4 = min(H4, xya[y][1])

    if W1 >= W2 or H3 >= H4:
        print(0)
        sys.exit()

    W_ans = W2 - W1
    H_ans = H4 - H3

print(W_ans*H_ans)

Submission status: Accepted

Solution code:
W, H, N = map(int,input().split())
x = []
y = []
a = []
x1 = 0
x2 = W
y1 = 0
y2 = H
for i in range(N):
    temp = list(map(int,input().split()))
    x.append(temp[0])
    y.append(temp[1])
    a.append(temp[2])

for i in range(N):
    if a[i] == 1:
        x1 = max(x1,x[i])
    if a[i] == 2:
        x2 = min(x2,x[i])
    if a[i] == 3:
        y1 = max(y1,y[i])
    if a[i] == 4:
        y2 = min(y2,y[i])
if (x2-x1)<0 or (y2-y1)<0:
    print(0)
else:
    print((x2-x1)*(y2-y1))

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())

x1, x2, y1, y2 = (0, W, 0, H)
for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        x1 = max(x1, x)
    elif a == 2:
        x2 = min(x2, x)
    elif a == 3:
        y1 = max(y1, y)
    elif a == 4:
        y2 = min(y2, y)
ans = max(0,x2-x1) * max(0,y2-y1)
print(ans)

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
sx, sy, ex, ey = 0, 0, w, h
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        sx = max(sx, x)
    if a == 2:
        ex = min(ex, x)
    if a == 3:
        sy = max(sy, y)
    if a == 4:
        ey = min(ey, y)
ans = (ex - sx) * (ey - sy)
if ex - sx < 0 or ey - sy < 0:
    print(0)
else:
    print(ans)

Submission status: Accepted

Solution code:
import numpy as np

H, W, N = list(map(int, input().split()))

arr = np.ones((H,W), dtype=np.bool)

for i in range(N):
    x, y, a = list(map(int, input().split()))
    if a==1:
        arr[0:x,:]=False
    elif a==2:
        arr[x:,:]=False
    elif a==3:
        arr[:,0:y]=False
    else:
        arr[:,y:]=False
        
print(np.sum(arr))

Submission status: Accepted

Solution code:
#prepare
L = []
Q = []

#input
W, H, N, = map(int,raw_input().split())
for i in range(N):
    L.append(map(int,raw_input().split()))
x1=0
x2=W
y1=0
y2=H

#calculate
Q = [row[2] for row in L]


for k in range(N):
    if Q[k] == 1:
        x1 = max(x1,L[k][0])
    elif Q[k] == 2:
        x2 = min(x2,L[k][0])
    elif Q[k] == 3:
        y1 = max(y1,L[k][1])
    elif Q[k] == 4:
        y2 = min(y2,L[k][1])

print max(0,x2-x1) * max(0,y2-y1)

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
X = [-1 for i in range(N)]
Y = [-1 for i in range(N)]
A = [-1 for i in range(N)]
for i in range(N):
	X[i], Y[i], A[i] = map(int, input().split())

result = [[0, 0], [W, H]]
for i in range(N):
	if A[i]==1:
		result[0][0] = max(result[0][0], X[i])
	if A[i]==2:
		result[1][0] = min(result[1][0], X[i])
	if A[i]==3:
		result[0][1] = max(result[0][1], Y[i])
	if A[i]==4:
		result[1][1] = min(result[1][1], Y[i])

if result[0][0]>=result[1][0] or result[0][1]>=result[1][1]:
	print(0)
else:
	print((result[1][0]-result[0][0])*(result[1][1]-result[0][1]))

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
x_bit = [1]*w
y_bit = [1]*h

for _ in range(n):
	x,y,a = map(int,input().split())
	if a == 1:
		for i in range(0,x):
			x_bit[i] = 0
	elif a == 2:
		for i in range(x,w):
			x_bit[i] = 0
	elif a == 3:
		for i in range(0,y):
			y_bit[i] = 0
	elif a == 4:
		for i in range(y,h):
			y_bit[i] = 0

print((x_bit.count(1) * (y_bit.count(1))))

Submission status: Accepted

Solution code:
W, H, N = map(int , input().split())
x = [0] * N
y = [0] * N 
a = [0] * N
for i in range(N):
    x[i], y[i], a[i] = map(int ,input().split())

board = [[1]*(W) for i in range((H))]
for i in range(N):
    l = [(y,x) for x in range(W) for y in range(H)]
    if a[i] == 1:
        l = list(filter(lambda t: t[1] <= x[i]-1, l))
    elif a[i] == 2:
        l = list(filter(lambda t: t[1] > x[i]-1, l))
    elif a[i] == 3:
        l = list(filter(lambda t: t[0] <= y[i]-1, l))
    elif a[i] == 4:
        l = list(filter(lambda t: t[0] > y[i]-1, l))
    for xy in l:
        board[xy[0]][xy[1]] = 0
ans = sum(map(sum, board))
print(ans)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def II(): return int(input())
def S(): return input()


def main():
    w,h,n = LI()
    a = [[1]*w for _ in range(h)]
    for _ in range(n):
        x,y,t = LI()
        if t == 1:
            for _x in range(x):
                for _y in range(h):
                    a[_y][_x] = 0
        elif t == 2:
            for _x in range(x, w):
                for _y in range(h):
                    a[_y][_x] = 0
        elif t == 3:
            for _x in range(w):
                for _y in range(y):
                    a[_y][_x] = 0
        else:
            for _x in range(w):
                for _y in range(y,h):
                    a[_y][_x] = 0
    return sum(sum(_) for _ in a)





print(main())

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
xya = []
l = 0
r = W
u = H
d = 0
for _ in range(N):
	x, y, a = map(int, input().split())
	if a == 1:
		l = max(l,x)
	elif a == 2:
		r = min(r,x)
	elif a == 3:
		d = max(d,y)
	else:
		u = min(u,y)
print(max(0,(u-d))*max(0,(r-l)))

Submission status: Accepted

Solution code:
W, H, N = map(int, raw_input().split())
xmax = W
xmin = 0
ymax = H
ymin = 0

for _ in range(N):
    x, y, a = map(int, raw_input().split())
    if a == 1:
        xmin = max(xmin, x)
    if a == 2:
        xmax = min(xmax, x)
    if a == 3:
        ymin = max(ymin, y)
    if a == 4:
        ymax = min(ymax, y)

print max(0, xmax-xmin) * max(0, ymax-ymin)

Submission status: Accepted

Solution code:
# W, Hは上限
# x, hは下限
# W, w, H, hをN回更新

W, H, N = map(int, input().split())
w, h = 0, 0

for i in range(N):
    x, y, a = map(int, input().split())

    if a == 1 and w < x:
        w = x
    elif a == 2 and W > x:
        W = x
    elif a == 3 and h < y:
        h = y
    elif a == 4 and H > y:
        H = y
if W-w <= 0 or H-h <= 0:
    print(0)
else:
    S = (W - w) * (H -h)
    print(S)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
def blocks(block,w,h):
    x, y, p = map(int, raw_input().split())
    if p == 1:
        for i in range(h):
            for j in range(w):
                if j < x:
                    block[i][j] = False
    if p == 2:
        for i in range(h):
            for j in range(w):
                if j >= x:
                    block[i][j] = False
    if p == 3:
        for i in range(h):
            for j in range(w):
                if i < y:
                    block[i][j] = False
    if p == 4:
        for i in range(h):
            for j in range(w):
                if i >= y:
                    block[i][j] = False
    return block

w, h, n = map(int, raw_input().split())
block = [[True for i in range(w)] for j in range(h)]
for i in range(n):
    block = blocks(block,w,h)
total = 0
for i in range(h):
    for j in range(w):
        if block[i][j] == True:
            total = total + 1
print (total)

Submission status: Accepted

Solution code:
def main():
    w, h, n = map(int, input().split())
    f = [[1] * w for _ in range(h)]

    for _ in range(n):
        x, y, a = map(int, input().split())
        if a == 1:
            for i in range(h):
                for j in range(x):
                    f[i][j] = 0
        if a == 2:
            for i in range(h):
                for j in range(x, w):
                    f[i][j] = 0
        if a == 3:
            for i in range(h - y, h):
                for j in range(w):
                    f[i][j] = 0
        if a == 4:
            for i in range(h - y):
                for j in range(w):
                    f[i][j] = 0

    ans = 0
    for l in f:
        ans += sum(l)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
whn=input().split(" ")
W=int(whn[0])
H=int(whn[1])
N=int(whn[2])
a=[]
for i in range(N):
    a.append(input().split(" "))

left=0
right=W
top=H
bottom=0

for i in range(N):
    if a[i][2]=="1":
        if left<int(a[i][0]):
            left=int(a[i][0])
    elif a[i][2]=="2":
        if right>int(a[i][0]):
            right=int(a[i][0])
    elif a[i][2]=="3":
        if bottom<int(a[i][1]):
            bottom=int(a[i][1])
    elif a[i][2]=="4":
        if top>int(a[i][1]):
            top=int(a[i][1])


if left>=right:
    print(0)
elif top<=bottom:
    print(0)
else:
    print((top-bottom)*(right-left))

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
w, h = 0, 0

for i in range(N):
	x, y, a = map(int, input().split())

	if a == 1 and w < x:
		w = x
	elif a == 2 and W > x:
		W = x
	elif a == 3 and h < y:
		h = y
	elif a == 4 and H > y:
		H = y

if W - w <= 0 or H - h <= 0:
	print(0)
else:
	print((W - w) * (H - h))

Submission status: Accepted

Solution code:
W, H, N = map(int, raw_input().split())

w = [0, W]
h = [0, H]

for i in range(N):
    x, y, a = map(int, raw_input().split())

    if a == 1:
        w[0] = max(x, w[0])
    elif a == 2:
        w[1] = min(x, w[1])
    elif a == 3:
        h[0] = max(y, h[0])
    elif a == 4:
        h[1] = min(y, h[1])

print max(w[1]-w[0], 0) * max(h[1]-h[0], 0)

Submission status: Accepted

Solution code:
W, H, N = map(int, raw_input().split())
w, h = 0, 0
 
for i in xrange(N):
    x, y, a = map(int, raw_input().split())

    if a == 1 and w < x:
        w = x
    elif a == 2 and W > x :
        W = x
    elif a == 3 and h < y:
        h = y
    elif a == 4 and H > y:
        H = y
 
print max(W-w, 0) * max(H-h, 0)

Submission status: Accepted

Solution code:
W, H, N = map(int, raw_input().split())
d = [map(int, raw_input().split()) for _ in range(N)]

r = []
for i in range(H):
    l = []
    for j in range(W):
        l.append(0)
    r.append(l)

for i in d:
    if i[2] == 1:
        for j in range(i[0]):
            for k in range(H):
                r[k][j] = 1
    elif i[2] == 2:
        for j in range(i[0],W):
            for k in range(H):
                r[k][j] = 1
    elif i[2] == 3:
        for j in range(i[1]):
            for k in range(W):
                r[j][k] = 1
    else:
        for j in range(i[1],H):
            for k in range(W):
                r[j][k] = 1

a = 0
for i in range(W):
    for j in range(H):
        if r[j][i] == 0:
            a += 1
print a

Submission status: Accepted

Solution code:
W, H, N = [int(n) for n in raw_input().split(" ")]
a = [[int(x) for x in raw_input().split(" ")] for n in range(N)]
 
x_min = y_min = 0
x_max, y_max = W, H
 
for s in a:
  if s[2] == 1:
    x_min = max(x_min, s[0])
  elif s[2] == 2:
    x_max = min(x_max, s[0])
  elif s[2] == 3:
    y_min = max(y_min, s[1])
  elif s[2] == 4:
    y_max = min(y_max, s[1])
 
 
if (x_max > x_min) and (y_max > y_min):
  print (x_max - x_min) * (y_max - y_min)
else:
  print 0

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
w, h = 0, 0

for _ in range(N):
	x, y, a = map(int, input().split())
	if a == 1:
		if w < x:
			w = x
	elif a == 2:
		if W > x:
			W = x
	elif a == 3:
		if h < y:
			h = y
	elif a == 4:
		if H > y:
			H = y

if W-w < 0 or H-h < 0:
	print(0)
else:
	print((W-w)*(H-h))

Submission status: Accepted

Solution code:
W, H, N = [int(x) for x in input().strip().split()]
x_min = 0
y_min = 0

for i in range(N):
    x, y, a = [int(x) for x in input().strip().split()]
    if a == 1 and x_min < x:
        x_min = x
    elif a == 2 and W > x:
        W = x
    elif a == 3 and y_min < y:
        y_min = y
    elif a == 4 and H > y:
        H = y
    
if x_min > W or y_min > H:
    print('0')
else:
    print((W - x_min)*(H - y_min))