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())

maxx = W
minx = 0
maxy = H
miny = 0

for i in range(N):

    x,y,a = map(int,input().split())

    if a == 1:

        minx = max(minx,x)

    if a == 2:

        maxx = min(maxx,x)
        
    if a == 3:

        miny = max(miny,y)

    if a == 4:

        maxy = min(maxy,y)


print ( max (0,maxx-minx) * max (0,maxy-miny))

Submission status: Accepted

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

minx = 0
miny = 0
MAXx = W
MAXy = H

for k in range(N):
    if list[k][2] == 1:
        minx = max(list[k][0], minx)
    elif list[k][2] == 2:
        MAXx = min(list[k][0], MAXx)
    elif list[k][2] == 3:
        miny = max(list[k][1], miny)
    elif list[k][2] == 4:
        MAXy = min(list[k][1], MAXy)

if MAXx - minx < 0 or MAXy - miny < 0:
    print(0)
else:
    print((MAXx - minx) * (MAXy - miny))

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
arr = [[int(i) for i in input().split()] for j in range(n)]
x1, y1, x2, y2 = 0, 0, w, h

for x, y, a in arr:
    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)

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

Submission status: Accepted

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

l, r, d, u = 0, W, 0, H
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)

if l <= r and d <= u :
    print((r - l) * (u - d))
else :
    print(0)

Submission status: Accepted

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

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


for list in list:
    if list[2] == 1:
        x_min = max(list[0], x_min)
    elif list[2] == 2:
        x_max = min(list[0], x_max)
    elif list[2] == 3:
        y_min = max(list[1], y_min)
    else:
        y_max = min(list[1], y_max)
 
ans = max((x_max - x_min), 0) * max((y_max - y_min), 0)
print(ans)

Submission status: Accepted

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

x_min = 0
y_min = 0
x_max = w
y_max = h
for a in coord_list:
    if a[2] == 1:
        x_min = max(a[0], x_min)
    elif a[2] == 2:
        x_max = min(a[0], x_max)
    elif a[2] == 3:
        y_min = max(a[1], y_min)
    elif a[2] == 4:
        y_max = min(a[1], y_max)

ans = max((x_max - x_min), 0) * max((y_max - y_min), 0)
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
W,H,N = [int(x) for x in stdin.readline().rstrip().split()]
data = []
for _ in range(N):
    data.append([int(x) for x in stdin.readline().rstrip().split()])

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

for i in data:
    if i[2] == 1:
        x1 = max(x1,i[0])
    if i[2] == 2:
        x2 = min(x2,i[0])
    if i[2] == 3:
        y1 = max(y1,i[1])
    if i[2] == 4:
        y2 = min(y2,i[1])
#print(x1,x2,y1,y2)
ans = max(x2-x1,0) * max(y2-y1,0)
print(ans)

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
l = [list(map(int,input().split())) for _ in range(n)]
xmin = 0
ymin = 0
xmax = w
ymax = h
for i in range(n):
    if l[i][2] == 1:
        xmin = max([xmin,l[i][0]])
    elif l[i][2] == 2:
        xmax = min([xmax,l[i][0]])
    elif l[i][2] == 3:
        ymin = max([ymin,l[i][1]])
    elif l[i][2] == 4:
        ymax = min([ymax,l[i][1]])
if xmax <= xmin or ymax <= ymin:
    print(0)
else:
    print((xmax - xmin) * (ymax - ymin))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#ABC47 B

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

m = [[False]*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):
                m[i][j] = True
    elif a == 2:
        for i in range(h):
            for j in range(x,w):
                m[i][j] = True
    elif a == 3:
        for i in range(y):
            for j in range(w):
                m[i][j] = True
    elif a == 4:
        for i in range(y,h):
            for j in range(w):
                m[i][j] = True
ans = 0
for i in range(h):
    for j in range(w):
        if m[i][j] == False:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
