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:
W,H,N = map(int,input().split())

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

# raw White & Black
AllArea = []
for numline in range(H):
    rawWhite = []
    rawBlack = []
    for numraw in range(W):
        rawWhite.append("W")
        rawBlack.append("B")
    AllArea.append(rawWhite)

# coloring from white to Black
for n in range(N):
    if CoordinateList[n][2] == 1:
        if CoordinateList[n][0] == 0:
             pass
        else:
            for i in range(H):
                del AllArea[i][:(CoordinateList[n][0])]
                for numX in range(CoordinateList[n][0]):
                    AllArea[i].insert(0,"B")

    elif CoordinateList[n][2] == 2:
        if CoordinateList[n][0] == 0:
            print(0)
            exit()
        else:
            for i in range(H):
                del AllArea[i][(CoordinateList[n][0]):]
                for numX in range(CoordinateList[n][0]):
                    AllArea[i].append("B")

    elif CoordinateList[n][2] == 3:
        changeY = H - int(CoordinateList[n][1])
        if changeY == 0:
            print(0)
            exit()
        else:
            del AllArea[changeY:]
            
            for changeRaw in range(int(CoordinateList[n][1])):
                AllArea.append(rawBlack)
            

    elif CoordinateList[n][2] == 4:
        changeY = H - int(CoordinateList[n][1]) 
        if changeY == 0:
            pass
        else:
            del AllArea[:changeY]
            for changeRaw in range(changeY):
                AllArea.insert(0,rawBlack)
            
# counting 
AreaWhite = 0
for i in range(H):
    AreaWhite += AllArea[i].count("W")

print(AreaWhite)

Submission status: Accepted

Solution code:
from sys import exit, stdin
W, H, M = [int(_) for _ in stdin.readline().rstrip().split()]
maxX, minX, maxY, minY = W, 0, H ,0
for i in range(M):
    x, y, a = [int(_) for _ in stdin.readline().rstrip().split()]
    if a == 1 and x > minX:
        minX = x
    elif a == 2 and x < maxX:
        maxX = x
    elif a == 3 and y > minY:
        minY = y
    elif a == 4 and y < maxY:
        maxY = y
  
x_diff = maxX - minX
y_diff = maxY - minY
if x_diff > 0 and y_diff > 0:
  print(x_diff * y_diff)
else:
  print(0)

Submission status: Accepted

Solution code:
W,H,N = map(int, input().strip().split(' '))
x1,x2 = 0,W
y1,y2 = 0,H
for _ in range(N):
  x,y,a = map(int, input().strip().split(' '))
  if a == 1:
    x1 = max(x1, x)
  elif a == 2:
    x2 = min(x2, x)
  elif a == 3:
    y1 = max(y1, y)
  else:
    y2 = min(y2, y)
  

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

Submission status: Accepted

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

x_min = 0
x_max = w
y_min = 0
y_max = h

for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        if x > x_min:
            x_min = x
    elif a == 2:
        if x < x_max:
            x_max = x
    elif a == 3:
        if y > y_min:
            y_min = y
    else:
        if y < y_max:
            y_max = y

if x_min > x_max or y_min > y_max:
    print(0)
else:
    print((x_max-x_min)*(y_max-y_min))

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
x_min = 0
x_max = W
y_min = 0
y_max = H
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1 and x > x_min:
        x_min = x
    elif a == 2 and x < x_max:
        x_max = x
    elif a == 3 and y > y_min:
        y_min = y
    elif a == 4 and y < y_max:
        y_max = y

x_l = x_max - x_min
y_l = y_max - y_min

if x_l > 0 and y_l > 0:
    S = (x_max - x_min) * (y_max - y_min)
else:
    S = 0
print(S)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    w, h, n = map(int, input().split())
    px = py = 0
    for _ in range(n):
        x, y, a = map(int, input().split())
        if a == 1:
            px = max(px, x)
        elif a == 2:
            w = min(w, x)
        elif a == 3:
            py = max(py, y)
        elif a == 4:
            h = min(h, y)

    print(max(0, w-px) * max(0, h-py))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
xya = [list(map(int,input().split())) for _ in range(N)]
p1,p2 = [0,0],[W,H]

