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

x=[0]*n
y=[0]*n
a=[0]*n
white=[0,h,w,0]
for i in range(n):
    line = list(map(int, input().split()))
    x[i] = line[0]
    y[i] = line[1]
    a[i] = line[2]

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

newh = (white[1] - white[3])
neww = (white[2] - white[0])
print(newh * neww if newh >=0 and neww >=0 else 0)

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
lo = [0,0]
hi = [w,h]
for i in range(n):
    a,b,x = map(int,input().split())
    if x == 1:
        if a >= lo[0]:
            lo[0] = a
    if x == 2:
        if a <= hi[0]:
            hi[0] = a

    if x == 3:
        if b >= lo[1]:
            lo[1] = b

    if x == 4:
        if b <= hi[1]:
            hi[1] = b
if hi[0] >= lo[0] and hi[1] >= lo[1]:
    print( (hi[0] - lo[0])*(hi[1] - lo[1]) )
else:
    print(0)

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
lx, dy, rx, uy = 0, 0, W, H #最後に残る白の長方形
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        if lx <= x:
            lx = x
    elif a == 2:
        if x <= rx:
            rx = x
    elif a == 3:
        if dy <= y:
            dy = y
    elif a == 4:
        if y <= uy:
            uy = y
if rx - lx <= 0 or uy - dy <= 0:
    print(0)
else:
    print((rx - lx) * (uy - dy))

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

W, H, N = MAP()
xya = [LIST() for _ in range(N)]

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

for x, y, a in xya:
	if a == 1 and left < x < right:
		left = x
	elif a == 1 and right <= x:
		S = 0
		break
	elif a == 2 and left < x < right:
		right = x
	elif a == 2 and x <= left:
		S = 0
		break
	elif a == 3 and bottom < y < top:
		bottom = y
	elif a == 3 and top <= y:
		S = 0
		break
	elif a == 4 and bottom < y < top:
		top = y
	elif a == 4 and y <= bottom:
		S = 0
		break
	else:
		pass
	# print(left, right, top, bottom)
	S = (right-left)*(top-bottom)
if S <= 0:
	S = 0
print(S)

Submission status: Accepted

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

x = 0
y = 0
a = 0
p1 = 0
p2 = W
p3 = 0
p4 = H
for i in range(N):
	x, y, a = map(int, input().split())

	if a==1:
		p1 = max(p1, x)
	elif a==2:
		p2 = min(p2, x)
	elif a==3:
		p3 = max(p3, y)
	elif a==4:
		p4 = min(p4, y)

if p1>=p2 or p3>=p4:
	print(0)
else:
	print((p2-p1)*(p4-p3))

Submission status: Accepted

Solution code:
def snuke_coloring2(W: int, H: int, N: int, queries: list) -> int:
    # 白い領域の上下左右の値。
    u, d, r, l = H, 0, W, 0

    for x, y, a in queries:
        if a == 1:
            l = max(l, x)
        elif a == 2:
            r = min(r, x)
        elif a == 3:
            d = max(d, y)
        else:  # a == 4
            u = min(u, y)

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


if __name__ == "__main__":
    N = 0
    W, H, N = map(int, input().split())
    queries = [tuple(int(s) for s in input().split()) for _ in range(N)]
    ans = snuke_coloring2(W, H, N, queries)
    print(ans)

Submission status: Accepted

Solution code:
w, h, n = map(int,input().split())
x1 = []
x2 = []
y3 = []
y4 = []
for i in range(n):
    x, y, a = map(int,input().split())
    if a == 1:
        x1.append(x)
    elif a == 2:
        x2.append(x)
    elif a == 3:
        y3.append(y)
    else:
        y4.append(y)

for t in [x1,y3]:
    if not t:
        t.append(0)
if not x2:
    x2.append(w)
if not y4:
    y4.append(h)

if max(x1) >= min(x2) or max(y3) >= min(y4):
    print(0)
    exit()
print((min(x2) - max(x1)) * (min(y4) - max(y3)))