li = [list(map(int,input().split())) for _ in range(n)]
x1 = 0
x2 = w
y1 = 0
y2 = h
for i in range(n):
  if li[i][2] == 1:
    x1 = max(x1,li[i][0])
  elif li[i][2] == 2:
    x2 = min(x2,li[i][0])
  elif li[i][2] == 3:
    y1 = max(y1,li[i][1])
  else:
    y2 = min(y2,li[i][1])
if x2 <= x1 or y2 <= y1:
  print(0)
else:
  print((x2-x1)*(y2-y1))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [tuple(map(typ, input().split())) if m > 1 else typ(input()) for _ in range(n)]


def main():
    W, H, N = read_h()
    pts = read_v(N, m=3)
    rec = [0, 0, W, H]

    for x, y, a in pts:
        if a == 1:
            rec[0] = max(rec[0], x)
        elif a == 2:
            rec[2] = min(rec[2], x)
        elif a == 3:
            rec[1] = max(rec[1], y)
        elif a == 4:
            rec[3] = min(rec[3], y)

        if rec[2] - rec[0] <= 0 or rec[3] - rec[1] <= 0:
            print(0)
            return

    ans = (rec[2] - rec[0]) * (rec[3] - rec[1])
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [tuple(map(typ, input().split())) if m > 1 else typ(input()) for _ in range(n)]


def main():
    W, H, N = read_h()
    pts = read_v(N, m=3)
    area = [[0, 0], [W, H]]

    for x, y, a in pts:
        if a == 1 and area[0][0] < x:
            area[0][0] = x
        elif a == 2 and area[1][0] > x:
            area[1][0] = x
        elif a == 3 and area[0][1] < y:
            area[0][1] = y
        elif a == 4 and area[1][1] > y:
            area[1][1] = y

        if area[1][0] - area[0][0] <= 0 or area[1][1] - area[0][1] <= 0:
            print(0)
            return

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

for x, y, a in (map(int, input().split()) for _ in range(N)):
  
  if a == 1:
    left = max(left, x)
  elif a == 2:
    right = min(right, x)
  elif a == 3:
    bottom = max(bottom, y)
  else:
    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())
q = 0
z = 0
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        if z <= x:
            z = x
    if a == 2:
        if w >= x:
            w = x
    if a == 3:
        if q <= y:
            q = y
    if a == 4:
        if h >= y:
            h = y
if w-z >= 0 and h-q >= 0:
    print((w-z)*(h-q))
else:
    print(0)

Submission status: Accepted

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

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

s1 = 0
s2 = w
t1 = 0
t2 = h

for i in range(n):
    if li[i][2] == 1:
        s1 = max(li[i][0],s1)
    if li[i][2] == 2:
        s2 = min(li[i][0],s2)
    if li[i][2] == 3:
        t1 = max(li[i][1],t1)
    if li[i][2] == 4:
        t2 = min(li[i][1],t2)

if s2-s1 < 0 or t2-t1 < 0:
    print(0)
    exit()
        
ans = (s2-s1) * (t2-t1)

print(ans if ans > 0 else 0)

Submission status: Accepted

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

X = 0
X1 = w
Y = 0
Y1 = h
for x, y, a in xyas:
    if a == 1:
        X = max(X, x)
        X1 = max(X1, x)
    elif a == 2:
        X = min(X, x)
        X1 = min(X1, x)
    elif a == 3:
        Y = max(Y, y)
        Y1 = max(Y1, y)
    else:
        Y = min(Y, y)
        Y1 = min(Y1, y)

print(abs(X - X1) * abs(Y - Y1))

Submission status: Accepted

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

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

x = p1[0]-p0[0]
y = p1[1]-p0[1]
if x < 0:
    x = 0
if y < 0:
    y = 0

print(x * y)

Submission status: Accepted