for *p,a in xya:
    if a == 1:
        if p1[0] < p[0]:
            p1[0] = p[0]
    elif a == 2:
        if p2[0] > p[0]:
            p2[0] = p[0]
    elif a == 3:
        if p1[1] < p[1]:
            p1[1] = p[1]
    else:
        if p2[1] > p[1]:
            p2[1] = p[1]
if p2[0] - p1[0] < 0 or p2[1] - p1[1] < 0:
    print(0)
else:
    print((p2[0] - p1[0]) * (p2[1] - p1[1]))

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
lx=0
rx=w
by=0
ty=h
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    lx=max(lx,x)
  elif a==2:
    rx=min(rx,x)
  elif a==3:
    by=max(by,y)
  else:
    ty=min(ty,y)
if rx-lx>0 and ty-by>0:
  print((rx-lx)*(ty-by))
else:
  print(0)

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
wl, hl = 0, 0
wr, hr = w, h
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        wl = min(max(wl, x), wr)
    elif a == 2:
        wr = max(min(wr, x), wl)
    elif a == 3:
        hl = min(max(hl, y), hr)
    elif a == 4:
        hr = max(min(hr, y), hl)

ans = (hr - hl) * (wr - wl)
print(ans)

Submission status: Accepted

Solution code:
[w,h,n]=list(map(int,input().split()))
risuto=[]
xmin=0
xmax=w
ymin=0
ymax=h
for i in range(n):
	risuto.append(list(map(int,input().split())))
for i in range(n):
	if risuto[i][2]==1 and risuto[i][0]>xmin:
		xmin=risuto[i][0]
	elif risuto[i][2]==2 and risuto[i][0]<xmax:
		xmax=risuto[i][0]
	elif risuto[i][2]==3 and risuto[i][1]>ymin:
		ymin=risuto[i][1]
	elif risuto[i][2]==4 and risuto[i][1]<ymax:
		ymax=risuto[i][1]
menseki=int((xmax-xmin)*(ymax-ymin))
if xmax<=xmin or ymax<=ymin:
	menseki=0
print(menseki)

Submission status: Accepted

Solution code:
[w,h,n]=list(map(int,input().split()))
risuto=[]
xmin=0
xmax=w
ymin=0
ymax=h
for i in range(n):
	risuto.append(list(map(int,input().split())))
for i in range(n):
	if risuto[i][2]==1 and risuto[i][0]>xmin:
		xmin=risuto[i][0]
	elif risuto[i][2]==2 and risuto[i][0]<xmax:
		xmax=risuto[i][0]
	elif risuto[i][2]==3 and risuto[i][1]>ymin:
		ymin=risuto[i][1]
	elif risuto[i][2]==4 and risuto[i][1]<ymax:
		ymax=risuto[i][1]
menseki=int((xmax-xmin)*(ymax-ymin))
if xmax<=xmin or ymax<=ymin:
	menseki=0
if menseki<0:
	menseki=0
print(menseki)

Submission status: Accepted

Solution code:

W, H, N = list(map(int, input().split(" ")))
point = []
square = [[1 for i in range(W)] for j in range(H)]
for i in range(N):
  x, y, a = list(map(int, input().split(" ")))
  if a == 1:
    for i in range(H):
      for j in range(x):
        square[i][j] = 0
  if a == 2:
    for i in range(H):
      for j in range(W - 1, x - 1, -1):
        square[i][j] = 0
  if a == 3:
    for i in range(y):
      square[i] = [0 for j in range(W)]
  if a == 4:
    for i in range(H - 1, y - 1, -1):
      square[i] = [0 for j in range(W)]

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

Submission status: Accepted

Solution code:
def resolve():
	xmin,ymin=0,0
	w,h,n=map(int,input().split())
	xmax,ymax=w,h
	for _ in range(n):
		x,y,a=map(int,input().split())
		if a==1:
			xmin=max(x,xmin)
		elif a==2:
			xmax=min(x,xmax)
		elif a==3:
			ymin=max(y,ymin)
		else:
			ymax=min(y,ymax)
	print((max(xmax-xmin,0))*max((ymax-ymin),0))
resolve()

Submission status: Accepted

Solution code:
import numpy as np

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