Submission status: Accepted

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

x0, y0, x1, y1 = 0, 0, W, H
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        if x0 < x:
            x0 = x
    elif a == 2:
        if x < x1:
            x1 = x
    elif a == 3:
        if y0 < y:
            y0 = y
    else:
        if y < y1:
            y1 = y

if x1-x0<0 or y1-y0<0:
    print(0)
else:
    print((x1-x0)*(y1-y0))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import reduce

def main():
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10

    # 1文字のみを読み込み
    # s = input().rstrip()
    
    # スペース区切りで標準入力を配列として読み込み
    # s = input().rstrip().split(' ')

    # 1文字ずつ標準入力を文字列として読み込み
    # s = list(input().rstrip())
    
    # 1文字ずつ標準入力を数値配列として読み込み
    # X = [int(_) for _ in input().split()]
    s = input().rstrip().split(' ')
    W = int(s[0])
    W_S = 0
    H = int(s[1])
    H_S = 0
    N = int(s[2])
    x = []
    y = []
    a = []
    for i in range(N):
        s = input().rstrip().split(' ')
        x.append(int(s[0]))
        y.append(int(s[1]))
        a.append(int(s[2]))

    for i in range(N):
        if(a[i]==1 and x[i]>W_S ):
            W_S = x[i]
        elif(a[i]==2 and x[i]<W ):
            W = x[i]
        elif(a[i]==3 and y[i]>H_S ):
            H_S = y[i]
        elif(a[i]==4 and y[i]<H ):
            H = y[i]        
    if W-W_S <0 or H-H_S < 0:
        ans = 0
    else:
        ans = (W-W_S) * (H-H_S)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
x_a=0
x_b=w
y_a=0
y_b=h

for i in range(n):
  x,y,z=map(int,input().split())
  if(z==1):
    x_a=max(x_a,x)
  elif(z==2):
    x_b=min(x_b,x)
  elif(z==3):
    y_a=max(y_a,y)
  elif(z==4):
    y_b=min(y_b,y)

if(x_b-x_a>0 and y_b-y_a>0):
  print((x_b-x_a)*(y_b-y_a))
else:
  print(0)

Submission status: Accepted

Solution code:
p1=[0,0]
*p2,N=map(int,input().split())
for _ in range(N):
	x,y,a=map(int,input().split())
	if a==1 and p1[0] < x:
		p1[0]=x
	elif a==2 and p2[0] > x:
		p2[0]=x
	elif a==3 and p1[1] < y:
		p1[1]=y
	elif a==4 and p2[1] > y:
		p2[1]=y
else:
	print(max(0,p2[0]-p1[0])*max(0,p2[1]-p1[1]))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
x1 = y1 = a1 = 0
xmin = 0
xmax = W
ymin = 0
ymax = H
for _ in range(N):
  x2, y2, a2 = map(int, input().split())
  if (a2 == 1):
    xmin = max(x2, xmin)
  if (a2 == 2):
    xmax = min(x2, xmax)
  if (a2 == 3):
    ymin = max(y2, ymin)
  if (a2 == 4):
    ymax = min(y2, ymax)
  if (xmax<= xmin or ymax <= ymin):
    print(0)
    exit()
print((xmax - xmin) * (ymax - ymin))

Submission status: Accepted

Solution code:
import numpy as np

w,h,n = map(int, input().split())
mp = np.zeros((w,h))
for i in range(n):
    xi, yi, ai = map(int, input().split())
    if ai == 1:
        mp[:xi, :] = 1
    elif ai == 2:
        mp[xi:, :] = 1
    elif ai == 3:
        mp[:, :yi] = 1
    elif ai == 4:
        mp[:, yi:] = 1
print(w*h - np.sum(mp))

Submission status: Accepted

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

ld = [0,0]
ru = [W,H]