Solution code:
import numpy as np
row = input().split()
W = int(row[0])
H = int(row[1])
N = int(row[2])
row2 = [input().split() for i in range(N)]
f = np.vectorize(int)
x = f(row2)
white = [0,0,W,H]
for i in x:
    if i[2] == 1 and white[0] < i[0]:
        white[0] = i[0]
    if i[2] == 2 and white[2] > i[0]:
        white[2] = i[0]
    if i[2] == 3 and white[1] < i[1]:
        white[1] = i[1]
    if i[2] == 4 and white[3] > i[1]:
        white[3] = i[1]
x_dis = white[2]- white[0]
y_dis = white[3]- white[1]
if x_dis >= 0 and y_dis >= 0:
    print(x_dis*y_dis)
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    w,h,n = map(int,input().split(' '))
    x_y_a=[]
    for i in range(n):
        x_y_a.append(list(map(int,input().split(' '))))

    up = [i[1] for i in x_y_a if i[2] == 4]+[h]
    down = [i[1] for i in x_y_a if i[2] == 3]+[0]
    left = [i[0]for i in x_y_a if i[2] == 1]+[0]
    right = [i[0] for i in x_y_a if i[2] == 2]+[w]
    if min(up)-max(down) < 0 or min(right) - max(left) < 0:
        ans = 0
    else:
        ans = (min(up)-max(down))*(min(right)-max(left))
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
xmin = 0
xmax = w
ymin = 0
ymax = h
for i in range(n):
    x, y, a = map(int, 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(xmax-xmin, 0)*max(ymax-ymin, 0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
ans = W*H
L_x = 0
D_y = 0


for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        if x >= W:
            ans = 0
            break
        elif L_x <= x < W:
            L_x = x

    elif a == 2:
        if x <= L_x:
            ans = 0
            break
        elif L_x <= x <= W:
            W = x

    elif a == 3:
        if H <= y:
            ans = 0
            break
        elif D_y <= y < H:
            D_y = y

    else:
        if y <= D_y:
            ans = 0
            break
        elif D_y < y <= H:
            H = y
if ans == 0:
    print(ans)
else:
    print((H - D_y) * (W - L_x))

Submission status: Accepted

Solution code:
def main():
    x_max, y_max, n = map(int, input().split())
    x_min, y_min = 0, 0

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

        if a == 1:
            x_min = max(x_min, x)
        elif a == 2:
            x_max = min(x_max, x)
        elif a == 3:
            y_min = max(y_min, y)
        elif a == 4:
            y_max = min(y_max, y)

    print(max(0, x_max - x_min) * max(0, y_max - y_min))

        # 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
        # 
        # if (x_max <= x_min) or (y_max <= y_min):
        #     print(0)
        #     return

    # print((x_max - x_min) * (y_max - y_min))

if __name__ == "__main__":

    main()

Submission status: Accepted

Solution code:
def main():
    x_max, y_max, n = map(int, input().split())
    x_min, y_min = 0, 0

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

        if a == 1:
            x_min = max(x_min, x)
        elif a == 2:
            x_max = min(x_max, x)
        elif a == 3:
            y_min = max(y_min, y)
        elif a == 4:
            y_max = min(y_max, y)

    print(max(0, (x_max - x_min)) * max(0, (y_max - y_min)))

        # 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
        # 
        # if (x_max <= x_min) or (y_max <= y_min):
        #     print(0)
        #     return

    # print((x_max - x_min) * (y_max - y_min))

if __name__ == "__main__":

    main()

Submission status: Accepted

Solution code:
def main():
    x_max, y_max, n = map(int, input().split())
    x_min, y_min = 0, 0

    for n 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

        if (x_max <= x_min) or (y_max <= y_min):
            print(0)
            return

    print((x_max - x_min) * (y_max - y_min))

if __name__ == "__main__":

    main()

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
x1=0
y1=0
x2=w
y2=h
for i 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)
print(max(0,(x2-x1))*max(0,(y2-y1)))

Submission status: Accepted

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

#座標用配列
s = [[1 for i in range(w)] for j in range(h)]

    
#標準入力
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        for j in range(h):
            s[j][0:x] = [0 for k in range(x)]         
    elif a ==2:
        for j in range(h):
            s[j][x:w] = [0 for k in range(x,w)]       
    elif a ==3:
        for j in range(y):
            s[j] = [0 for k in range(w)]   
    elif a==4:
        for j in range(y,h):
            s[j] =[0 for k in range(w)]
            

cnt = 0
for i in s:
    cnt += sum(i)
print(cnt)

Submission status: Accepted

Solution code:
W, H, N = list(map(int, input().split()))
#1-> x < x_i, 2-> x > x_i, 3-> y < y_i, 4-> y > y_i
d = {'1': 0,
	 '2': W,
	 '3': 0,
	 '4': H}
for i in range(N):
	x, y, a = list(map(int, input().split()))
	if a == 1:
		if x > d['1']:
			d['1'] = x
	elif a == 2:
		if x < d['2']:
			d['2'] = x
	elif a == 3:
		if y > d['3']:
			d['3'] = y
	else:
		if y < d['4']:
			d['4'] = y
if d['1'] > d['2'] or d['3'] > d['4']:
	print(0)
else:
	print((d['2']-d['1']) * (d['4']-d['3']))

Submission status: Accepted

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

x_min = 0
y_min = 0
x_max = W
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

width = x_max - x_min
height = y_max - y_min
if width > 0 and height > 0:
    print(width * height)
else:
    print(0)

Submission status: Accepted

Solution code:
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18

W, H, N = list(map(int, sys.stdin.readline().split()))
X, Y, A = list(zip(*[map(int, sys.stdin.readline().split()) for _ in range(N)]))

board = np.ones((W, H), dtype=bool)
for x, y, a in zip(X, Y, A):
    if a == 1:
        board[:x, :] = 0
    if a == 2:
        board[x:, :] = 0
    if a == 3:
        board[:, :y] = 0
    if a == 4:
        board[:, y:] = 0
print(board.sum())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
xl, yl, xr, yr = 0, 0, W, H
for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        xl = max(xl, x)
    elif a == 2:
        xr = min(xr, x)
    elif a == 3:
        yl = max(yl, y)
    else:
        yr = min(yr, y)

if xl < xr and yl < yr:
    print(int((xr - xl) * (yr - yl)))
else:
    print(0)

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
point = [list(map(int,input().split())) for i in range(N)]
x_min = 0
x_max = W
y_min = 0
y_max = H

for i in point:
    if i[2] == 1:
        x_min = max(x_min,i[0])
    elif i[2] == 2:
        x_max = min(x_max,i[0])
    elif i[2] == 3:
        y_min = max(y_min,i[1])
    else:
        y_max = min(y_max,i[1])

x_line = x_max - x_min
y_line = y_max - y_min

if x_line > 0 and y_line > 0:
    print(x_line*y_line)
else:
    print(0)

Submission status: Accepted

Solution code:
o1=0
o2=0
oo1=0
oo2=0
w,h,n=map(int,input().split())
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        oo1=max(o1+x,oo1)
    elif a==2:
        w=min(x,w)
    elif a==3:
        oo2=max(o2+y,oo2)
    else:h=min(y,h)
if oo1>=w or oo2>=h:
    print(0)
else:print((w-oo1)*(h-oo2))

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
x = [0] * N
y = [0] * N
a = [0] * N
x1 = 0
x2 = W
y3 = 0
y4 = H
for i in range(N):
    x[i], y[i], a[i] = map(int, input().split())
    if a[i] == 1:
        if x1 < x[i]:
            x1 = x[i]
    elif a[i] == 2:
        if x2 > x[i]:
            x2 = x[i]
    elif a[i] == 3:
        if y3 < y[i]:
            y3 = y[i]
    elif a[i] == 4:
        if y4 > y[i]:
            y4 = y[i]

if x2-x1 <=0 or y4-y3 <= 0:
    print(0)
else:
    print((x2-x1)*(y4-y3))

Submission status: Accepted

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

b = 0
t = H
l = 0
r = W

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:
    b = max(b, y)
  else:
    assert a==4
    t = min(t, y)
print( max(t-b, 0) * max(r-l, 0) )

Submission status: Accepted

Solution code:
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

W, H, N =  nl()

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

for i in range(N):
    x, y, a = nl()
    if a == 1:
        left = max(left, x)
    elif a == 2:
        right = min(right, x)
    elif a == 3:
        bottom = max(bottom, y)
    else:
        top = min(top, y)

print(max(top - bottom, 0) * max(right - left, 0))

Submission status: Accepted

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

xya = [0]*N
for i in range(N):
    xya[i] = map(int, input().split())
WH = []
for h in range(H):
    w = [0]*W
    WH.append(w)

for x,y,a in xya:
    if a == 1:
        for w in WH:
            for i in range(0,x):
                w[i] = 1
    elif a == 2:
        for w in WH:
            for i in range(x,W):
                w[i] = 1
    elif a == 3:
        for i in range(0,y):
            w = WH[i]
            for j in range(len(w)):
                w[j] = 1
    elif a == 4:
        for i in range(y,H):
            w = WH[i]
            for j in range(len(w)):
                w[j] = 1

result = 0
for w in WH:
    result += sum(w)
print(W*H - result)

Submission status: Accepted

Solution code:
def abc():
    w, h, n = map(int, input().split())
    field = [[1] * w] * h
    for i in range(n):
        x, y, a = map(int, input().split())
        if a == 1:
            for f in field:
                f[:x] = [0] * x
        if a == 2:
            for f in field:
                f[x:] = [0] * (w - x)
        if a == 3:
            for j in range(y):
                field[j] = [0] * w
        if a == 4:
            for j in range(y, h):
                field[j] = [0] * w
    ans = 0
    for f in field:
        ans += sum(f)
    print(ans)


abc()

Submission status: Accepted

Solution code:
w, h, n = [ int(v) for v in input().split() ]
u, d, l, r = h, 0, 0, w

for i in range(n):
    x, y, a = [ int(v) for v in input().split() ]
    if a == 1 and x >= l:
        l = x
    elif a == 2 and x <= r:
        r = x
    elif a == 3 and y >= d:
        d = y
    elif a == 4 and y <= u:
        u = y



print(max(0,r-l)*max(0,u-d))

Submission status: Accepted

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

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

L.sort(key=lambda x: x[0])
R.sort(key=lambda x: x[0])
U.sort(key=lambda x: x[1])
D.sort(key=lambda x: x[1])

print(max(R[0][0] - L[-1][0], 0) * max(U[0][1] - D[-1][1], 0))

Submission status: Accepted

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

Submission status: Accepted

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

min_x = W
max_x = 0
min_y = H
max_y = 0
for i in range(N):
    x,y,a = [int(i) for i in input().split()]
    if a == 1:
        max_x = max(max_x,x)
    elif a == 2:
        min_x = min(min_x,x)
    elif a == 3:
        max_y = max(max_y,y)
    else:
        min_y = min(min_y,y)

if min_x <= max_x or min_y <= max_y:
    print(0)
else:
    print((min_x-max_x)*(min_y-max_y))

Submission status: Accepted

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

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

    if a == 1:
        W0 = max(W0, x)
    elif a == 2:
        W = min(W, x)
    elif a == 3:
        H0 = max(H0, y)
    else:
        H = min(H, y)

# X, Y, X and Yが負のケースでは答えは0
X = max(0, W - W0)
Y = max(0, (H - H0))

print(X * Y)

Submission status: Accepted

Solution code:
from subprocess import*
call(('python3','-c',"""
import numpy
I=lambda:map(int,input().split())
W,H,N=I()
m=numpy.zeros((H,W),int)
while N:x,y,a=I();m[y*(a>3):H*(a^3)or y,x*(a==2):W*~-a or x]=1;N-=1
print(W*H-m.sum())
"""))

Submission status: Accepted

Solution code:
w,h,n = map(int, input().split())
x1,y1 = 0, 0
x2, y2 = w, h
for i 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)

