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:
width, high, num = map(int, input().split())
arr = [list(map(int, input().split())) for i in range(num)]

def rec(xl, yl, xh, yh, arr):
    if xl>xh or yl>yh:
        return 0
    if len(arr) == 0:
        return (xh-xl)*(yh-yl)
    if arr[0][2] == 1:
        xl = max(arr[0][0], xl)
        arr = arr[1:len(arr)]
        return rec(xl, yl, xh, yh, arr)
    elif arr[0][2] == 2:
        xh = min(arr[0][0], xh)
        arr = arr[1:len(arr)]
        return rec(xl, yl, xh, yh, arr)
    elif arr[0][2] == 3:
        yl = max(arr[0][1], yl)
        arr = arr[1:len(arr)]
        return rec(xl, yl, xh, yh, arr)
    elif arr[0][2] == 4:
        yh = min(arr[0][1], yh)
        arr = arr[1:len(arr)]
        return rec(xl, yl, xh, yh, arr)

print(rec(0, 0, width, high, arr))

Submission status: Accepted

Solution code:
width, height, num = map(int, input().rstrip("\n").split())
area = [0, width, 0, height]
for _ in range(num):
    x, y, a = map(int, input().rstrip("\n").split())
    area[a - 1] = [max, min][(a - 1) % 2](area[a - 1], [x, y][a > 2])

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

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
a = [0,w,0,h]
for i in range(n):
    xi,yi,ai = map(int,input().split())
    if ai == 1:
        a[0] = max(a[0],xi)
    elif ai == 2:
        a[1] = min(a[1],xi)
    elif ai == 3:
        a[2] = max(a[2],yi)
    else:
        a[3] = min(a[3],yi)

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

w1 = 0
w2 = W
h1 = 0
h2 = H
ans = 0
tLst = [list(map(int, input().split())) for i in range(N)]

for i in range(N):
    if tLst[i][2] == 1:
        w1 = max(w1, tLst[i][0])
    elif tLst[i][2] == 2:
        w2 = min(w2, tLst[i][0])
    elif tLst[i][2] == 3:
        h1 = max(h1, tLst[i][1])
    elif tLst[i][2] == 4:
        h2 = min(h2, tLst[i][1])

w = w2 - w1
h = h2 - h1
if w <= 0 or h <= 0:
    ans = 0
else:
    ans = int(w * h)
print(ans)

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
more_y = H
less_y = 0
more_x = W
less_x = 0
for _ in range(N):
  _x, _y, _type = map(int, input().split())
  if _type == 1:
    less_x = max(less_x, _x)
  elif _type == 2:
    more_x = min(more_x, _x)
  elif _type == 3:
    less_y = max(less_y, _y)
  else:
    more_y = min(more_y, _y)
if more_x <= less_x or more_y <= less_y:
  print(0)
else:
  print((more_x-less_x)*(more_y-less_y))

Submission status: Accepted

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

for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1 and x0 < x:
        x0 = x
    elif a == 2 and x < w:
        w = x
    elif a == 3 and y0 < y:
        y0 = y
    elif a == 4 and y < h:
        h = y

print(max(0, w - x0) * max(0, h - y0))

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
s=[[0 for i in range(h)] for j in range(w)]
for i in range(n):
	a,b,c=map(int,input().split())
	if c==1:
		for x in range(a):
			for y in range(h):
				s[x][y]=1
	elif c==2:
		for x in range(a,w):
			for y in range(h):
				s[x][y]=1
	elif c==3:
		for x in range(w):
			for y in range(b):
				s[x][y]=1
	else:
		for x in range(w):
			for y in range(b,h):

				s[x][y]=1
cnt=0
for i in range(w):
	for j in range(h):
		if s[i][j]==0:
			cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
a, b, c = map(int, input().split())
x = y = 0
for i in range(c):
    d, e, f = map(int, input().split())
    if f == 1:
        x = max(x, d)
    elif f == 2:
        a = min(a, d)
    elif f == 3:
        y = max(y, e)
    elif f == 4:
        b = min(b, e)
if x >= a or y >= b:
    print(0)
else:
    print(abs(a - x) * abs(b - y))

Submission status: Accepted