flag = True
for x,y,a in xya:
    if a == 1:
        if ld[0] < x: ld[0] = x
    if a == 2:
        if ru[0] > x: ru[0] = x
    if a == 3:
        if ld[1] < y: ld[1] = y
    if a == 4:
        if ru[1] > y: ru[1] = y
    tate = ru[1] - ld[1]
    yoko = ru[0] - ld[0]
    if tate <= 0 or yoko <= 0:
        flag = False
        break

if flag:
    print(tate*yoko)
else:
    print(0)

Submission status: Accepted

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

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
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    s = LI()
    if sum(s) ==  2*max(s):
        print("Yes")
    else:
        print("No")
    return

#B
def B():
    w,h,n = LI()
    l,r = 0,w
    d,u = 0,h
    for i in range(n):
        x,y,a = LI()
        if a == 1:
            l = max(x,l)
        elif a == 2:
            r = min(x,r)
        elif a == 3:
            d = max(y,d)
        else:
            u = min(y,u)
    print(max(r-l,0)*max(u-d,0))
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

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

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split(" "))
Lx = [1 for i in range(W)]
Ly = [1 for i in range(H)]
 
for i in range(N):
  xi,yi,ai = map(int,input().split(" "))
  if ai ==1:
    for j in range(xi):
      Lx[j] = 0
         
  if ai ==2:
    for j in range(xi,W):
      Lx[j] = 0
    
  if ai ==3:
    for j in range(yi):
      Ly[j] = 0
    
  if ai ==4:
    for j in range(yi,H):
      Ly[j] = 0
x = sum(Lx)
y = sum(Ly)
 
print(x*y)

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
limit = {'top': H, 'right': W, 'down': 0, 'left': 0}
for _ in range(N):
  x,y,a = map(int,input().split())
  if a == 1:
    if x > limit['left']:
      limit['left'] = x
  elif a == 2:
    if x < limit['right']:
      limit['right'] = x
  elif a == 3:
    if y > limit['down']:
      limit['down'] = y
  elif a == 4:
    if y < limit['top']:
      limit['top'] = y
height = limit['top'] - limit['down']
width = limit['right'] - limit['left']
if (height > 0) and (width > 0):
  print(height * width)
else:
  print(0)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
w,h,n=map(int, input().split());
x,y=0,0
for i in '1'*n:
	a,b,c=map(int, input().split())
	if c==1:x=max(x,a)
	elif c==2:w=min(w,a)
	elif c==3:y=max(y,b)
	else: h=min(h,b)
print((max(w-x,0))*(max(h-y,0)))

Submission status: Accepted

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

# 格子点の中間点 (n.5, m.5) について考える
ws = [False] * W
hs = [False] * H

for x, y, a in xyan:
    if a == 1:
        for i in range(0, x):
            ws[i] = True
    elif a == 2:
        for i in range(x, W):
            ws[i] = True
    elif a == 3:
        for i in range(0, y):
            hs[i] = True
    elif a == 4:
        for i in range(y, H):
            hs[i] = True

print(len([w for w in ws if not w]) * len([h for h in hs if not h]))

Submission status: Accepted

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

sx = 0
sy = 0
ex = w
ey = h
for x,y,a in xya:
    if a == 1:
        sx = max(sx,x)
    if a == 2:
        ex = min(ex,x)
    if a == 3:
        sy = max(sy,y)
    if a == 4:
        ey = min(ey,y)

if ex-sx > 0 and ey-sy > 0:
    print((ex-sx)*(ey-sy))
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    W, H, N = map(int, input().split())
    white = [[1]*H for _ in range(W)]
    for _ in range(N):
        x, y, a = map(int, input().split())
        xr = range(W)
        yr = range(H)
        if a == 1:
            xr = range(x)
        elif a == 2:
            xr = range(x, W)
        elif a == 3:
            yr = range(y)
        else:
            yr = range(y, H)
        for i in xr:
            for j in yr:
                white[i][j] = 0
    print(sum([sum(x) for x in white]))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

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