r = np.ones([h, w], dtype=int)

for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        r[:, :x] = 0
    elif a == 2:
        r[:, x:] = 0
    elif a == 3:
        r[:y, :] = 0
    else:
        r[y:, :] = 0

print(sum(sum(r)))

Submission status: Accepted

Solution code:
W,H,N=list(map(int,input().split(" ")))
point=[]
square=[[1 for i in range(W)] for j in range(H)]
for i in range(N):
    x,y,a=list(map(int,input().split(" ")))
    if a==1:
        for i in range(H):
            for j in range(x):
                square[i][j]=0
    if a==2:
        for i in range(H):
            for j in range(W-1,x-1,-1):
                square[i][j]=0
    if a==3:
        for i in range(y):
            square[i]=[0 for j in range(W)]
    if a==4:
        for i in range(H-1,y-1,-1):
             square[i]=[0 for j in range(W)]

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

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
X=[w for w in range(W+1)]
Y=[h for h in range(H+1)]
for n in range(N):
    w,h,a=map(int,input().split())
    if a==1:
        X=[x for x in X if x>=w]
    elif a==2:
        X=[x for x in X if x<=w]
    elif a==3:
        Y=[y for y in Y if y>=h]
    else:
        Y=[y for y in Y if y<=h]
if len(X)<2 or len(Y)<2:
  print(0)
else:
  print((len(X)-1)*(len(Y)-1))

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
x=[]
for i in range(n):
    a,b,c=map(int,input().split())
    if c<3:
        x.append([a,c])
    else:
        x.append([b,c])
def get_unique_list(seq):
    seen=[]
    return [x for x in seq if x not in seen and not seen.append(x)]
X=get_unique_list(x)
a=[];b=[];c=[];d=[]
for i in range(len(X)):
    if X[i][1]==1:
        a.append(X[i][0])
    elif X[i][1]==2:
        b.append(X[i][0])
    elif X[i][1]==3:
        c.append(X[i][0])
    else:
        d.append(X[i][0])
if len(b)>0:
    w=min(b)
if len(a)>0:
    w-=max(a)
if len(d)>0:
    h=min(d)
if len(c)>0:
    h-=max(c)
print([h*w,0][h<1 or w<1])

Submission status: Accepted

Solution code:
import copy
w,h,n=map(int,input().split())
W=[i for i in range(w+1)]
H=[i for i in range(h+1)]
for _ in range(n):
    x,y,a=map(int,input().split())
    WW=copy.deepcopy(W)
    HH=copy.deepcopy(H)
    if a==1:
        for i in WW:
            if i<x:
                W.remove(i)
    if a==2:
        for i in WW:
            if i>x:
                W.remove(i)            
    if a==3:
        for i in HH:
            if i<y:
                H.remove(i)            
    if a==4:
        for i in HH:
            if i>y:
                H.remove(i)  
if W==[] or H==[]:
    print(0)
else:    
    print((W[-1]-W[0])*(H[-1]-H[0]))

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
Data = []
for _ in range(N):
    Data.append(list(map(int,input().split())))

x1,x2 = 0,W
y1,y2 = 0,H

for i in range(N):
    x,y,a = Data[i]
    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)

if x2 >= x1 and y2 >= y1:
    s = (x2-x1)*(y2-y1)
else:
    s = 0
print(s)

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
data = [list(map(int, input().split())) for _ in range(N)]
xmax = 0 # a=1
xmin = W # a=2
ymax = 0 # a=3
ymin = H # a=4

for x,y,a in data:
    if a == 1: # x以下
        xmax = max(x, xmax)
    elif a == 2: # x以上
        xmin = min(x, xmin)
    elif a == 3: # y以下
        ymax = max(y, ymax)
    else: # y以上
        ymin = min(y, ymin)
S = max(0,(xmin - xmax)) * max(0,(ymin - ymax))
print(S if S>=0 else 0)

Submission status: Accepted

Solution code:
import numpy as np
W, H, N = map(int, input().split())
x_s = [0] * N
y_s = [0] * N
a_s = [0] * N
for i in range(N):
    x_s[i], y_s[i], a_s[i] = map(int, input().split())

