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())
xya=[list(map(int,input().split())) for i in range(n)]

My=h
Mx=w
my=0
mx=0
for x,y,a in xya:
    if a==1 and mx<x:mx=x
    if a==2 and Mx>x:Mx=x
    if a==3 and my<y:my=y
    if a==4 and My>y:My=y

if Mx-mx<=0 or My-my<=0:print(0)
else:print((Mx-mx)*(My-my))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
#corner決定
left = 0
under =0
right = W
upper = H

for _ in range(N):
    x,y,a = map(int,input().split())
    if a ==1:
        left = max(x,left)
    elif a ==2:
        right =min(x,right)
    elif a == 3:
        under = max(y,under)
    elif a == 4:
        upper = min(y,upper)
#面積決定
if (right-left)>0 and (upper-under)>0:
    S = (right-left)*(upper-under)
    print(S)
else:
    print(0)

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
zahyo = [list(map(int, input().split())) for i in range(N)]
area = [[0 for i in range(H)] for j in range(W)]
for i in range(N):
    if zahyo[i][2] == 1:
        for j in range(zahyo[i][0]):
            for k in range(H):
                area[j][k] = 1
                
    elif zahyo[i][2] == 2:
        for j in range(zahyo[i][0], W):
            for k in range(H):
                area[j][k] = 1
                
    elif zahyo[i][2] == 3:
        for j in range(W):
            for k in range(zahyo[i][1]):
                area[j][k] = 1
                
    elif zahyo[i][2] == 4:
        for j in range(W):
            for k in range(zahyo[i][1], H):
                area[j][k] = 1

cnt = 0
for l in area:
    for m in range(H):
        if l[m] == 0:
            cnt += 1
print(cnt)

Submission status: Accepted

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

point_list = [input().split() for i in range(n)]

area = [[1]*w for i in range(h)]


for point in point_list:

    if point[2] == "1":
        for i in range(h):
            for j in range(int(point[0])):
                area[i][j] = 0
    elif point[2] == "2":
        for i in range(h):
            for j in range(int(point[0]), w):
                area[i][j] = 0
    elif point[2] == "3":
        for i in range(int(point[1])):
            for j in range(w):
                area[i][j] = 0
    elif point[2] == "4":
        for i in range(int(point[1]), h):
            for j in range(w):
                area[i][j] = 0

print(sum([sum(i) for i in area]))

Submission status: Accepted

Solution code:
#ABC047.B

w,h,n = map(int,input().split())
#座標を作る
right = w
left = 0
upper = h
under = 0

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

    if a ==1:
        left = max(x,left)
    elif a ==2:
        right = min(x,right)
    elif a ==3:
        under = max(y,under)
    else:
        upper = min(y,upper)

if(upper-under)>0 and (right-left)>0:
    c = (upper-under)*(right-left)
    print(c)
else:
    print(0)

Submission status: Accepted

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

xl = 0
xr = W
yt = H
yb = 0

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:
        yb = max(y,yb)    

    else :
        yt = min(y, yt)

# print(xr)
# print(xl)
# print(yt)
# print(yb)

ans = (xr - xl) * (yt - yb)
if ans <= 0 or ((xr - xl < 0 )or (yt - yb < 0)):
    ans = 0

print(ans)

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
rec=[[0,0],[W,H]]

for i in range(N):
    x,y,a=map(int,input().split())
    if a==1:
        rec[0][0]=max(rec[0][0],x)
    elif a==2:
        rec[1][0]=min(rec[1][0],x)
    elif a==3:
        rec[0][1]=max(rec[0][1],y)
    elif a==4:
        rec[1][1]=min(rec[1][1],y)

if (rec[1][0]-rec[0][0]) >=0 and (rec[1][1]-rec[0][1])>=0:
    ans=(rec[1][0]-rec[0][0])*(rec[1][1]-rec[0][1])
else:
    ans=-1
print(ans if ans>=0 else 0)

Submission status: Accepted

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

a1 = []
a2 = []
a3 = []
a4 = []