for i in range(n):
    if p[i][2] == 1:
        if p[i][0] > max_x:
            max_x = p[i][0]
        
    if p[i][2] == 2:
        if p[i][0] < min_x:
            min_x = p[i][0]
    
    if p[i][2] == 3:
        if p[i][1] > max_y:
            max_y = p[i][1]
    
    if p[i][2] == 4:
        if p[i][1] < min_y:
            min_y = p[i][1]
        
        
if max_x > min_x:
    new_x = 0
else:
    new_x = min_x - max_x
    
if max_y > min_y:
    new_y = 0
else:
    new_y = min_y - max_y
    
print(new_x*new_y)

Submission status: Accepted

Solution code:
W,H,N=list(map(int,input().split()))
ten=[list(map(int,input().split())) for _ in range(N)]
base=[[0,0,1],[0,0,3],[W,H,2],[W,H,4]]
ten.extend(base)
onemax=max(i[0] for i in ten if i[2]==1)
twomin=min(i[0] for i in ten if i[2]==2)
thrmax=max(i[1] for i in ten if i[2]==3)
foumin=min(i[1] for i in ten if i[2]==4)
if (twomin-onemax)>0 and (foumin-thrmax) >0:
    print((twomin-onemax)*(foumin-thrmax))
else:print(0)

Submission status: Accepted

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

L, R = 0, W
D, T = 0, H

for i in range(N):
    x, y, a = list(map(int, input().split()))
    if a == 1:
        if L < x:
            L = x
    elif a == 2:
        if x < R:
            R = x
    elif a == 3:
        if D < y:
            D = y
    elif a == 4:
        if y < T:
            T = y

if (R - L) > 0 and (T - D) > 0:
    print((R - L) * (T - D))
elif (R - L) > 0 and (T - D) < 0:
    print((R - L))
elif (R - L) < 0 and (T - D) > 0 > 0:
    print(T - D)
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

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

ld = [0,0]
ru = [W,H]

flag = True
for x,y,a in xya:
    if a == 1:
        if ld[0] < x: ld[0] = x
    if a == 2:
        if ru[0] > x: ru[0] = x
    if a == 3:
        if ld[1] < y: ld[1] = y
    if a == 4:
        if ru[1] > y: ru[1] = y
    tate = ru[1] - ld[1]
    yoko = ru[0] - ld[0]
    if tate <= 0 or yoko <= 0:
        flag = False
        break

if flag:
    print(tate*yoko)
else:
    print(0)

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
x_a , x_b , y_c , y_d = 0 , W , 0 , H
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        x_a = max(x,x_a)
    elif a == 2:
        x_b = min(x,x_b)
    elif a == 3:
        y_c = max(y,y_c)
    else :
        y_d = min(y,y_d)
ans = max(x_b - x_a, 0) * max(y_d - y_c, 0)
print(ans)

Submission status: Accepted

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

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

for a in A:
    if a[2] == 1:
        for w in range(W):
            if w < a[0]:
                wdot[w] = 0
    elif a[2] == 2:
        for w in range(W):
            if w >= a[0]:
                wdot[w] = 0
    elif a[2] == 3:
        for h in range(H):
            if h < a[1]:
                hdot[h] = 0
    elif a[2] == 4:
        for h in range(H):
            if h >= a[1]:
                hdot[h] = 0

print(sum(hdot)*sum(wdot))

Submission status: Accepted

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

x1,x2,y1,y2=w,0,h,0