l = np.zeros((H, W))
for x, y, a in zip(x_s, y_s, a_s):
  if a == 1:
    l[:, :x] = 1
  elif a == 2:
    l[:, x:] = 1
  elif a == 3:
    l[(H-y):, :] = 1
  else: #a=4
    l[:(H-y), :] = 1
print(np.count_nonzero(l==0))

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
XYA = [list(map(int, input().split())) for _ in range(N)]
x1, x2, y1, y2 = 0, W, 0, H
for x, y, a in XYA:
    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)
if x2 > x1 and y2 > y1:
    print((x2-x1)*(y2-y1))
else:
    print(0)

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
l = [list(map(int, input().split())) for i in range(n)]
x = [x_i for x_i in range(w + 1)]
y = [y_i for y_i in range(h + 1)]
for l_e in l:
    if l_e[2] == 1:
        x = [i for i in x if i > l_e[0] - 1]
    elif l_e[2] == 2:
        x = [i for i in x if i < l_e[0] + 1]
    elif l_e[2] == 3:
        y = [i for i in y if i > l_e[1] - 1]
    else:
        y = [i for i in y if i < l_e[1] + 1]
print(0 if len(x) == 0 or len(y) == 0 else (x[-1] - x[0]) * (y[-1] - y[0]))

Submission status: Accepted

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

s = [[int(i) for i in input().split()] for j in range(n)]

u_left = 0
v_low = 0
u_right = w
v_high = h

for num in s:
    x = num[0]
    y = num[1]
    a = num[2]
    if a == 1 and x >= u_left:
        u_left = x
    elif a == 2 and x <= u_right:
        u_right = x
    elif a == 3 and y >= v_low:
        v_low = y
    elif a == 4 and y <= v_high:
        v_high = y

s = (u_right-u_left)*(v_high-v_low)
if u_left < u_right and v_low < v_high:
    print(s)
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

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

l = 0
r = W
d = 0
u = H

for x, y, a in xya:
    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 r>l and u>d:
    print((r-l)*(u-d))
else:
    print(0)

Submission status: Accepted

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

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        xmin = max(xmin, x)
    elif a == 2:
        xmax = min(xmax, x)
    elif a == 3:
        ymin = max(ymin, y)
    else:
        ymax = min(ymax, y)

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

Submission status: Accepted

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

li=[[1 for w in range(W)] for h in range(H)]

for n in range(N):
  X,Y,a=map(int,input().split())
  if a==1:
    for y in range(H):
      for x in range(X):
        li[y][x]=0
  elif a==3:
    for y in range(Y):
      for x in range(W):
        li[y][x]=0
  elif a==2:
    for y in range(H):
      for x in range(X,W):
        li[y][x]=0
  else:
    for y in range(Y,H):
      for x in range(W):
        li[y][x]=0

ans=sum(x.count(1) for x in li)

print(ans)

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
ls = [[] for _ in range(4)]
for _ in range(n):
    x, y, a = map(int, input().split())
    ls[a - 1].append(x if a < 3 else y)
l = max(ls[0] + [0])
r = min(ls[1] + [w])
d = max(ls[2] + [0])
u = min(ls[3] + [h])
if u - d < 0 or r - l < 0:
    print(0)
else:
    print((u - d) * (r - l))

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
min_x, min_y = 0, 0
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        min_x = max(min_x, x)
    elif a == 2:
        w = min(w, x)
    elif a == 3:
        min_y = max(min_y, y)
    elif a == 4:
        h = min(h, y)

print( (w-min_x)*(h-min_y) if min_x < w and min_y < h else 0)

Submission status: Accepted

Solution code:
def black(x, y):
  for xi in x:
    for yi in y:
      block[yi][xi] = False

W, H, N = map(int, input().split())
coords = [ map(int, input().split()) for _ in range(N) ]

block = [ [True] * W for _ in range(H) ]

for x, y, a in coords:
  if a == 1:
    black(range(x), range(H))
  if a == 2:
    black(range(x, W), range(H))
  if a == 3:
    black(range(W), range(y))
  if a == 4:
    black(range(W), range(y, H))

result = 0
for i in range(H):
  result += block[i].count(True)