Solution code:
a, b, c = map(int, input().split())
x = y = 0
for i in range(c):
    d, e, f = map(int, input().split())
    if f == 1:
        x = max(x, d)
    elif f == 2:
        a = min(a, d)
    elif f == 3:
        y = max(y, e)
    elif f == 4:
        b = min(b, e)
if x >= a or y >= b:
    print(0)
else:
    print(abs(a - x) * abs(b - y))

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
x_max=W
x_min=0
y_max=H
y_min=0
for i in range(N):
  li=list(map(int,input().split()))
  if li[2]==1 and li[0]>x_min:
    x_min=li[0]
  elif li[2]==2 and li[0]<x_max:
    x_max=li[0]
  elif li[2]==3 and li[1]>y_min:
    y_min=li[1]
  elif li[2]==4 and li[1]<y_max:
    y_max=li[1]
    
#print(x_max,x_min,y_max,y_min)
s=(x_max-x_min)*(y_max-y_min)
if s>0 and x_max-x_min>0 and y_max-y_min:
  print(s)
else:
  print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
w, h, n = map(int,input().split())
arr = [[0 for i in range(w)] for j in range(h)]
sums = 0
for i in range(n):
  x, y, a = map(int,input().split())
  if a == 1:
    for i in range(x):
      for j in range(h):
        arr[j][i] = 1
  elif a == 2:
    for i in range(x,w):
      for j in range(h):
        arr[j][i] = 1
  elif a == 3:
    for i in range(y):
      for j in range(w):
        arr[i][j] = 1
  else:
    for i in range(y,h):
      for j in range(w):
        arr[i][j] = 1
for i in arr:
  sums += i.count(0)
print(sums)

Submission status: Accepted

Solution code:
# ABC 47, B - sunuke coloring easy 2
w, h, n = [int(el) for el in input().split(' ')]
field = [[int(el) for el in input().split(' ')] for i in range(n)]

left = 0
right = w
top = h
bottom = 0

for i in range(n):
    if field[i][2] == 1:
        left = max(left, field[i][0])
    if field[i][2] == 2:
        right = min(right, field[i][0])
    if field[i][2]  == 3:
        bottom = max(bottom, field[i][1])
    if field[i][2] == 4:
        top = min(top, field[i][1])
print(max(top - bottom, 0) * max(right - left, 0))

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())
anslist = [[1 for i in range(H)] for j in range(W)]
for i in range(N):
  if a[i] == 1:
    for k in range(x[i]):
      for l in range(H):
        anslist[k][l] = 0
  elif a[i] == 2:
     for k in range(x[i], W):
      for l in range(H):
        anslist[k][l] = 0
  elif a[i] == 3:
     for k in range(W):
      for l in range(y[i]):
        anslist[k][l] = 0
  elif a[i] == 4:
     for k in range(W):
      for l in range(y[i],H):
        anslist[k][l] = 0
print(sum([sum(anslist[i]) for i in range(W)]))

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
data = []
for i in range(n):
    data.append(list(map(int,input().split())))
map_data = [[0 for i in range(w)] for j in range(h)]
for i in range(n):
    if data[i][2] == 1:
       for j in range(h):
           for k in range(0,data[i][0]):
               map_data[j][k] = 1
    elif data[i][2] == 2:
       for j in range(h):
           for k in range(data[i][0],w):
               map_data[j][k] = 1
    elif data[i][2] == 3:
       for j in range(0,data[i][1]):
           for k in range(w):
               map_data[j][k] = 1
    else:
       for j in range(data[i][1],h):
           for k in range(w):
               map_data[j][k] = 1
ans = 0
for i in range(h):
    ans += map_data[i].count(0)
print(ans)

Submission status: Accepted

Solution code:
w, h, n = list(map(int, input().split()))
al, xl, yl = [0 for i in range(n)], [0 for i in range(n)], [0 for i in range(n)]
for i in range(n):
	x,y,a = list(input().split())
	xl[i] = int(x)
	yl[i] = int(y)
	al[i] = a

total = w*h
d = {"1": 0, "2": w, "3": 0, "4": h}
for i in range(n):
	if al[i] == "1":
		if xl[i] > d["1"]:
			d["1"] = xl[i]
	elif al[i] == "2":
		if xl[i] < d["2"]:
			d["2"] = xl[i]
	elif al[i] == "3":
		if yl[i] > d["3"]:
			d["3"] = yl[i]
	else:
		if yl[i] < d["4"]:
			d["4"] = yl[i]
