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())
mans = [list(map(int,input().split())) for _ in range(n)]
X = [i for i in range(w + 1)]
Y = [i for i in range(h + 1)]
def flatten(nested_list):
  return [e for inner_list in nested_list for e in inner_list]
remove_X = []
remove_Y = []
for i in range(n):
  x = mans[i][0]
  y = mans[i][1]
  a = mans[i][2]
  if a == 1:
    remove_X.append(X[:x])
  elif a == 2:
    remove_X.append(X[x + 1:])
  elif a== 3:
    remove_Y.append(Y[:y])
  else:
    remove_Y.append(Y[y + 1:])
dis_X = set(flatten(remove_X))
dis_Y = set(flatten(remove_Y))
for x in dis_X:
  X.remove(x)
for y in dis_Y:
  Y.remove(y)
if len(X) == 0 or len(Y) == 0:
  print(0)
else:
  print((max(X) - min(X)) * (max(Y) - min(Y)))

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
a_1 = []
a_2 = []
a_3 = []
a_4 = []
for i in range(n):
  x,y,a = map(int,input().split())
  if a == 1:
    a_1.append(x)
  elif a == 2:
    a_2.append(x)
  elif a == 3:
    a_3.append(y)
  else:
    a_4.append(y)
    
left_black = max(a_1,default = 0)
right_black = min(a_2,default = w)
under_black = max(a_3,default = 0)
upper_black = min(a_4,default = h)

answer = (right_black - left_black)*(upper_black - under_black)
if left_black > right_black or under_black > upper_black:
  answer = 0
print(answer)

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
MAP=[[0 for i in range(W)] for j in range(H)]
command=[list(map(int,input().split())) for i in range(N)]
for x,y,a in command:
    if a==1:
        for i in range(H):
            for j in range(x):MAP[i][j]=1
    elif a==2:
        for i in range(H):
            for j in range(x,W):MAP[i][j]=1
    elif a==3:
        for i in range(y):
            for j in range(W):MAP[i][j]=1
    else:
        for i in range(y,H):
            for j in range(W):MAP[i][j]=1
cnt=0
for i in range(H):
    cnt +=MAP[i].count(0)
print(cnt)

Submission status: Accepted

Solution code:
import numpy as np
W,H,N=map(int,input().split())
MAP=[[0 for i in range(W)] for j in range(H)]
command=[list(map(int,input().split())) for i in range(N)]
for x,y,a in command:
    if a==1:
        for i in range(H):
            for j in range(x):
                MAP[i][j]=1
    elif a==2:
        for i in range(H):
            for j in range(x,W):
                MAP[i][j]=1
    elif a==3:
        for i in range(y):
            for j in range(W):
                MAP[i][j]=1
    else:
        for i in range(y,H):
            for j in range(W):
                MAP[i][j]=1
#print(np.array(MAP))
cnt=0
for i in range(H):
    cnt +=MAP[i].count(0)
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

top = H
bottom = 0
left = 0
right = W
for x, y, a in xya:
    if a == 1:
        left = max(left, x)
    elif a == 2:
        right = min(right, x)
    elif a == 3:
        bottom = max(bottom, y)
    elif a == 4:
        top = min(top, y)

if right-left < 0 or top-bottom < 0:
    print(0)
else:
    print((right-left)*(top-bottom))

Submission status: Accepted

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

for i in range(h):
    for j in range(w):
        ans+=g[i][j]

print(ans)

Submission status: Accepted

Solution code:



def main()->None:
    W, H, N = map(int, input().split())
    range_N = range(N)
    xl, xr, yd, yu = 0, W, 0, H
    for i in range_N:
        x, y, a = map(int, input().split())
        if a == 1:
            xl = max(x, xl)
        elif a == 2:
            xr = min(x, xr)
        elif a == 3:
            yd = max(y, yd)
        else:
            yu = min(y, yu)
    if xl >= xr or yd >= yu:
        print(0)
    else:
        print((xr - xl) * (yu - yd))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