print(result)

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
l=0
u=0
for _ in range(n):
  x,y,a = map(int,input().split())
  if a ==1:
    l = max(x,l)
  elif a == 2:
    w = min(x,w)
  elif a == 3:
    u = max(y,u)
  elif a == 4:
    h = min(y,h)
print((w-l)*(h-u) if w-l > 0 and h-u > 0 else 0)

Submission status: Accepted

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


X=Y= 0
for i in range(n):
    x, y, a = map(int, input().split())
    
    if a==1 and X<x:
        X=x
    if a==2 and w>x:
        w=x
    if a==3 and Y<y:
        Y=y
    if a==4 and h>y:
        h=y


print(max(w-X,0)*max(h-Y,0))

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
X=Y=0
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1 and X<x:
    X=x
  if a==2 and w>x:
    w=x
  if a==3 and Y<y:
    Y=y
  if a==4 and h>y:
    h=y

print(max(w-X,0)*max(h-Y,0))

Submission status: Accepted

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

for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        for j in range(h):
            for k in range(x):
                board[j][k] = 0
    if a == 2:
        for j in range(h):
            for k in range(x, w):
                board[j][k] = 0
    if a == 3:
        for j in range(y):
            for k in range(w):
                board[j][k] = 0
    if a == 4:
        for j in range(y, h):
            for k in range(w):
                board[j][k] = 0
ans = 0
for i in board:
    ans += sum(i)
print(ans)

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
x_left = 0
x_right = w
y_bottom = 0
y_top = h
for i in range(n):
  x, y, a = map(int, input().split())
  if a == 1:
    x_left = max(x_left, x)
  if a == 2:
    x_right = min(x_right, x)
  if a == 3:
    y_bottom = max(y_bottom, y)
  if a == 4:
    y_top = min(y_top, y)

if x_right - x_left < 0  or  y_top - y_bottom < 0:
  print(0)
else:
  print((x_right - x_left) * (y_top - y_bottom))

Submission status: Accepted

Solution code:
w, h, n = map(int,input().split())
s = [0,w,0,h]
for i in range(n):
  x, y ,a = map(int,input().split()) 
  if a==1:
    s[0]=max(x, s[0])
  elif a==2:
    s[1]=min(x, s[1])
  elif a==3:
    s[2]=max(y, s[2])
  elif a==4:
    s[3]=min(y, s[3])
if s[1]-s[0] >=0 and s[3]-s[2] >=0:
  print((s[1]-s[0])*(s[3]-s[2]))
else:
  print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split(" "))
list_place = [0, w, 0, h]
for _ in range(n):
  x, y, a = map(int, input().split(" "))
  if a == 1:
    if x > list_place[0]:
      list_place[0] = x
  elif a == 2:
    if x < list_place[1]:
      list_place[1] = x
  elif a == 3:
    if y > list_place[2]:
      list_place[2] = y
  else:
    if y < list_place[3]:
      list_place[3] = y
if list_place[1] - list_place[0] < 0 or list_place[3] - list_place[2] < 0:
  print(0)
else:
  s = (list_place[1] - list_place[0]) * (list_place[3] - list_place[2])
  print(s)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input = __import__('sys').stdin.readline
W, H, N = map(int, input().split())
l = [[False]*W for _ in range(H)]
area = 0

for i in range(N):
    x, y, a = map(int, input().split())
    
    if a == 1:
        for i in range(H):
            for j in range(x):
                l[i][j] = True
    elif a == 2:
        for i in range(H):
            for j in range(x, W):
                l[i][j] = True
    elif a == 3:
        for i in range(y):
            for j in range(W):
                l[i][j] = True
    else:
        for i in range(y, H):
            for j in range(W):
                l[i][j] = True

for i in l:
    for j in i:
        if not j:
            area += 1

print(area)

Submission status: Accepted

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

for i in range(n):
    xi, yi, ai = map(int, input().split())
    if ai == 1 and xi > x:
        x = xi
    elif ai == 2 and xi < w:
        w = xi
    elif ai == 3 and yi > y:
        y = yi
    elif ai == 4 and yi < h:
        h = yi

if w <= x or h <= y:
    res = 0
else:
    res = (w-x) * (h-y)
print(res)

Submission status: Accepted

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

# initial area
area = [[0, 0], [w, h]]