if (d["2"]-d["1"]) <= 0 or (d["4"]-d["3"]) <= 0:
	print(0)
else:
	print((d["2"]-d["1"]) * (d["4"]-d["3"]))

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
a_r = w
a_l = 0
a_u = h
a_d = 0
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        a_l = max(a_l, x)
    elif a == 2:
        a_r = min(a_r, x)
    elif a == 3:
        a_d = max(a_d, y)
    else:
        a_u = min(a_u, y)


print(max(0, a_r - a_l) * max(0, a_u - a_d))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, fractions, itertools


def solve(W: int, H: int, N: int, x: "List[int]", y: "List[int]", a: "List[int]"):
    xmin = W
    xmax = 0
    ymin = H
    ymax = 0
    for i in range(N):
        if a[i] == 1:
            xmax = max(xmax, x[i])
        elif a[i] == 2:
            xmin = min(xmin, x[i])
        elif a[i] == 3:
            ymax = max(ymax, y[i])
        else:
            ymin = min(ymin, y[i])
    print((max(ymin - ymax, 0))* max(xmin - xmax, 0))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    W = int(next(tokens))  # type: int
    H = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]" 
    y = [int()] * (N)  # type: "List[int]" 
    a = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
        a[i] = int(next(tokens))
    solve(W, H, N, x, y, a)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
x1mx = 0
x2mi = W
y3mx = 0
y4mi = H

for i in range(N):
    x,y,a = map(int,input().split())
    if a == 1:
        if x > x1mx:
            x1mx =x
    elif a == 2:
        if x < x2mi:
            x2mi =x
    elif a == 3:
        if y > y3mx:
            y3mx =y
    elif a ==4:
        if y < y4mi:
            y4mi =y

if x1mx >=x2mi or  y3mx >= y4mi:
    print(0)
else:
    print((x2mi - x1mx)*(y4mi - y3mx))

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
fld = []
for i in range(h):
    l = []
    for j in range(w):
       l.append(0)
    fld.append(l)

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):
                fld[j][k] = 1
    elif a == 2:
        for j in range(h):
            for k in range(x,w):
                fld[j][k] = 1
    elif a == 3:
        for j in range(w):
            for k in range(y):
                fld[k][j] = 1
    else:
        for j in range(w):
            for k in range(y,h):
                fld[k][j] = 1

cnt = 0
for i in range(h):
    for j in range(w):
        if fld[i][j] == 0:
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
bo = [[0]*W]*H
for i in range(N):
    x,y,z = map(int,input().split())
    if z == 1:
        for j in range(H):
            for k in range(x):
                bo[j][k] = 1
    elif z == 2:
        for j in range(H):
            for k in range(x,W,1):
                bo[j][k] = 1
    elif z == 3:
        for j in range(y):
            bo[j] = [1]*W
    else:
        for j in range(H-1,y-1,-1):
            bo[j] = [1]*W

sum = 0

for i in range(H-1,-1,-1):
    sum += bo[i][:].count(1)
print((W*H)-sum)

Submission status: Accepted

Solution code:
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import bisect



def main():
    width, high, num = map(int, input().split())
    data = [[0 for i in range(width)] for j in range(high)]

    for i in range(num):
        x, y, a = map(int, input().split())
        if a == 1:
            for j in range(high):
                for k in range(x):
                    data[j][k] = 1
        elif a == 2:
            for j in range(high):
                for k in range(x, width):
                    data[j][k] = 1
        elif a == 3:
            for j in range(y):
                for k in range(width):
                    data[j][k] = 1
        elif a == 4:
            for j in range(y, high):
                for k in range(width):
                    data[j][k] = 1

        # print(data)

    # for i in range(high):
    #     print(data[i])

    ans = 0
    for i in range(high):
        ans += data[i].count(0)

    print(ans)





if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools

w, h, n = map(int, input().split())
x = [None] * n
y = [None] * n
a = [None] * n
for i in range(n):
    x[i], y[i], a[i] = map(int, input().split())