if (x2 - x1 < 0) or (y2 - y1 < 0):
    print(0)
else:
    print(max((x2 - x1) * (y2 - y1), 0))

Submission status: Accepted

Solution code:
import sys

W, H, N = map(int, input().split())
l = d = 0
u = H
r = W
for i in range(N):
    x, y, a = list(map(int, input().split()))
    if a == 1:
        l = max(x, l)
    if a == 2:
        r = min(x, r)
    if a == 3:
        d = max(y, d)
    if a == 4:
        u = min(y, u)

ans = (r - l) * (u - d)
if r - l < 0 or u - d < 0:
    ans = 0
print(max(ans, 0))

Submission status: Accepted

Solution code:
import numpy as np
w, h, n = map(int, input().split())
arr = np.zeros((w, h))
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        arr[:x] = np.ones((x, h))
    elif a == 2:
        arr[x:] = np.ones((w - x, h))
    elif a == 3:
        arr[:, :y] = np.ones((w, y))
    elif a == 4:
        arr[:, y:] = np.ones((w, h - y))
print(int(w * h - np.sum(arr)))

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split(' '))
x_mi = 0
x_ma = w
y_mi = 0
y_ma = h
for _ in range(n):
    x, y, a = map(int, input().split(' '))
    if a == 1:
        if x_mi < x:
            x_mi = x
    if a == 2:
        if x_ma > x:
            x_ma = x
    if a == 3:
        if y_mi < y:
            y_mi = y
    if a == 4:
        if y_ma > y:
            y_ma = y