max_x = w
max_y = h
min_x = 0
min_y = 0

for i in list_state:
    if i[2] == 1 and min_x < i[0]:
        min_x = i[0]
    if i[2] == 2 and max_x > i[0]:
        max_x = i[0]
    if i[2] == 3 and min_y < i[1]:
        min_y = i[1]
    if i[2] == 4 and max_y > i[1]:
        max_y = i[1]

x = max_x - min_x
y = max_y - min_y

if x > 0 and y > 0:
    print(x*y)
else:
    print(0)

Submission status: Accepted

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

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

max_x = w
max_y = h
min_x = 0
min_y = 0

for i in list_state:
    if i[2] == 1 and min_x < i[0]:
        min_x = i[0]
    if i[2] == 2 and max_x > i[0]:
        max_x = i[0]
    if i[2] == 3 and min_y < i[1]:
        min_y = i[1]
    if i[2] == 4 and max_y > i[1]:
        max_y = i[1]

x = max_x - min_x
y = max_y - min_y

if x < 0 or y < 0:
    print(0)
else:
    print(x*y)

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
x1 = y1 = 0
x2 = W
y2 = H
for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        x1 = max(x1, x)
    elif a == 2:
        x2 = min(x2, x)
    elif a == 3:
        y1 = max(y1, y)
    else:
        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())
xya = [list(map(int,input().split())) for _ in range(N)]

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

for i in range(N):
    a = xya[i][2]

    if a == 1:
        x1 = max(x1,xya[i][0])
    elif a == 2:
        x2 = min(x2,xya[i][0])
    elif a == 3:
        y1 = max(y1,xya[i][1])
    elif a == 4:
        y2 = min(y2,xya[i][1])

x = x2 - x1
y = y2 - y1

if x > 0 and y > 0:
    print((x2-x1) * (y2-y1))
else:
    print(0)

Submission status: Accepted

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

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

for i in range(N):
    a = xya[i][2]

    if a == 1:
        x1 = max(x1, xya[i][0])
    elif a == 2:
        x2 = min(x2, xya[i][0])
    elif a == 3:
        y1 = max(y1, xya[i][1])
    else:
        y2 = min(y2, xya[i][1])
x = x2-x1
y = y2-y1

if x > 0 and y > 0:
    print((x2-x1) * (y2-y1))
else:
    print(0)

Submission status: Accepted

Solution code:
w, h, n = (int(x) for x in input().split())

squre_1 = 0
squre_2 = w
squre_3 = 0
squre_4 = h

for i in range(n):
    x, y, a = (int(x) for x in input().split())
    if a == 1 and squre_1 <= x:
        squre_1 = x
    elif a == 2 and squre_2 >= x:
        squre_2 = x
    elif a == 3 and squre_3 <= y:
        squre_3 = y
    elif a == 4 and squre_4 >= y:
        squre_4 = y

if squre_2 > squre_1 and squre_4 > squre_3:
    ans = (squre_2 - squre_1) * (squre_4 - squre_3)
    print(ans)
else:
    print('0')

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:
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))

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

l = [0,0]
r = [w,h]

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

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

if (r[0]-l[0]) <= 0 or (r[1]-l[1])<=0:
    print(0)