for i in range(n):
    # x,y,a = 2,1,1
    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)
    elif a == 4:
        a4.append(y)

if len(a1) == 0:
    aa1 = 0
else:
    aa1 = max(a1)

if len(a2) == 0:
    aa2 = 0
else:
    aa2 = min(a2)

if len(a3) == 0:
    aa3 = 0
else:
    aa3 = max(a3)

if len(a4) == 0:
    aa4 = 0
else:
    aa4 = min(a4)

rx = 0
if aa2 != 0:
    rx = w - aa2

ty = 0
if aa4 != 0:
    ty = h - aa4
s = (w - aa1 - rx) * (h - aa3 - ty)

if s >= 0:
    print(s)
else:
    print(0)

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
nums_list=[list(map(int, input().split())) for i in range(n)]
minX = 0
maxX = w
minY = 0
maxY = h
for nums in nums_list:
	x, y, a = map(int, nums)
	if a == 1:
		minX = minX if (minX > x) else x
	elif a == 2:
		maxX = maxX if (maxX < x) else x
	elif a == 3:
		minY = minY if (minY > y) else y
	else:
		maxY = maxY if (maxY < y) else y
width = maxX-minX
width = width if (width > 0) else 0
height = maxY-minY
height = height if (height > 0) else 0
v = width*height
print(v)

Submission status: Accepted

Solution code:
import sys

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

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

area = [[0 for i in range(h)] for j in range(w)]

for i in range(n):
    if zahyo[i][2] == 1:
        for j in range(zahyo[i][0]):
            for k in range(len(area[j])):
                area[j][k] = 1
    elif zahyo[i][2] == 2:
        for j in range(w - 1, zahyo[i][0] - 1, -1):
            for k in range(len(area[j])):
                area[j][k] = 1
    elif zahyo[i][2] == 3:
        for j in range(len(area)):
            for k in range(zahyo[i][1]):
                area[j][k] = 1
    elif zahyo[i][2] == 4:
        for j in range(len(area)):
            for k in range(h - 1, zahyo[i][1] - 1, -1):
                area[j][k] = 1

cnt_zero = 0
for i in range(len(area)):
    for j in range(len(area[i])):
        if area[i][j] == 0:
            cnt_zero += 1

print("{}".format(cnt_zero))

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
Mx = w ; My = h
mx = 0 ; my = 0

for i in range(n):
    x,y,a = map(int,input().split())
    
    if a == 1:
        mx = max(mx,x)
    elif a == 2:
        Mx = min(Mx,x)
    elif a == 3:
        my = max(my,y)
    else:
        My = min(My,y)
        
s = (Mx - mx)*(My - my)
print(s if mx < Mx and my < My else 0)

Submission status: Accepted

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

xr = w
xl = 0
yu = h
yl = 0

for i in range(n):
    if T[i][2] == 2:
        xr = min(xr, T[i][0])
    elif T[i][2] == 1:
        xl = max(xl, T[i][0])
    elif T[i][2] == 4:
        yu = min(yu, T[i][1])
    else:
        yl = max(yl, T[i][1])

if (xr - xl) <= 0 or (yu - yl) <= 0:
    print(0)
else:
    print((xr - xl) * (yu - yl))

Submission status: Accepted

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

left = 0
right = w
under = 0
upper = h

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

    if a==1:
        left = max(x, left)
    elif a==2:
        right = min(x, right)
    elif a==3:
        under = max(y, under)
    else:
        upper = min(y, upper)

if (upper-under)>0 and (right-left)>0:
    ans = (upper-under)*(right-left)
    print(ans)
else:
    print(0)

Submission status: Accepted

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    W,H,N=MI()
    L=[0,W,0,H]
    for _ in range(N):
        x,y,a=MI()
        a-=1
        if a==0:
            L[a]=max(L[a],x)
        elif a==1:
            L[a]=min(L[a],x)
        elif a==2:
            L[a]=max(L[a],y)
        else:
            L[a]=min(L[a],y)
            
            
    dx=L[1]-L[0]
    dy=L[3]-L[2]
    
    if dx>0 and dy>0:
        print(dx*dy)
    else:
        print(0)
            