for _ in range(n):
    # new point
    x, y, a = map(int, input().split())
    
    if (a == 1):
        if (area[1][0] < x):
            area[1][0] = area[0][0]
            break
        elif (area[0][0] < x):
            area[0][0] = x
    elif (a == 2):
        if (x < area[0][0]):
            area[0][0] = area[1][0]
            break
        elif (x < area[1][0]):
            area[1][0] = x
    elif (a == 3):
        if (area[1][1] < y):
            area[1][1] = area[0][1]
            break
        elif (area[0][1] < y):
            area[0][1] = y
    else:
        if (y < area[0][1]):
            area[0][1] = area[1][1]
            break
        elif (y < area[1][1]):
            area[1][1] = y

print((area[1][0] - area[0][0]) * (area[1][1] - area[0][1]))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

white = [0, w, 0, h]
for x, y, a in xya:
    if a == 1:
        white[0] = max(white[0], x)
    elif a == 2:
        white[1] = min(white[1], x)
    elif a == 3:
        white[2] = max(white[2], y)
    else:  # a == 4
        white[3] = min(white[3], y)

width = max(white[1] - white[0], 0)
height = max(white[3] - white[2], 0)

ans = width * height
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    w,h,n=map(int,input().split())
    A=[0,w,0,h] # xl,xh,yl,yh
    for _ in range(n):
        x,y,a=map(int,input().split())
        if a==1: A[0]=max(A[0],x)
        elif a==2: A[1]=min(A[1],x)
        elif a==3: A[2]=max(A[2],y)
        elif a==4: A[3]=min(A[3],y)
    print(max(0,A[1]-A[0])*max(0,A[3]-A[2]))
resolve()

Submission status: Accepted

Solution code:
import numpy as np
H, W, N = map(int, input().split())

L = np.ones((W,H))
for i in range(N):
  x, y, a = map(int, input().split())
  if a == 1:
    for i in range(x):
      for j in range(W):
        L[j][i] = 0
  elif a == 2:
    for i in range(x, H):
      for j in range(W):
        L[j][i] = 0
  elif a == 3:
    for i in range(y):
      for j in range(H):
        L[i][j] = 0
  elif a == 4:
    for i in range(y, W):
      for j in range(H):
        L[i][j] = 0

print (int(np.sum(L)))

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:
        l = max(l,x)
    elif a==2:
        r = min(r,x)
    elif a==3:
        d = max(d,y)
    else:
        u = min(u,y)
if r-l<=0 or u-d<=0:
    print(0)
else:
    print((r-l)*(u-d))

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
sx, gx, sy, gy = 0, w, 0, h
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1 and sx < x:
        sx = x
    if a == 2 and gx > x:
        gx = x
    if a == 3 and sy < y:
        sy = y
    if a == 4 and gy > y:
        gy = y
if (gx-sx) > 0 and (gy-sy) > 0:
    print(max((gx-sx)*(gy-sy), 0))
else:
    print(0)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
w,h,n=map(int,input().split())

l=[[0,0,0] for _ in range(n)]
for i in range(n):
    l[i][0],l[i][1],l[i][2]=map(int,input().split())
#print(l)

s=[0,w,0,h]
for i in range(n):
    if l[i][2]==1:
        s[0]=max(s[0],l[i][0])
    elif l[i][2]==2:
        s[1]=min(s[1],l[i][0])
    elif l[i][2]==3: 
        s[2]=max(s[2],l[i][1])
    elif l[i][2]==4:
        s[3]=min(s[3],l[i][1])
print((s[1]-s[0])*(s[3]-s[2]) if s[1]>=s[0] and s[3]>=s[2] else 0)

Submission status: Accepted

Solution code:
def main():
  w, h, k = map(int, raw_input().split())
  area = [[0 for _ in xrange(w)] for _ in xrange(h)]

  for _ in xrange(k):
    x, y, mode = map(int, raw_input().split())
    for a in xrange(h):
      for b in xrange(w):
        if mode == 1 and b < x:
          area[a][b] = 1
        if mode == 3 and a < y:
          area[a][b] = 1

        if mode == 2 and b >= x:
          area[a][b] = 1
        if mode == 4 and a >= y:
          area[a][b] = 1

  vol = 0
  for i in xrange(h):
    for j in xrange(w):
      elem = area[i][j]
      if elem == 0:
        vol += 1
  print(vol)