for i in range(n):
    if (s[i][2] == 1) and (x2 < s[i][0]):
        x2 = s[i][0]
    elif (s[i][2] == 2) and (x1 > s[i][0]):
        x1 = s[i][0]
    elif (s[i][2] == 3) and (y2 < s[i][1]):
        y2 = s[i][1]
    elif (s[i][2] == 4) and (y1 > s[i][1]):
        y1 = s[i][1]

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

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split(' '))
info = [[0],[W],[0],[H]] #min_x,max_x,min_y,max_y
for i in range(N):
  x,y,a=map(int,input().split(' '))
  info[a-1].append([x,y][(a-1)//2])
print(max(min(info[1])-max(info[0]),0)*max(min(info[3])-max(info[2]),0))

Submission status: Accepted

Solution code:
import numpy as np

W, H, N = map(int, input().split())
xlist = np.zeros(N,dtype=int)
ylist = np.zeros(N,dtype=int)
alist = np.zeros(N,dtype=int)
for i in range(N):
    xlist[i], ylist[i], alist[i] = map(int, input().split())
rectangular = np.zeros((H, W))
for i in range(N):
    if alist[i] == 1:
        rectangular[:,:xlist[i]] = 1
    if alist[i] == 2:
        rectangular[:,xlist[i]:] = 1
    if alist[i] == 3:
        rectangular[:ylist[i],:] = 1
    if alist[i] == 4:
        rectangular[ylist[i]:,:] = 1
print(sum(sum(rectangular < 1)))

Submission status: Accepted

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

_input = []
for i in range(N):
    _input.append(list(map(int,input().split())))

rec = [[0 for i in range(W)] for j in range(H)]

for x,y,a in _input:
    if a == 1:
        for i in range(H):
            for j in range(x):
                rec[i][j] = 1

    elif a == 2:
        for i in range(H):
            for j in range(x,W):
                rec[i][j] = 1

    elif a == 3:
        for i in range(y):
            for j in range(W):
                rec[i][j] = 1
    
    else:
        for i in range(y,H):
            for j in range(W):
                rec[i][j] = 1

res = 0
for i in range(H):
    for j in range(W):
        if rec[i][j] == 0:
            res += 1

print(res)

Submission status: Accepted

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

for _ in range(N):
    x,y,a = map(int,input().split())
    if a==1:
        w = max(x,w)
    elif a==2:
        W = min(x,W)
    elif a==3:
        h = max(y,h)
    else:
        H = min(y,H)
        
if h<H and w<W:
    print((W-w)*(H-h))
else:
    print(0)

Submission status: Accepted

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

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

if s[0] >= t[0] or s[1] >= t[1]:
    print(0)
else:
    print((t[0] - s[0]) * (t[1] - s[1]))

Submission status: Accepted

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

xmin,xmax,ymin,ymax = 0,w,0,h

for x,y,a in p:
    if a == 1:
        if x > xmin:
            xmin = x

    elif a == 2:
        if x < xmax:
            xmax = x

    elif a == 3:
        if y > ymin:
            ymin = y

    elif a == 4:
        if y < ymax:
            ymax = y

if xmax-xmin < 0 or ymax-ymin < 0:
    print(0)
else:
    print((xmax-xmin) * (ymax-ymin))

Submission status: Accepted

Solution code:
w,h,n = map(int, input().split())
a=0
b=0
listA=[]
while True:
  try:
    listA.append(list(map(int,input().split())))
  except:
    break;
for i in range(n):
  if listA[i-1][2]==1 and listA[i-1][0]>a:
    a = listA[i-1][0]
  elif listA[i-1][2]==2 and listA[i-1][0]<w:
    w = listA[i-1][0]
  elif listA[i-1][2]==3 and listA[i-1][1]>b:
    b = listA[i-1][1]
  elif listA[i-1][2]==4 and listA[i-1][1]<h:
    h = listA[i-1][1]
if w-a>0 and h-b>0:
  print((w-a)*(h-b))
else:
  print(0)

Submission status: Accepted

Solution code:
W, H, N = [int(x) for x in input().split()]
L = [[int(y) for y in input().split()] for _ in range(N)]
xmin = 0
xmax = W
ymin = 0
ymax = H

for i in range(N):
    if L[i][2] == 1 and L[i][0] > xmin:
        xmin = L[i][0]
    elif L[i][2] == 2 and L[i][0] < xmax:
        xmax = L[i][0]
    elif L[i][2] == 3 and L[i][1] > ymin:
        ymin = L[i][1]
    elif L[i][2] == 4 and L[i][1] < ymax:
        ymax = L[i][1]

print((xmax-xmin)*(ymax-ymin) if xmax-xmin > 0 and ymax-ymin > 0 else 0)

Submission status: Accepted

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

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

for xi, yi, ai in p:
  if ai == 1:
    if xl < xi:
      xl = xi
  if ai == 2:
    if xr > xi:
      xr = xi
  if ai == 3:
    if yl < yi:
      yl = yi
  if ai == 4:
    if yh > yi:
      yh = yi

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

Submission status: Accepted

Solution code:
""" AtCoder """

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

w = 0
h = 0

for i in range(N):
    if xya[i][2] == 1:
        if w < xya[i][0]:
            w = xya[i][0]
    elif xya[i][2] == 2:
        if W > xya[i][0]:
            W = xya[i][0]
    elif xya[i][2] == 3:
        if h < xya[i][1]:
            h = xya[i][1]
    else:
        if H > xya[i][1]:
            H = xya[i][1]

ans = (H - h) * (W - w)

if H - h < 0 or W - w < 0:
    print(0)
else:
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

sx, sy, ex, ey = 0, 0, W, H

for x, y, a in XYA:
    if a == 1:
        sx = max(sx, x)
    elif a == 2:
        ex = min(ex, x)
    elif a == 3:
        sy = max(sy, y)
    elif a == 4:
        ey = min(ey, y)
    
result = max(ex - sx, 0) * max(ey - sy, 0)
print(result)

Submission status: Accepted

Solution code:
W, H, N = map(int, input().rstrip().split(' '))
sq = [[0 for i in range(W)] for j in range(H)]
for i in range(N):
    x, y, a = map(int, input().rstrip().split(' '))
    if a == 1:
        # < xi
        for j in range(H):
            for k in range(0, x):
                sq[j][k] = 1

    elif a == 2:
        # xi <=
        for j in range(H):
            for k in range(x, W):
                sq[j][k] = 1
    elif a == 3:
        # < yi
        for j in range(y):
            for k in range(W):
                sq[j][k] = 1
    elif a == 4:
        # yi < 
        for j in range(y, H):
            for k in range(W):
                sq[j][k] = 1


result = 0 
for i in range(H):
    for j in range(W):
        if sq[i][j] == 0:
            result += 1


print(result)

Submission status: Accepted

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

area = [ [ 0 for _ in range(W) ] for _ in range(H) ]
for xya in xyas:
    x, y, a = xya
    if a == 1:
        for i in range(x):
            for j in range(H):
                area[j][i] = 1
    elif a == 2:
        for i in range(x, W):
            for j in range(H):
                area[j][i] = 1
    elif a == 3:
        for i in range(W):
            for j in range(y):
                area[j][i] = 1
    else:
        for i in range(W):
            for j in range(y, H):
                area[j][i] = 1
ans = 0
for s in area:
    for t in s:
        if t == 0:
            ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

left = 0
right = w
down = 0
up = h

for xya in xya_s:
    if xya[2] == 1:
        if left < xya[0]:
            left = xya[0]
    elif xya[2] == 2:
        if xya[0] < right:
            right = xya[0]
    elif xya[2] == 3:
        if xya[1] > down:
            down = xya[1]
    else:
        if xya[1] < up:
            up = xya[1]
if right - left > 0 and up - down > 0:
    print((right - left) * (up - down))
else:
    print(0)

Submission status: Accepted

Solution code:
w,h,n=[int(i) for i in input().split()]
a1=[0]
a2=[w]
a3=[0]
a4=[h]
for i in range(n):
    x,y,a=[int(j) for j in input().split()]
    if a==1:
        a1.append(x)
    elif a==2:
        a2.append(x)
    elif a==3:
        a3.append(y)
    else:
        a4.append(y)

a1a2=sorted(a2)[0]-sorted(a1)[-1]
a3a4=sorted(a4)[0]-sorted(a3)[-1]
if a1a2>0 and a3a4>0:
    ans=a1a2*a3a4
else:
    ans=0
print(ans)