area = [[False] * h for _ in range(w)]
for i in range(n):
    for p, q in itertools.product(range(w), range(h)):
        if a[i] == 1 and p < x[i]:  area[p][q] = True
        if a[i] == 2 and p >= x[i]: area[p][q] = True
        if a[i] == 3 and q < y[i]:  area[p][q] = True
        if a[i] == 4 and q >= y[i]: area[p][q] = True

print(sum(sum(1 for v in row if not v) for row in area))

Submission status: Accepted

Solution code:
import numpy as np


w, h, n = map(int, input().split())
m = np.zeros((h, w), int)
while n:
    x, y, a = map(int, input().split())
    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:
import numpy as np
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())

check = [[0]*W for _ in range(H)]

for i in range(N):
    if a[i] == 1:
        for j in range(H):
            k = 0
            while k != x[i]:
                check[j][k] = 1
                k += 1
    if a[i] == 2:
        for j in range(H):
            k = x[i]
            while k != W:
                check[j][k] = 1
                k += 1
    if a[i] == 3:
        k = 0
        while k != y[i]:
            for j in range(W):
                check[k][j] = 1
            k += 1
    if a[i] == 4:
        k = y[i]
        while k != H:
            for j in range(W):
                check[k][j] = 1
            k += 1


ans = 0

for i in range(H):
    tmp = check[i].count(0)
    ans += tmp

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(W: int, H: int, N: int, x: "List[int]", y: "List[int]", a: "List[int]"):
    x0, x1 = 0, W
    y0, y1 = 0, H
    for i in range(N):
        if a[i] == 1:
            x0 = max(x0, x[i])
        if a[i] == 2:
            x1 = min(x1, x[i])
        if a[i] == 3:
            y0 = max(y0, y[i])
        if a[i] == 4:
            y1 = min(y1, y[i])
    if x1 <= x0 or y1 <= y0:
        ret = 0
    else:
        ret = (x1 - x0) * (y1 - y0)
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    W = int(next(tokens))  # type: int
    H = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]" 
    y = [int()] * (N)  # type: "List[int]" 
    a = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
        a[i] = int(next(tokens))
    solve(W, H, N, x, y, a)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
D=[list(map(int,input().split()))for _ in range(N)]
sx=0
sy=0
lx=W
ly=H
for d in D:
  if d[2]==1:
    sx=max(sx,d[0])
    #左側から作るイメージ(値が大きいなら拡張)
  elif d[2]==2:
    lx=min(lx,d[0])
    #右側から作る(値が小さい方が拡張)
  elif d[2]==3:
    sy=max(sy,d[1])
  else:
    ly=min(ly,d[1])
if lx<=sx or ly<=sy:
  print(0)
else:
  print((lx-sx)*(ly-sy))

Submission status: Accepted

Solution code:
W,H,M = map(int, input().split())
maxX,minX,maxY,minY = W, 0, H ,0
for i in range(M):
  x, y, a = map(int, input().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

  
xl = maxX - minX
yl = maxY - minY
if xl > 0 and yl > 0:
  print(xl * yl)
else:
  print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
area = []
for i in range(h):
    temp = [0] * w
    area.append(temp)
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        for j in range(x):
            for k in range(h):
                area[k][j] = 1
    elif a == 2:
        for j in range(x, w):
            for k in range(h):
                area[k][j] = 1
    elif a == 3:
        for j in range(w):
            for k in range(y):
                area[k][j] = 1
    else:
        for j in range(w):
            for k in range(y, h):
                area[k][j] = 1
count = 0
for i in range(w):
    for j in range(h):
        if area[j][i] == 0:
            count += 1
print(count)

Submission status: Accepted

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

grid = np.array([[0] * W] * H)

for n in range(N):
    tmp_w, tmp_h, a = map(int, input().split())
    if a == 1:
        grid.T[: tmp_w] = 1
    if a == 2:
        grid.T[tmp_w:] = 1
    if a == 3:
        grid[0: tmp_h] = 1
    if a == 4:
        grid[tmp_h: ] = 1
    #print(grid)

print(Counter((grid.reshape(1, W * H).tolist())[0])[0])

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
Xmax, Xmin, Ymax, Ymin = W, 0, H, 0

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1 and x > Xmin:
        Xmin = x
    elif a == 2 and x < Xmax:
        Xmax = x
    elif a == 3 and y > Ymin:
        Ymin = y
    elif a == 4 and y < Ymax:
        Ymax = y

if Xmax - Xmin > 0 and Ymax - Ymin > 0:
    print((Xmax-Xmin) * (Ymax - Ymin))
else:
    print(0)

Submission status: Accepted

Solution code:
W, H, N = map(int,input().split())
xmin,xmax,ymin,ymax = 0,W,0,H
for _ in range(N):
    x,y,a = map(int,input().split())
    if a == 1:
        if x > xmin:
            xmin = x
    elif a == 2:
        if x < xmax:
            xmax = x
    elif a == 3:
        if y > ymin:
            ymin = y
    else:
        if y < ymax:
            ymax = y

#ans = max(0,(xmax-xmin)*(ymax-ymin))
if xmax-xmin > 0 and ymax-ymin > 0:
    print((xmax-xmin)*(ymax-ymin))
else:
    print(0)

Submission status: Accepted

Solution code:
#ABC047b
import sys
import numpy as np
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

w, h, n = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]
square = np.zeros((h, w), dtype="int16")