if y_ma - y_mi <=0 or x_ma - x_mi <= 0:
    print(0)
else:
    print((x_ma - x_mi)*(y_ma - y_mi))

Submission status: Accepted

Solution code:
xmax,ymax,N=map(int,input().split())
xmin=0
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,(xmax-xmin))*max(0,(ymax-ymin)))

Submission status: Accepted

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

L = 0
R = W
D = 0
U = H

for _ in range(N):
  x,y,a = map(int,input().split())
  if a == 1:
    L = max(L,x)
  if a == 2:
    R = min(R,x)
  if a == 3:
    D = max(D,y)
  if a == 4:
    U = min(U,y)

x = max(0,R-L)
y = max(0,U-D)
answer = x*y

print(answer)

Submission status: Accepted

Solution code:
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

W, H, N = mi()

#H[0], H[1]が白い部分の左端～右端を表す
H = [0, H]
W = [0, W]

for i in range(N):
  x, y, a = mi()
  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])
  else:
    H[1] = min(y,H[1])

print(max((H[1]-H[0]),0)*max((W[1]-W[0]),0))

Submission status: Accepted

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

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

w1 = int(w)
h1 = int(h)

a = [list(map(int, input().split())) for i in range(n)]

ar = [[0]*w for i in range(h)]

for x, y, aa in a:
    x -= 1
    y -= 1
    if aa == 1:
        for i in range(h):
            for j in range(w):
                if j <= x:
                    ar[i][j] += 1
    if aa == 2:
        for i in range(h):
            for j in range(w):
                if j > x:
                    ar[i][j] += 1
    if aa == 3:
        for i in range(h):
            for j in range(w):
                if i <= y:
                    ar[i][j] += 1
    if aa == 4:
        for i in range(h):
            for j in range(w):
                if i > y:
                    ar[i][j] += 1

print(sum(ar, []).count(0))

Submission status: Accepted

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

X = [0, W]
Y = [0, H]

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

    if a == 1 and X[0] < x:
        X[0] = x
    elif a == 2 and x < X[1]:
        X[1] = x
    elif a == 3 and Y[0] < y:
        Y[0] = y
    elif a == 4 and y < Y[1]:
        Y[1] = y
    
if X[1] > X[0] and Y[1] > Y[0]:
    result = (X[1] - X[0]) * (Y[1] - Y[0])
else:
    result = 0

print(result)

Submission status: Accepted

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

Submission status: Accepted

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