main()

Submission status: Accepted

Solution code:
#abc047 b
w,h,n=map(int,input().split())
zahyo=[]
a=[]
for i in range(n):
    x,y,z=map(int,input().split())
    zahyo.append([x,y])
    a.append(z)
l=[0,0]
r=[w,h]

def white(i):
    if a[i]==1:
        if l[0]<zahyo[i][0]:
            l[0]=zahyo[i][0]
    elif a[i]==2:
        if r[0]>zahyo[i][0]:
            r[0]=zahyo[i][0]
    elif a[i]==3:
        if l[1]<zahyo[i][1]:
            l[1]=zahyo[i][1]
    else:
        if r[1]>zahyo[i][1]:
            r[1]=zahyo[i][1]
#塗りつぶされてるときある

for i in range(n):
    white(i)

yoko=r[0]-l[0]
tate=r[1]-l[1]
ans=0
if yoko>=0 and tate>=0:# マイナスxマイナスを含めない
    ans=yoko*tate
print(ans)

Submission status: Accepted

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

c1 = [0, 0] # corner 1
c2 = [W, H] # corner 2

while(N):
    x, y, a = map(int, input().split())
    if a == 1:
        if c1[0] < x:
            c1[0] = x
    elif a == 2:
        if c2[0] > x:
            c2[0] = x
    elif a == 3:
        if c1[1] < y:
            c1[1] = y
    else:
        if c2[1] > y:
            c2[1] = y
            
    N = N - 1

if (c2[0] - c1[0]) >= 0 and (c2[1] - c1[1]) >= 0:
    S = (c2[0] - c1[0]) * (c2[1] - c1[1])
    print(S)
else:
    print(0)

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
P = [None for _ in range(N)]
a = [None for _ in range(N)]
for i in range(N):
  *P[i], a[i] = map(int, input().split())

ans = [[1] * W for _ in range(H)]
for i in range(N):
  if a[i] == 1:
    for j in range(H):
      for k in range(P[i][0]):
        ans[j][k] = 0
  elif a[i] == 2:
    for j in range(H):
      for k in range(P[i][0],W):
        ans[j][k] = 0
  elif a[i] == 3:
    for j in range(P[i][1]):
      for k in range(W):
        ans[j][k] = 0
  else:
    for j in range(P[i][1],H):
      for k in range(W):
        ans[j][k] = 0
  #print(P[i],i,ans)
print(sum(map(sum,ans)))

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
u, d = 0, h
l, r = 0, w

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:
        u = max(u, y)
    if a == 4:
        d = min(d, y)