else:
    print((r[0]-l[0])*(r[1]-l[1]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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


d = []
for _ in range(n):
  a = [int(i) for i in input().split()]
  d.append(a)
  
#print(w, h)
  
x1 = [0]
x2 = [w]
y1 = [0]
y2 = [h]

for i in range(n):
  if d[i][2] == 1:
    x1.append(d[i][0])
  if d[i][2] == 2:
    x2.append(d[i][0])
  if d[i][2] == 3:
    y1.append(d[i][1])
  if d[i][2] == 4:
    y2.append(d[i][1])
#print(x1, x2, y1, y2)
x1 = sorted(x1, reverse = True)[0]
x2 = sorted(x2)[0]
y1 = sorted(y1, reverse = True)[0]
y2 = sorted(y2)[0]

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import numpy as np

def solve(W: int, H: int, N: int, x: "List[int]", y: "List[int]", a: "List[int]"):
    grid = np.zeros((H,W))
    for i in range(N):
        if a[i] == 1:
            grid[:,:x[i]] = 1
        elif a[i] == 2:
            grid[:,x[i]:] = 1
        elif a[i] == 3:
            grid[:y[i],:] = 1
        elif a[i] == 4:
            grid[y[i]:,:] = 1
    print(np.count_nonzero(grid==0))
    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 = map(int, input().split())

bottom_left = [0, 0]
top_right = [W, H]

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

if top_right[0] > bottom_left[0] and top_right[1] > bottom_left[1]:
    area = (top_right[0] - bottom_left[0]) * (top_right[1] - bottom_left[1])
else:
    area = 0

print(area)

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
xl, xr, yd, yu = 0, w, 0, h
for _ in range(n):
  x, y, a = map(int, input().split())
  if a == 1:
    xl = max(x, xl)
  elif a == 2:
    xr = min(x, xr)
  elif a == 3:
    yd = max(y, yd)
  else:
    yu = min(y, yu)
if xl >= xr or yd >= yu:
  print(0)
else:
  print((xr-xl) * (yu-yd))

Submission status: Accepted

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

xl1 =[0]
xl2 =[w]
yl3 =[0]
yl4 =[h]
for i in range(n):
    if xya[i][2]==1:
        xl1.append(xya[i][0])
    elif xya[i][2]==2:
        xl2.append(xya[i][0])
    elif xya[i][2]==3:
        yl3.append(xya[i][1])
    elif xya[i][2]==4:
        yl4.append(xya[i][1])
s1=min(xl2)-max(xl1)
s2=min(yl4)-max(yl3)

if s1>0 and s2>0:
    s = s1*s2
    print(s)
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin

w,h,n = [int(x) for x in stdin.readline().rstrip().split()]
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]

mix = 0
miy = 0
mx = w
my = h

for i in li:
    if i[2] == 1:
        mix = max(mix,i[0])
    elif i[2] == 2:
        mx = min(mx,i[0])
    elif i[2] == 3:
        miy = max(miy,i[1])
    else:
        my = min(my,i[1])

if mix >= mx or miy >= my:
    print(0)
else:
    print((mx-mix)*(my-miy))

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        w0 = max(x, w0)
    elif a == 2:
        w = min(x, w)
    elif a == 3:
        h0 = max(y, h0)
    elif a == 4:
        h = min(y, h)

w = max(0, w - w0)
h = max(0, h - h0)

print(w * h)

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

W, H, N = rl()
x_left = 0
x_right = W
y_down = 0
y_up = H

for _ in range(N):
    x, y, a = rl()
    if a == 1:
        x_left = max(x_left, x)
    elif a == 2:
        x_right = min(x_right, x)
    elif a == 3:
        y_down = max(y_down, y)
    else:
        y_up = min(y_up, y)

if x_left < x_right and y_up > y_down:
    answer = (x_right - x_left) * (y_up - y_down)
else:
    answer = 0

print(answer)

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
maxX=W
maxY=H
minX=0
minY=0

for i in range(N):
  x,y,a=map(int,input().split())
  if a==1:
    minX=max(minX,x)
  elif a==2:
    maxX=min(maxX,x)
  elif a==3:
    minY=max(minY,y)
  else:
    maxY=min(maxY,y)

print(max(maxX-minX,0)*max(maxY-minY,0))

Submission status: Accepted

Solution code:
width,height,n = map(int,input().split())
lst =[]
lost_x_left =0
lost_x_right =0
lost_y_up =0
lost_y_down =0
for i in range(n):
    lst.append(list(map(int, input().split())))
for i in range(n):
    if(lst[i][2] == 1):
        if(lst[i][0] > lost_x_left):
            lost_x_left = lst[i][0]
    elif(lst[i][2] == 2):
        a = width - lst[i][0]
        if(a > lost_x_right):
            lost_x_right = a
    elif(lst[i][2] == 4):
        b = height - lst[i][1]
        if(b> lost_y_up):
            lost_y_up = b
    else:
        if(lst[i][1]> lost_y_down):
            lost_y_down = lst[i][1]
if ((lost_x_left + lost_x_right >= width) or (lost_y_up + lost_y_down >= height)):
    ans =0
else:
    ans = (width-(lost_x_left+lost_x_right)) * (height-(lost_y_up+lost_y_down))


print(ans)

Submission status: Accepted

Solution code:
import numpy as np
w,h,n = map(int, input().split())
d = np.array([[1]*w for _ in range(h)], dtype=int)
for _ in range(n):
  x,y,a = map(int, input().split())
  for i in range(w):
    for j in range(h):
      if a==1 and i<x:
        d[j][i] = 0
      elif a==2 and x<=i:
        d[j][i] = 0
      elif a==3 and j<y:
        d[j][i] = 0
      elif a==4 and y<=j:
        d[j][i] = 0
  #print(d)
print(sum(sum(x) for x in d))

Submission status: Accepted

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

Submission status: Accepted

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

xl, xr = 0, W
yl, yh = 0, H

for i in range(N):
    xi, yi, ai = map(int, input().split())

    if ai == 1:
        xl = max(xi, xl)
    elif ai == 2:
        xr = min(xi, xr)
    elif ai == 3:
        yl = max(yi, yl)
    else:
        yh = min(yi, yh)

if xr - xl > 0 and yh - yl > 0:
    ans = (xr - xl) * (yh - yl)
else:
    ans = 0

print(ans)

Submission status: Accepted

Solution code:
W,H,N = map(int, input().split())
data = [0,W,0,H]
for i in range(0,N):
    xi,yi,ai = map(int, input().split())
    if ai == 1:
        data[0] = max([data[0],xi])
    elif ai == 2:
        data[1] = min([data[1],xi])
    elif ai == 3:
        data[2] = max([data[2],yi])
    else:
        data[3] = min([data[3],yi])

ans = (data[1]-data[0])*(data[3]-data[2])
if data[1]-data[0]<0 or data[3]-data[2]<0: ans = 0
print(ans)

Submission status: Accepted

Solution code:
w,h,n=[int(j) for j in input().split()]
xl,xr=0,w
yl,yr=0,h
for i in range(n):
    x,y,a=[int(j) for j in 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 (xr-xl)>=0 and (yr-yl)>=0:
    ans=(xr-xl)*(yr-yl)
else:
    ans=0
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

W,H,N=list(map(int,input().split(" ")))
D=np.full((H,W),"w",np.str) # 長方形

# 各点について、黒色に塗りつぶしてゆく
for _ in range(N):
    x,y,a=list(map(int,input().split(" ")))
    
    if a==1: # x未満の領域 
        D[:,:x]="b"
    elif a==2: # xより大きい領域
        D[:,x:]="b"
    elif a==3: # y未満の領域
        D[:y,:]="b"
    elif a==4: # yより大きい領域
        D[y:,:]="b"

print(np.sum(D=="w"))

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    W,H,N = MI()
    bottom = 0
    top = H
    left = 0
    right = W
    for i in range(N):
        a,b,c = MI()
        if c==1:
            left = max(left,a)
        if c==2:
            right = min(right,a)
        if c==3:
            bottom = max(bottom, b)
        if c==4:
            top = min(top, b)
    if left <= right and bottom <= top:
        print((right-left)*(top-bottom))
    else:
        print(0)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
from string import ascii_lowercase
 
line = input()
w, h, n = [int(x) for x in line.split()]
xl = 0
xr = w
yl = 0
yr = h
for i in range(n):
	line = input()
	x, y, t = [int(x) for x in line.split()]
	if (t == 1):
		xl = max(xl, x)
	elif (t == 2):
		xr = min(xr, x)
	elif (t == 3):
		yl = max(yl, y)
	else:
		yr = min(yr, y)
	
print(max(xr - xl, 0) * max(yr - yl, 0))

Submission status: Accepted

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

w0 = 0
h0 = 0
for i in range(n):
    if xya[i][2] == 1:
        w0 = max(w0,xya[i][0])
    elif xya[i][2] == 2:
        w = min(w,xya[i][0])
    elif xya[i][2] == 3:
        h0 = max(h0,xya[i][1])
    else:
        h = min(h,xya[i][1])
        
print(max(0, (w-w0)) * max(0, (h-h0)))

Submission status: Accepted

Solution code:
w,h,n = map(int, input().split())
xya = [list(map(int, input().split())) for i in range(n)]
lx = 0
rx = w
ly = 0
ry = h
for x,y,a in xya:
  if a == 1:
    lx = max(lx,x)
  elif a == 2:
    rx = min(rx,x)
  elif a == 3:
    ly = max(ly,y)
  else:
    ry = min(ry,y)
ans = max(0,rx-lx) * max(0,ry-ly)
print(ans)

Submission status: Accepted

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

for i in range(n):
	x,y,a = map(int,input().split())
	if a == 1:
		W = [0]*x+W[x:]
	elif a == 2:
		W = W[:x]+[0]*(w-x)
	elif a == 3:
		H = [0]*y+H[y:]
	else:
		H = H[:y]+[0]*(h-y)
	# print(W)
	# print(H)
print(sum(W)*sum(H))

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
area = [[1] * W for i in range(H)]
for n in range(N):
  x, y, a = map(int, input().split())
  for i in range(len(area)):
      for j in range(len(area[i])):
        if a == 1 and j <= x - 1:
          area[i][j] = 0
        elif a == 2 and j > x - 1:
          area[i][j] = 0
        elif a == 3 and i <= y - 1:
          area[i][j] = 0
        elif a == 4 and i > y - 1:
          area[i][j] = 0
# print(area)
answer = 0
for row in area:
  answer += sum(row)
print(answer)

Submission status: Accepted

Solution code:
#テストファイルで実行する時
import sys
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')


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

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

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


for i in range(n):
	if   l[i][2] == 1:
		if minx < l[i][0]:
			minx = l[i][0]

	elif l[i][2] == 2:
		if maxx > l[i][0]:
			maxx = l[i][0]
	
	elif l[i][2] == 3:
		if miny < l[i][1]:
			miny = l[i][1]	
	
	elif l[i][2] == 4:
		if maxy > l[i][1]:
			maxy = l[i][1]
			
ans = (maxx-minx)*(maxy-miny)		

if (maxx-minx)<0:
	ans = 0
elif (maxy-miny)<0:
	ans = 0
			
print(ans)

Submission status: Accepted

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

L = np.array([[0 for _ in range(W)] for _ in range(H)])
#print(L)

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

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

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

def g(a, x1, x2, y1, y2):
    for i in range(x1,x2):
        for j in range(y1,y2):
            a[i][j] = 0
    return a
            
        
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        NN = g(NN,0,x,0,h)
    elif a == 2:
        NN = g(NN,x,w,0,h)
    elif a == 3:
        NN = g(NN,0,w,0,y)
    elif a == 4:
         NN = g(NN,0,w,y,h)

np.array(NN)
print(np.sum(NN))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

wr,ht,n=map(int,input().split())
wl=0;hd=0
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        wl=max(wl,x)
    elif a==2:
        wr=min(wr,x)
    elif a==3:
        hd=max(hd,y)
    else:
        ht=min(ht,y)
print(max(0,wr-wl)*max(0,ht-hd))
# print(wr,wl,ht,hd)

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
maxX,minX,maxY,minY = W, 0, H ,0
for i in range(N):
    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
        
x1 = maxX - minX
y1 = maxY - minY
if x1 > 0 and y1 > 0:
    print(x1*y1)
else:
    print(0)

Submission status: Accepted

Solution code:
w, h, n = list(map(int, input().split()))
data1 = [0]
data2 = [w]
data3 = [0]
data4 = [h]
for i in range(n):
  x, y, a = list(map(int, input().split()))
  if a == 1:
    data1.append(x)
  elif a == 2:
    data2.append(x)
  elif a == 3:
    data3.append(y)
  else:
    data4.append(y)
data1.sort()
data2.sort()
data3.sort()
data4.sort()
x = (data2[0] - data1[-1])
y = (data4[0] - data3[-1])
if x < 0 or y < 0:
  print(0)
  exit()
print(x*y)

Submission status: Accepted

Solution code:
import numpy as np
N, M, K = map(int, input().split())
xy_board = np.ones((N, M))
for _ in range(K):
    x, y, a = map(int, input().split())
    if a == 1:
        xy_board[:x, :] = 0
    elif a == 2:
        xy_board[x:, :] = 0
    elif a == 3:
        xy_board[:, :y] = 0
    elif a == 4:
        xy_board[:, y:] = 0

# print(xy_board)
print(xy_board.sum())

Submission status: Accepted

Solution code:
from operator import itemgetter

#入力
W,H,N = [int(x)for x in input().split()]

xlow=0
ylow=0
xhigh=W
yhigh=H

for i in range(N):
    x,y,a=[int(x)for x in input().split()]
    if(a==1):
        if(xlow < x):
            xlow=x
    elif(a==2):
        if(xhigh > x):
            xhigh=x
    elif (a == 3):
        if (ylow < y):
            ylow = y
    elif (a == 4):
        if (yhigh > y):
            yhigh = y


#print(xhigh,xlow,yhigh,ylow)
if(xlow < xhigh and ylow<yhigh):
    print((xhigh - xlow)*(yhigh - ylow))
else:
    print(0)

Submission status: Accepted

Solution code:
w, h, n = list(map(int, input().split()))
data1 = [0]
data2 = [w]
data3 = [0]
data4 = [h]
for i in range(n):
    x, y, a = list(map(int, input().split()))
    if a == 1:
        data1.append(x)
    elif a == 2:
        data2.append(x)
    elif a == 3:
        data3.append(y)
    else:
        data4.append(y)
data1.sort()
data2.sort()
data3.sort()
data4.sort()
x = (data2[0] - data1[-1])
y = (data4[0] - data3[-1])
if x < 0 or y < 0:
    print(0)
    exit()
print(x*y)

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
xmin = 0
xmax = W
ymin = 0
ymax = H
for _ 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())
x=[0]*n
y=[0]*n
a=[0]*n
ans=0
a1=0
a2=w
a3=0
a4=h
for i in range(n):
    x[i],y[i],a[i]=map(int,input().split())
for i in range(n):
    if a[i]==1:
        a1=max(a1,x[i])
    elif a[i]==2:
        a2=min(a2,x[i])
    elif a[i]==3:
        a3=max(a3,y[i])
    else:
        a4=min(a4,y[i])
#print(a1,a2,a3,a4)
if a1>=a2 or a3>=a4:
    print(0)
else:
    print((a2-a1)*(a4-a3))

Submission status: Accepted

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

area = []
for i in range(H):
    area.append([])
    for j in range(W):
        area[i].append('o')

for value in A:
    if value[2] == 1:
        for i in range(H):
            for j in range(value[0]):
                area[i][j] = 'x'
    if value[2] == 2:
        for i in range(H):
            for j in range(value[0], W):
                area[i][j] = 'x'
    if value[2] == 3:
        for j in range(W):
            for i in range(value[1]):
                area[i][j] = 'x'
    if value[2] == 4:
        for j in range(W):
            for i in range(value[1], H):
                area[i][j] = 'x'

tmp = []
for i in range(H):
    for j in range(W):
        tmp.append(area[i][j])
print(tmp.count('o'))