for i in l:
    if (i[2] == 1):
        square[:, :i[0]] = 1
    elif (i[2] == 2):
        square[:, i[0]:] = 1
    elif (i[2] == 3):
        square[:i[1], :] = 1
    else:
        square[i[1]:, :] = 1
#print(square)
print(w*h-np.sum(square))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

def main():
    w, h, N = map(int, input().split())
    xya = [list(map(int, input().split())) for i in range(N)]


    top = h
    bottom = 0
    left = 0
    right = w
    for i in range(N):
        x, y, a = xya[i]
        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("top:{} bottom:{} left:{} right:{}".format(top, bottom, left, right))
    if bottom >= top or left >= right:
        print(0)
    else:
        print((top-bottom)*(right-left))




if __name__ == "__main__":
    main()

Submission status: Accepted

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

wl = 0
wr = W
hu = H
hl = 0

for i in range(N):
    x,y,a = map(int,input().split())
    if a == 1 and x > wl:
        wl = x
    elif a == 2 and x < wr:
        wr = x
    elif a == 3 and y > hl:
        hl =y
    elif a == 4 and y < hu:
        hu = y
    
if wl>wr or hl>hu:
    print(0)
else:
    print((wr-wl)*(hu-hl))

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
x0, x1, y0, y1 = 0, W, 0, H
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        x0 = max(x0, x)
    if a == 2:
        x1 = min(x1, x)
    if a == 3:
        y0 = max(y0, y)
    if a == 4:
        y1 = min(y1, y)

if x1 > x0 and y1 > y0:
    print((x1 - x0) * (y1 - y0))
else:
    print(0)

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
board = []
for i in range(0, H):
	lst = []
	for j in range(0, W):
		lst.append(1)
	board.append(lst)
for i in range(0, N):
	x, y, a = map(int, input().split())
	X = [0, 0]
	Y = [0, 0]
	if a == 1:
		X = [0, x]
		Y = [0, H]
	elif a == 2:
		X = [x, W]
		Y = [0, H]
	elif a == 3:
		X = [0, W]
		Y = [0, y]
	else:
		X = [0, W]
		Y = [y, H]
	for j in range(Y[0], Y[1]):
		for k in range(X[0], X[1]):
			board[j][k] = 0
cnt = 0
for i in range(0, H):
	for j in range(0, W):
		cnt += board[i][j]
print(cnt)

Submission status: Accepted

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

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

print(w * h - sum(sum(it) for it in a))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b, c = LI()
    if a == b + c:
        print("Yes")
    elif b == a + c:
        print("Yes")
    elif c == a + b:
        print("Yes")
    else:
        print("No")
    return

#B
def B():
    W, H, n = LI()
    wh = [[0, W], [0, H]]
    for _ in range(n):
        x, y, a = LI()
        wha = wh[a > 2]
        x = y if a > 2 else x
        wha[0] = max(x, wha[0]) * (a % 2) or wha[0]
        wha[1] = wha[1] * (a % 2) or min(x, wha[1])
        if wha[0] >= wha[1]:
            print(0)
            return
    print(max(0, (wh[0][1] - wh[0][0]) * (wh[1][1] - wh[1][0])))
    return