print(max(0, (d-u)) * max(0, (r-l)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

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


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

    print((W-w)*(H-h) if (W-w)>=0 and (H-h)>=0 else 0)




resolve()

Submission status: Accepted

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

Op1 = [0]
Op2 = [w]
Op3 = [0]
Op4 = [h]
for j in range(n):
    if Op[j][2] == 1:
        Op1.append(Op[j][0])
    elif Op[j][2] == 2:
        Op2.append(Op[j][0])
    elif Op[j][2] == 3:
        Op3.append(Op[j][1])
    elif Op[j][2] == 4:
        Op4.append(Op[j][1])
'''
print(Op1)
print(Op2)
print(Op3)
print(Op4)
'''
if min(Op2)-max(Op1) < 0:
    print(0)
elif min(Op4)-max(Op3) < 0:
    print(0)
else:
    print((min(Op2)-max(Op1))*(min(Op4)-max(Op3)))

Submission status: Accepted

Solution code:
W, H, N = map(int,input().split())
B = [[0]*W for k in range(H)]
for _ in range(N):
    x, y, a = map(int,input().split())
    if a == 1:
        for k in range(x):
            for l in range(H):
                B[l][k] = 1
    elif a == 2:
        for k in range(x,W):
            for l in range(H):
                B[l][k] = 1
    elif a == 3:
        for k in range(W):
            for l in range(y):
                B[l][k] = 1
    else:
        for k in range(W):
            for l in range(y,H):
                B[l][k] = 1
ans = 0
for e in B:
    ans += e.count(0)
print(ans)

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
w=[0]*2
h=[0]*2
w[1]=W
h[1]=H
for _ in range(N):
    x,y,a,=map(int,input().split())
    if a==1:
        if w[0]<=x:
            w[0]=x
    if a==2:
        if w[1]>=x:
            w[1]=x
    if a==3:
        if h[0]<=y:
            h[0]=y
    if a==4:
        if h[1]>=y:
            h[1]=y
W=max((w[1]-w[0]),0)
H=max((h[1]-h[0]),0)
print(H*W)

Submission status: Accepted

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

A = [0]*4
for i in range(4):
  A[i] = []
for i in range(N):
  x,y,a = map(int, input().split())
  if a==1 or a==2:
  	A[a-1].append(x)
  else:
    A[a-1].append(y)

A[0] = max(A[0]) if len(A[0])!=0 else 0
A[1] = min(A[1]) if len(A[1])!=0 else W
A[2] = max(A[2]) if len(A[2])!=0 else 0
A[3] = min(A[3]) if len(A[3])!=0 else W
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())
x1=0
x2=W
y1=0
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(x,x2)
    elif a==3:
        y1=max(y1,y)
    elif a==4:
        y2=min(y,y2)
if x2<x1 or y2<y1:
    print(0)
    exit()
xx=x2-x1
yy=y2-y1
print(xx*yy)

Submission status: Accepted

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

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

lst1 = [0,w,0,h] #←x,x→,y↓,y↑
for i in range(n):
    x,y,a = map(int,readline().split())
    if a==1 or a==3: #max
        if a==1: #x
            lst1[a-1] = max(lst1[a-1],x)
        else: #y
            lst1[a-1] = max(lst1[a-1],y)
    
    else:
        if a==2: #x
            lst1[a-1] = min(lst1[a-1],x)
        else: #y
            lst1[a-1] = min(lst1[a-1],y)

class Square_area():
    """
    about:
    四角形の左縁からx1,右縁からx2迄,下縁からy1迄,上縁からy2迄,塗りつぶした時の、塗りつぶした面積を出力する。
    require:
    w,h,x1,x2,y1,y2
    w:幅
    h:高さ
    四角形の左下の座標を(0,0)とした時、
    x1:その左側を塗りつぶす
    x2:その右〃
    y1:その下〃
    y2:その上〃
    x1とx2の領域が重なる(x2<x1)の場合は、全て塗りつぶすという扱いになる。yについても同様。
    """
    def __init__(self,w,h,x1,x2,y1,y2): #塗りつぶさないなら:(x1=0,x2=w,y1=0,y2=h)
        self.w = w
        self.h = h
        self.area = w*h
        self.x1 = x1
        if x2 < x1:
            self.x2 = w-x1
        else:
            self.x2 = w-x2
        self.y1 = y1
        if y2 < y1:
            self.y2 = h-y1
        else:
            self.y2 = h-y2
        
        for i in [self.x1,self.x2]:
            if not 0 <= i <= w:
                raise Exception
        for i in [self.y1,self.y2]:
            if not 0 <= i <= h:
                raise Exception

    def get_outer(self): #指定した座標の外側の面積
        return (self.x1+self.x2)*self.h +(self.y1+self.y2)*self.w - self.dublication()

    def get_inner(self): #指定した座標の内側の面積
        return self.area - self.get_outer()

    def dublication(self): #重複部分の面積。x同士、y同士の重複はinitで処理してしまっているので注意
        return self.x1*(self.y1+self.y2)+self.x2*(self.y1+self.y2)

req = Square_area(w,h,lst1[0],lst1[1],lst1[2],lst1[3])

print(req.get_inner())

Submission status: Accepted

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

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

lst1 = [0,w,0,h] #←x,x→,y↓,y↑
for i in range(n):
    x,y,a = map(int,readline().split())
    if a==1 or a==3: #max
        if a==1: #x
            lst1[a-1] = max(lst1[a-1],x)
        else: #y
            lst1[a-1] = max(lst1[a-1],y)
    
    else:
        if a==2: #x
            lst1[a-1] = min(lst1[a-1],x)
        else: #y
            lst1[a-1] = min(lst1[a-1],y)

class Square_area():
    """
    about:
    四角形の縁からx,yだけ塗りつぶした時の、塗りつぶした面積を出力する。
    require:
    w,h,x1,x2,y1,y2
    w:幅
    h:高さ
    四角形の左下の座標を(0,0)とした時、
    x1:その左側を塗りつぶす
    x2:その右〃
    y1:その下〃
    y2:その上〃
    x1とx2の領域が重なる(x2<x1)の場合は、全て塗りつぶすという扱いになる。yについても同様。
    """
    def __init__(self,w,h,x1=0,x2=w,y1=0,y2=h):
        self.w = w
        self.h = h
        self.area = w*h
        self.x1 = x1
        if x2 < x1:
            self.x2 = w-x1
        else:
            self.x2 = w-x2
        self.y1 = y1
        if y2 < y1:
            self.y2 = h-y1
        else:
            self.y2 = h-y2
    
    def get_outer(self): #指定した座標の外側の面積
        return (self.x1+self.x2)*h +(self.y1+self.y2)*w - self.dublication()

    def get_inner(self): #指定した座標の内側の面積
        return self.area - self.get_outer()

    def dublication(self): #重複部分の面積。x同士、y同士の重複はinitで処理してしまっているので注意
        return self.x1*(self.y1+self.y2)+self.x2*(self.y1+self.y2)

req = Square_area(w,h,lst1[0],lst1[1],lst1[2],lst1[3])

print(req.get_inner())

Submission status: Accepted

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

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

lst1 = [0,w,0,h] #←x,x→,y↓,y↑
for i in range(n):
    x,y,a = map(int,readline().split())
    if a==1 or a==3: #max
        if a==1: #x
            lst1[a-1] = min(lst1[1],max(lst1[a-1],x))
        else: #y
            lst1[a-1] = min(lst1[3],max(lst1[a-1],y))
    
    else:
        if a==2: #x
            lst1[a-1] = max(lst1[0],min(lst1[a-1],x))
        else: #y
            lst1[a-1] = max(lst1[2],min(lst1[a-1],y))

print(w*h
    - lst1[0]*h
    - (w-lst1[1])*h
    - lst1[2]*w
    - (h-lst1[3])*w
    + lst1[0]*lst1[2]
    + lst1[0]*(h-lst1[3])
    + (w-lst1[1])*lst1[2]
    + (w-lst1[1])*(h-lst1[3])
     )

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
y0 = 0
y1 = h
x0 = 0
x1 = w
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)
    elif a==4:
        y1 = min(y1, y)