main()

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
U=[H]
D=[0]
R=[W]
L=[0]

for i in range(N):
  x,y,a=map(int,input().split())
  if a==1:
    L.append(x)
  if a==2:
    R.append(x)
  if a==3:
    D.append(y)
  if a==4:
    U.append(y)
#print(U)
#print(D)
#print(R)
#print(L)

#print(min(U))
#print(max(D))
#print(min(R))
#print(max(L))

H2=max(min(U)-max(D),0)
W2=max(min(R)-max(L),0)
print(H2*W2)

Submission status: Accepted

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

for i in range(N):
    xi, yi, ai = map(int, input().split())
    if ai == 1 and xi > x:
        x = xi
    elif ai == 2 and xi < W:
        W = xi
    elif ai == 3 and yi > y:
        y = yi
    elif ai == 4 and yi < H:
        H = yi
if W <= x or H <= y:
    ans = 0
else:
    ans = (W-x)*(H-y)
print(ans)

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
i = 0
x_1 =0
x_2 =w
y_1 =0
y_2 =h
for i in range(n):
    x,y,z = map(int,input().split())
    if z == 1 and x > x_1 :
        x_1 = x
    if z == 2 and x < x_2 :
        x_2 = x
    if z == 3 and y > y_1:
        y_1 = y
    if z == 4 and y < y_2:
        y_2 = y
if x_2 > x_1 and y_2 > y_1:
    print((x_2-x_1)*(y_2-y_1))
else:
    print(0)

Submission status: Accepted

Solution code:
import numpy as np
W, H, N = map(int, input().split())

g = np.array([[1] * W for _ in range(H)])

for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        g[:,:x] = 0
    elif a == 2:
        g[:,x:] = 0
    elif a == 3:
        g[H - y:,:] = 0
    elif a == 4:
        g[:H - y,:] = 0

print (g.sum())

# print (g)

Submission status: Accepted

Solution code:

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

lst = [[0] * W for _ in range(H)]
for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        for i in range(x):
            for j in range(H):
                lst[j][i] = 1
    elif a == 2:
        for i in range(x, W):
            for j in range(H):
                lst[j][i] = 1
    elif a == 3:
        for i in range(W):
            for j in range(y):
                lst[H - 1 - j][i] = 1
    elif a == 4:
        for i in range(W):
            for j in range(y, H):
                lst[H - 1 - j][i] = 1

ans = 0
for i in lst:
    ans += i.count(0)
    # print (i)
print (ans)

Submission status: Accepted

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

A = [0, -w, 0, -h]

for i in range(n):
    j = X[i][2]-1
    A[j] = max(A[j], X[i][j//2] * (-1) ** j)

# print(A)
print(max(0, -A[1]-A[0]) * max(0, -A[3]-A[2]))

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
xya = [list(map(int,input().split())) for _ in range(N)]
p1,p2 = [0,0],[W,H]

for *p,a in xya:
    if a == 1:
        if p1[0] < p[0]:
            p1[0] = p[0]
    elif a == 2:
        if p2[0] > p[0]:
            p2[0] = p[0]
    elif a == 3:
        if p1[1] < p[1]:
            p1[1] = p[1]
    else:
        if p2[1] > p[1]:
            p2[1] = p[1]

if p2[0] - p1[0] < 0 or p2[1] - p1[1] < 0:
    print(0)
else:
    print((p2[0] - p1[0]) * (p2[1] - p1[1]))

Submission status: Accepted

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

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

for *p, a in xya:
    if a == 1:
        if p1[0] < p[0]:
            p1[0] = p[0]
    elif a == 2:
        if p2[0] > p[0]:
            p2[0] = p[0]
    elif a == 3:
        if p1[1] < p[1]:
            p1[1] = p[1]
    else:
        if p2[1] > p[1]:
            p2[1] = p[1]

if p2[0]-p1[0] < 0 or p2[1] - p1[1] < 0:
    print(0)
else:
    print((p2[0]-p1[0]) * (p2[1] - p1[1]))