#C
def C():
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    B()

Submission status: Accepted

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

if x1 > x0 and y1 > y0:
	print((x1 - x0) * (y1 - y0))
else:
	print(0)

Submission status: Accepted

Solution code:
a, b, c = map(int, input().split())
maxX = a
maxY = b
minX = minY = 0
for i in range(c):
    x, y, z = map(int, input().split())
    if z == 1:
        minX = max(minX, x)
    elif z == 2:
        maxX = min(maxX, x)
    elif z == 3:
        minY = max(minY, y)
    elif z == 4:
        maxY = min(maxY, y)
if minX >= maxX or minY >= maxY:
    print(0)
else:
    print(abs(minX - maxX) * abs(minY - maxY))

Submission status: Accepted

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

a,b=0,0
for i in range(n):
    if l[i][2]==1:a=max(a,l[i][0])
    elif l[i][2]==2:w=min(w,l[i][0])
    elif l[i][2]==3:b=max(b,l[i][1])
    else:h=min(h,l[i][1])

print(max(0,w-a)*max(0,h-b))

Submission status: Accepted

Solution code:
x, y, n = map(int, input().split())
input = [list(map(int, input().split())) for _ in range(n)] 
xmax = x
xmin = 0
ymax = y
ymin = 0
for i in input:
    type = i[2]
    if type == 1 and (i[0] > xmin):
        xmin = i[0]
    elif type == 2 and (i[0] < xmax):
        xmax = i[0]
    elif type == 3 and (i[1] > ymin):
        ymin = i[1]
    elif type == 4 and (i[1] < ymax):
        ymax = i[1]
if (xmax > xmin) and (ymax > ymin):
    print((xmax - xmin)*(ymax - ymin))
else:
    print(0)

Submission status: Accepted

Solution code:
from operator import itemgetter

w, h, n = map(int, input().split())
binary = [[0 for _ in range(h)] for i in range(w)]

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

total = 0
for i in range(len(binary)):
    total += binary[i].count(0) 
print(total)

Submission status: Accepted

Solution code:
maxX, maxY, a = map(int, input().split())
minX = 0
minY = 0
for i in range(a):
    x, y, b = map(int, input().split())
    if b == 1:
        minX = max(x, minX)
    elif b == 2:
        maxX = min(x, maxX)
    elif b == 3:
        minY = max(y, minY)
    elif b == 4:
        maxY = min(y, maxY)
if maxX > minX and maxY > minY:
    print((maxX - minX)*(maxY - minY))
else:
    print(0)

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
s=[[1]*w for i in range(h)]
#for i in range(w):
#    for j in range(h):
#        s[i][j]=1
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        for j in range(x):
            for k in range(h):
                s[k][j]=0
                #print(j,k,'jk')
    elif a==2:
        for j in range(x,w):
            for k in range(h):
                s[k][j]=0        
    elif a==3:
        for j in range(w):
            for k in range(y):
                s[k][j]=0  
    elif a==4:
        for j in range(w):
            for k in range(y,h):
                s[k][j]=0  
    #print(s,x,y,a)
ss=[]
for i in s:
    ss.extend(i)
#print(ss)
print(ss.count(1))

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
ws, we, hs, he = 0, W, 0, H
for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        ws = max(ws, x)
    elif a == 2:
        we = min(we, x)
    elif a == 3:
        hs = max(hs, y)
    elif a == 4:
        he = min(he, y)
if we >= ws and he >= hs:
    res = (we - ws)*(he - hs)
else:
    res = 0
print(res)

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
x_1=[0]
x_2=[w]
y_1=[0]
y_2=[h]

for _ in range(n):
    tmp_x,tmp_y,tmp_a=map(int,input().split())
    if tmp_a==1:
        x_1.append(tmp_x)
    elif tmp_a==2:
        x_2.append(tmp_x)
    elif tmp_a==3:
        y_1.append(tmp_y)
    elif tmp_a==4:    
        y_2.append(tmp_y)
        
ans=max(0,(min(x_2)-max(x_1)))*max(0,(min(y_2)-max(y_1)))

print(ans)