if (x1-x0>0) and (y1-y0>0):
    print((x1-x0)*(y1-y0))
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

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

def calcArea(M, H, N, plot_infos):
  pointA = [M, H]
  pointB = [0, 0]
  for i in range(N):
    plot_info = plot_infos[i]
    if plot_info[2] == 1:
      pointB[0] = max(plot_info[0], pointB[0])
    elif plot_info[2] == 2:
      pointA[0] = min(plot_info[0], pointA[0])
    elif plot_info[2] == 3:
      pointB[1] = max(plot_info[1], pointB[1])
    elif plot_info[2] == 4:
      pointA[1] = min(plot_info[1], pointA[1])
      
  if pointA[0] < pointB[0] or pointA[1] < pointB[1]:
      return 0
      
  return (pointA[0] - pointB[0]) * (pointA[1] - pointB[1])

print(calcArea(W, H, N, plot_infos))

Submission status: Accepted

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

if xl >= xh or yl >= yh:
    print(0)
else:
    print((xh-xl) * (yh-yl))

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())
b=[0]
c=[W]
d=[0]
e=[H]
for i in range(N):
    if a[i]==1:
        b.append(x[i])
    if a[i]==2:
        c.append(x[i])
    if a[i]==3:
        d.append(y[i])
    if a[i]==4:
        e.append(y[i])
w=min(c)-max(b)
h=min(e)-max(d)
if w<=0 or h<=0:
    print(int(0))
else:
    print(w*h)

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
grid = []
for i in range(N):
	array = list(map(int,input().split()))
	grid.append(array)
x1 = 0
xW = W
y1 = 0
yH = H
for i in grid:
	if i[2] == 1 and x1 < i[0]:
		x1 = i[0]
	elif i[2] == 2 and xW > i[0]:
		xW = i[0]
	elif i[2] == 3 and y1 < i[1]:
		y1 = i[1]
	elif i[2] == 4 and yH > i[1]:
		yH = i[1]
print(max(0,xW-x1)*max(0,yH-y1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
Q = [0,W,0,H]
for i in range(N):
    q = list(map(int, input().split()))
    if q[2]==1 and Q[0]<q[0]:
        Q[0]=q[0]
    elif q[2]==2 and Q[1]>q[0]:
        Q[1]=q[0]
    elif q[2]==3 and Q[2]<q[1]:
        Q[2]=q[1]
    elif q[2]==4 and Q[3]>q[1]:
        Q[3]=q[1]

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

Submission status: Accepted

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

x_l=0
x_h=W
y_l=0
y_h=H

for i in xya:
    if i[2]==1 and x_l<i[0]:
        x_l=i[0]
    elif i[2]==2 and x_h>i[0]:
        x_h=i[0]
    elif i[2]==3 and y_l<i[1]:
        y_l=i[1]
    elif i[2]==4 and y_h>i[1]:
        y_h=i[1]

print(max(0,x_h-x_l)*max(0,y_h-y_l))

Submission status: Accepted

Solution code:
W, H, N = map(int,input().split())
w = [1] * (W + 1)
h = [1] * (H + 1)
for _ in range(N):
    x, y, a = map(int,input().split())
    if a == 1:
        w[:x] = [0 for _ in range(x)]
    if a == 2:
        w[(x + 1):] = [0 for _ in range(W - x)]
    if a == 3:
        h[:y] = [0 for _ in range(y)]
    if a == 4:
        h[(y + 1):] = [0 for _ in range(H - y)]
if sum(w):
    A = sum(w) - 1
else:
    A = 0
if sum(h):
    B = sum(h) - 1
else:
    B = 0
print(A * B)

Submission status: Accepted

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

x,y=0,0
for s,t,u in a:
    if u==1:
        x=max(x,s)
    elif u==2:
        w=min(w,s)
    elif u==3:
        y=max(y,t)
    else:
        h=min(h,t)
height=max(0,h-y)
width=max(0,w-x)
print(height*width)

Submission status: Accepted

Solution code:
import numpy as np
w, h, n = map(int, input().split())
mat = [list(map(int, input().split())) for _ in range(n)]

arr = np.array([[1 for _ in range(w)] for _ in range(h)])

for x, y, a in mat:
    if a == 1:
        arr[:,:x] = 0
    elif a == 2:
        arr[:, x:] = 0
    elif a == 3:
        arr[-y:,:] = 0
    
    elif a == 4:
        arr[:-y,:] = 0

print(arr.sum())

Submission status: Accepted

Solution code:
import numpy as np

if __name__ == "__main__":
    w, h, n = map(int, input().split())
    mp = np.zeros((h, w))

    for i in range(n):
        tmp = list(map(int, input().split()))
        if tmp[2] == 1:
            mp[0:h, 0:tmp[0]] = 1
        elif tmp[2] == 2:
            mp[0:h, tmp[0]:w] = 1
        elif tmp[2] == 3:
            mp[0:tmp[1], 0:w] = 1
        else:
            mp[tmp[1]:h, 0:w] = 1

    print(w*h - np.count_nonzero(mp))

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
min_x,max_x=0,w
min_y,max_y=0,h
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)
    elif a==4:
        max_y=min(max_y,y)
if max_x-min_x<=0 or max_y-min_y<=0:
    print(0) 
else:
    ans=(max_x-min_x)*(max_y-min_y)
    print(max(ans,0))

Submission status: Accepted

Solution code:
#B - すぬけ君の塗り絵 2 イージー
W, H,N = map(int, input().split())
a = [input().split() for l in range(N)]
tmpx = W
tmpx1 = 0
tmpy = H
tmpy1 = 0
for i in range(N):
    if a[i][2] == "1":
        if tmpx1 < int(a[i][0]):
            tmpx1 = int(a[i][0])
        else:
            pass
    elif a[i][2] == "2" :
        if tmpx > int(a[i][0]):
            tmpx = int(a[i][0])
        else:
            pass
    elif a[i][2] == "3" :
        if tmpy1 < int(a[i][1]):
            tmpy1 = int(a[i][1])
    elif a[i][2] == "4" :
        if tmpy > int(a[i][1]):
            tmpy = int(a[i][1])
    else:
        print(0)
        exit()

if tmpx-tmpx1 <= 0 or tmpy - tmpy1 <=0:
    print(0)
else:
    print(abs(tmpx-tmpx1)*abs(tmpy-tmpy1))

Submission status: Accepted

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

fie = [[1]*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): fie[j][k] = 0
        if a==2:
                for j in range(x, w):
                        for k in range(h): fie[j][k] = 0
        if a==3:
                for j in range(w):
                        for k in range(y): fie[j][k] = 0
        if a==4:
                for j in range(w):
                        for k in range(y, h): fie[j][k] = 0
sm = 0
for i in range(w): sm += sum(fie[i])
print(sm)

Submission status: Accepted

Solution code:
##!/usr/bin/env python3
w,h,n = map(int,input().split())
hl = 0
hu = w
wl = 0
wu = h
for i in range(n):
  x,y,a = map(int,input().split())
  if a == 1: hl = max(x,hl)
  if a == 2: hu = min(x,hu)
  if a == 3: wl = max(y,wl)
  if a == 4: wu = min(y,wu)
#print(hl,hu,wl,wu)
print(max(0,(hu-hl))*max(0,wu-wl))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
w, h, n = map(int,input().split()) 
a = []
for i in range(n):
    a.append([int(i) for i in input().split()])

x_left = 0
x_right = w
y_lower = 0
y_upper = h
for i in range(n):
    if a[i][2] == 1:
        x_left = max(a[i][0], x_left)
    if a[i][2] == 2:
        x_right = min(a[i][0], x_right)
    if a[i][2] == 3:
        y_lower = max(a[i][1], y_lower)
    if a[i][2] == 4:
        y_upper = min(a[i][1], y_upper)
if y_lower >= y_upper or x_left >= x_right:
    print(0)
else:
    #print(y_upper)
    #print(y_upper - y_lower, x_right - x_left)
    print((y_upper - y_lower) * (x_right - x_left))

Submission status: Accepted

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

l,r,d,u = 0,W,0,H
for x,y,a in XYA:
    if a==1:
        l = max(l,x)
    elif a==2:
        r = min(r,x)
    elif a==3:
        d = max(d,y)
    else:
        u = min(u,y)
w = max(0,r-l)
h = max(0,u-d)
print(w*h)

Submission status: Accepted

Solution code:
W, H, N = map(int,input().split())
G = [[0]*W for k in range(H)]

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

ans = H*W
for k in range(H):
    for l in range(W):
        ans -= G[k][l]
print(ans)

Submission status: Accepted

Solution code:
def main():
    W, H, N = (int(i) for i in input().split())
    seen = [[True]*W for _ in range(H)]
    for i in range(N):
        X, Y, a = (int(i) for i in input().split())
        if a == 1:
            for h in range(H):
                for x in range(X):
                    seen[h][x] = False
        elif a == 2:
            for h in range(H):
                for x in range(X, W):
                    seen[h][x] = False
        elif a == 3:
            for w in range(W):
                for y in range(Y):
                    seen[y][w] = False
        else:
            for w in range(W):
                for y in range(Y, H):
                    seen[y][w] = False
    # print(*seen, sep="\n")
    ans = 0
    for h in range(H):
        for w in range(W):
            if seen[h][w]:
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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