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())
a = [[] for _ in range(4)]
for _ in range(n):
    x, y, z = map(int, input().split())
    if z == 1 or z == 2:
        a[z-1].append(x)
    else:
        a[z-1].append(y)

x_count = 0
for i in range(w):
    flag = False

    for k in a[0]:
        if i < k:
            flag = True
            break
    if flag:
        continue
    
    for k in a[1]:
        if i >= k:
            flag = True
            break
    if flag:
        continue
    
    x_count += 1

y_count = 0
for i in range(w):
    flag = False

    for k in a[2]:
        if i < k:
            flag = True
            break
    if flag:
        continue
    
    for k in a[3]:
        if i >= k:
            flag = True
            break
    if flag:
        continue
    
    y_count += 1

print(x_count * y_count)

Submission status: Accepted

Solution code:
W,H,N = map(int, input().split(' '))
ls = []
for i in range(N):
  ls.append(input())
  
WA,WZ,HA,HZ = 0,W,0,H
 
for str_ in ls:
  x,y,a = map(int,str_.split(' '))
  
  if a == 1 and WA < x:
    WA = x
  elif a == 2 and WZ > x:
    WZ = x
  elif a == 3 and HA < y:
    HA = y
  elif a == 4 and HZ > y:
    HZ = y
 
if (w := WZ-WA) > 0 and (h := HZ-HA) > 0:
  print(int(w*h))
else:
  print(0)

Submission status: Accepted

Solution code:
import numpy as np
w,h,n = map(int, input().split())
area = np.array([[1]*w]*h)

for _ in range(n):
  x,y,a = map(int, input().split())
  if a == 1:
    area[:,:x]=0
  elif a == 2:
    area[:,x:]=0
  elif a == 3:
    area[:y,:]=0
  elif a == 4:
    area[y:,:]=0
print(area.sum())

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def main():
    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())

    x_min = 0
    x_max = W
    y_min = 0
    y_max = H
    for x, y, a in zip(X, Y, A):
        if a == 1:
            x_min = max(x_min, x)
        elif a == 2:
            x_max = min(x_max, x)
        elif a == 3:
            y_min = max(y_min, y)
        else:
            y_max = min(y_max, y)

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

print(w.count(1)*h.count(1))

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
st = set()
for i in range(n):
  x, y, a = map(int, input().split())
  if a == 1:
    for k in range(x):
      for l in range(h):
        st.add((k, l))
  elif a == 2:
    for k in range(x, w):
      for l in range(h):
        st.add((k, l))
  elif a == 3:
    for k in range(w):
      for l in range(y):
        st.add((k, l))
  elif a == 4:
    for k in range(w):
      for l in range(y, h):
        st.add((k, l))
print(w * h - len(st))

Submission status: Accepted

Solution code:
w0, h0 = 0, 0
w, h, n = map(int, input().split())
for _ 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

print([0, (w - w0) * (h - h0)][w - w0 > 0 < h - h0])

Submission status: Accepted

Solution code:
import numpy as np
from pprint import pprint
W, H, N = map(int, input().split())
area = np.ones((H, W))
# pprint(area[1][:3])
for _ in range(N):
    x, y, a = map(int, input().split())
    y = H - y
    if a == 1:
        for i in range(H):
            area[i][:x] = 0
    elif a == 2:
        for i in range(H):
            area[i][x:] = 0
    elif a == 3:
        for i in range(y, H):
            area[i] = 0
    elif a == 4:
        for i in range(y):
            area[i] = 0
pprint(int(area.sum()))

Submission status: Accepted

Solution code:
W, H, N = list(map(int, input().split()))
x_low, x_up = 0, W
y_low, y_up = 0, H
for _ in range(N):
    x, y, a = list(map(int, input().split()))
    if a == 1:
        x_low = max(x_low, x)
    elif a == 2:
        x_up = min(x_up, x)
    elif a == 3:
        y_low = max(y_low, y)
    else:
        y_up = min(y_up, y)
print(max(0, x_up - x_low) * max(0, y_up - y_low))

Submission status: Accepted

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

def main():
    W, H, N = map(int, input().split())
    xya = [list(map(int, input().split())) for i in range(N)]
    a, b = 0, 0
    for i in range(N):
        if xya[i][2] == 1:
            a = max(a, xya[i][0])
        elif xya[i][2] == 2:
            W = min(W, xya[i][0])
        elif xya[i][2] == 3:
            b = max(b, xya[i][1])
        elif xya[i][2] == 4:
            H = min(H, xya[i][1])
    print(max(0, W - a) * max(0, H - b))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

width = edge[0] - origin[0]
height = edge[1] - origin[1]
if width < 0:
  width = 0
if height < 0:
  height = 0

print(width * height)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
x_a = 0
y_a = 0
for i in range(n):
    x,y,a = map(int,input().split())
    
    if a == 1:
        if x_a < x:
            x_a = x
    elif a == 2:
        if x < w:
            w = x
    elif a == 3:
        if y_a < y:
            y_a = y
    elif a == 4:
        if y < h:
            h = y

if w - x_a <= 0 or h - y_a <= 0:
    ans = 0
else:
    ans = (w - x_a)*(h - y_a)

print(ans)

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
x_a = 0
y_a = 0
for i in range(n):
    x,y,a = map(int,input().split())
    
    if a == 1:
        if x < x_a:
            x_a = x_a
        else:
            x_a = x
    elif a == 2:
        if x < w:
            w = x
        else:
            w = w
        
    elif a == 3:
        if y < y_a:
            y_a = y_a
        else:
            y_a = y
    
    elif a == 4:
        if y < h:
            h = y
        else:
            h = h

if w - x_a <= 0 or h - y_a <= 0:
    ans = 0
else:
    ans = (w - x_a)*(h - y_a)

print(ans)

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
lst=[]
for _ in range(n):
    x,y,a=map(int,input().split())
    if a==1 or a==2:
        lst.append([x,a])
    else:
        lst.append([y,a])
answer=0
for i in range(h):
    for j in range(w):
        ans=True
        for k in range(n):
            nuri,c=lst[k]
            if c==1:
                if j<nuri:
                    ans=False
                    break
            elif c==2:
                if j>=nuri:
                    ans=False
                    break
            elif c==3:
                if i<nuri:
                    ans=False
                    break
            else:
                if i>=nuri:
                    ans=False
                    break
        if ans==True:
            answer+=1
print(answer)

Submission status: Accepted

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

for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1 and w < x: w = x
    elif a == 2 and W > x: W = x
    elif a == 3 and h < y: h = y
    elif a == 4 and H > y: H = y

print(max(W - w, 0) * max(H - h, 0))

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
List = []
for i in range (N):
  List.append(list(map(int, input().split())))
WRange = [0,W]
HRange = [0,H]
for i in range(N):
  if List[i][2] == 1:
    WRange[0] = max(WRange[0],List[i][0])
  elif List[i][2] == 2:
    WRange[1] = min(WRange[1],List[i][0])
  elif List[i][2] == 3:
    HRange[0] = max(HRange[0],List[i][1])
  else:
    HRange[1] = min(HRange[1],List[i][1])
if WRange[1]-WRange[0] >0:
  W = WRange[1]-WRange[0]
else:
  W = 0
if HRange[1]-HRange[0] >0:
  H = HRange[1]-HRange[0]
else:
  H = 0
res = H * W
print(res)

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
minx,maxx=0,w
miny,maxy=0,h

for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    minx=max(minx,x)
  if a==2:
    maxx=min(maxx,x)
  if a==3:
    miny=max(miny,y)
  if a==4:
    maxy=min(maxy,y)
xx=(maxx-minx)
yy=(maxy-miny)
if xx>0 and yy>0:
  print(xx*yy)
else:
  print(0)

Submission status: Accepted

Solution code:
wmax,hmax,n=map(int,input().split())
wmin,hmin=0,0
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    wmin=max(wmin,x)
  elif a==2:
    wmax=min(wmax,x)
  elif a==3:
    hmin=max(hmin,y)
  elif a==4:
    hmax=min(hmax,y)

if hmin>=hmax or wmin>=wmax:
  print(0)
else:
  print((hmax-hmin)*(wmax-wmin))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def main():
    Wr, Hu, N = map(int, input().split())
    C =  [list(map(int, input().split())) for i in range(N)]
    Wl, Hd = 0, 0
    for x, y ,a in C:
        if a == 1:
            if Wl <= x:
                Wl = x
        if a == 2:
            if Wr >= x:
                Wr = x
        if a == 3:
            if Hd <= y:
                Hd = y
        if a == 4:
            if Hu >= y:
                Hu = y
        if Wr <= Wl or Hu <= Hd:
            print(0)
            return
    W = Wr - Wl
    H = Hu - Hd
    print(W*H)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

for n in range(N):
    x,y,a = list(map(int,input().split()))
    if a == 1:
        X[0] = max(X[0],x)
    elif a == 2:
        X[1] = min(X[1],x)
    elif a == 3:
        Y[0] = max(Y[0],y)
    elif a == 4:
        Y[1] = min(Y[1],y)
    
# print((X[1]-X[0])*(Y[1]-Y[0]))
print(max(0,X[1]-X[0])*max(0,Y[1]-Y[0]))

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
P = [list(map(int, input().split())) for _ in range(N)]
L, R, U, D = 0, W, H, 0
for p in P:
  x, y, a = p
  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(max(U-D, 0) * max(R-L, 0))

Submission status: Accepted

Solution code:
def resolve():
    W, H, N = list(map(int, input().split()))
    # (0,0)(W,H)を含む交点のx,y座標リスト
    white_W_list = list(range(W+1))
    white_H_list = list(range(H+1))
    for i in range(N):
        x, y, a = list(map(int, input().split()))
        if a == 1:
            white_W_list = [j for j in white_W_list if j >= x]
        elif a == 2:
            white_W_list = [j for j in white_W_list if j <= x]
        elif a == 3:
            white_H_list = [j for j in white_H_list if j >= y]
        elif a == 4:
            white_H_list = [j for j in white_H_list if j <= y]
    width = len(white_W_list) - 1
    length = len(white_H_list) - 1
    if width >= 1 and length >= 1:
        area = width * length
        print(area)
    else:
        print(0)

resolve()

Submission status: Accepted

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


def calculate(w, h, n, arr):
    minX = 0
    minY = 0
    maxX = w
    maxY = h

    for i in range(n):
        x = arr[i][0]
        y = arr[i][1]
        type = arr[i][2]

        if type == 1:
            minX = max(minX, x)
            continue

        if type == 2:
            maxX = min(maxX, x)
            continue

        if type == 3:
            minY = max(minY, y)
            continue

        if type == 4:
            maxY = min(maxY, y)
            continue

    s1 = max(0, maxX - minX)
    s2 = max(0, maxY - minY)

    print(s1 * s2)


calculate(W, H, N, ARR)

Submission status: Accepted

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

Submission status: Accepted

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

board = [[1]*W for _ in range(H)]

for _ in range(N):
    x, y, a = map(int, input().split())
    t = 0
    b = H
    l = 0
    r = W
    if a == 1:
        r = x
    if a == 2:
        l = x
    if a == 3:
        b = y
    if a == 4:
        t = y
    
    for h in range(t, b):
        for w in range(l, r):
            board[h][w] = 0
    
print(sum([sum(r) for r in board]))

Submission status: Accepted

Solution code:
import sys
from itertools import accumulate

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    W, H, N, *XYA = map(int, read().split())

    x_left = 0
    x_right = W
    y_left = 0
    y_right = H
    for x, y, a in zip(*[iter(XYA)] * 3):
        if a == 1 and x_left < x:
            x_left = x
        elif a == 2 and x_right > x:
            x_right = x
        elif a == 3 and y_left < y:
            y_left = y
        elif a == 4 and y_right > y:
            y_right = y

    print(max(x_right - x_left, 0) * max(y_right - y_left, 0))
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from itertools import accumulate

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    W, H, N, *XYA = map(int, read().split())

    vec_x = [0] * (W + 1)
    vec_y = [0] * (H + 1)
    for x, y, a in zip(*[iter(XYA)] * 3):
        if a == 1:
            vec_x[0] += 1
            vec_x[x] -= 1
        elif a == 2:
            vec_x[x] += 1
            vec_x[W] -= 1
        elif a == 3:
            vec_y[0] += 1
            vec_y[y] -= 1
        else:
            vec_y[y] += 1
            vec_y[H] -= 1

    vec_x = list(accumulate(vec_x))
    vec_y = list(accumulate(vec_y))

    ans = 0
    for i in range(W):
        for j in range(H):
            if vec_x[i] == 0 and vec_y[j] == 0:
                ans += 1

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for _ in range(n):
  x,y,a = map(int,input().split())
  if a == 1:
    width[:x] = x*[0]
  elif a == 2:
    width[x:] = (w-x)*[0]
  elif a == 3:
    height[:y] = y*[0]
  else:
    height[y:] = (h-y)*[0]
 
print(width.count(1)*height.count(1))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[11]:


W,H,N = map(int, input().split())
l,r,u,d = 0,W,H,0
for _ in range(N):
    x,y,a = list(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(max(0,(r-l))*max(0,(u-d)))


# In[ ]:

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
x1 = 0
y1 = 0
x2 = w
y2 = h
f = 0
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        x1 = max(x, x1)
    elif a == 2:
        x2 = min(x, x2)
    elif a == 3:
        y1 = max(y, y1)
    elif a == 4:
        y2 = min(y, y2)
    
    if x1 >= x2 or y1 >= y2 or x2 <= 0 or y2 <= 0:
        f = 1
if f:
    print("0")
else:
    print((x2-x1)*(y2-y1))

Submission status: Accepted

Solution code:
import sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

W,H,N = LI()

s,t,u,v = 0,W,0,H
for i in range(N):
    x,y,a = LI()
    if a == 1:
        s = max(s,x)
    if a == 2:
        t = min(t,x)
    if a == 3:
        u = max(u,y)
    if a == 4:
        v = min(v,y)

if t > s and v > u:
    print(max(0,(t-s)*(v-u)))
else:
    print(0)

Submission status: Accepted

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

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

Submission status: Accepted

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


# 持っているビスケットを叩き、1枚増やす
# ビスケット A枚を 1円に交換する
# 1円をビスケット B枚に交換する
def main():
    w, h, n = input_list()
    zahyou = [[0]*w for _ in range(h)]
    for _ in range(n):
        x, y, a = input_list()
        umeru(zahyou, x, y, a)
    ans = 0
    for hz in zahyou:
        ans += hz.count(0)
    print(ans)

def umeru(zu, x, y, a):
    for Y, row in enumerate(zu):
        for X, v in enumerate(row):
            if a == 1:
                if X < x:
                    zu[Y][X] = 1
            if a == 2:
                if X > x - 1:
                    zu[Y][X] = 1
            if a == 3:
                if Y < y:
                    zu[Y][X] = 1
            if a == 4:
                if Y > y - 1:
                    zu[Y][X] = 1


def input_list():
    return list(map(int, input().split()))


def input_list_str():
    return list(map(str, input().split()))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
xs = [0, W]
ys = [0, H]
for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1 and x > xs[0]:
        xs[0] = x
    elif a == 2 and x < xs[1]:
        xs[1] = x
    elif a == 3 and y > ys[0]:
        ys[0] = y
    elif a == 4 and y < ys[1]:
        ys[1] = y
    else:
        pass
x_len = xs[1] - xs[0] if xs[1] > xs[0] else 0
y_len = ys[1] - ys[0] if ys[1] > ys[0] else 0
print(x_len * y_len)

Submission status: Accepted

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

xy = []
for i in range(h):
    tmp = [0] * w
    xy.append(tmp)


lis = []
for _ in range(n):
    t = list(map(int, input().split()))
    lis.append(t)

for i in lis:
    if i[2] == 1:
        for j in range(h):
            for k in range(i[0]):
                xy[j][k] = 1
    elif i[2] == 2:
        for j in range(h):
            for k in range(i[0], w):
                xy[j][k] = 1
    elif i[2] == 3:
        for j in range(i[1]):
            for k in range(w):
                xy[j][k] = 1
    elif i[2] == 4:
        for j in range(i[1], h):
            for k in range(w):
                xy[j][k] = 1

ans = 0
for i in xy:
    for j in i:
        if j == 0:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():

    w, h, n = [int(x) for x in input().split()]
    l, r, u, d = 0, w, h, 0
    for _ in range(n):
        x, y, a = [int(x) for x in 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(max(0, (r - l)) * max(0, (u - d)))

    
    

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

2 3 4 4
3 4 4
2 3 4
2 3 4
2 4 4


"""

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())
box = []

for i in range(h):
    box.append([1]*w)
for i in range(n):
    if a[i] == 1:
        for m in range(h):
            for j in range(x[i]):
                box[m][j] = 0  
    elif a[i] == 2:
        for m in range(h):
            for j in range(x[i],w):
                box[m][j] = 0
    elif a[i] == 3:
        for m in range(y[i]):
            for j in range(w):
                box[m][j] = 0
    else:
        for m in range(y[i],h):
            for j in range(w):
                box[m][j] = 0
print(sum(map(sum,box)))

Submission status: Accepted

Solution code:
MM = input().split()
W = int(MM[0])
H = int(MM[1])
N = int(MM[2])
a = 0
b = 0
c = W
d = H
for i in range(N):
  LL = input().split()
  x = int(LL[0])
  y = int(LL[1])
  aa = int(LL[2])
  if aa == 1:
    if x > a:
      a = x
  elif aa == 2:
    if x < c:
      c = x
  elif aa == 3:
    if y > b:
      b = y
  else:
    if y < d:
      d  = y

if (c-a) > 0 and (d -b) > 0:
  ans = (c-a) * (d -b)
  print(ans)
else:
  print(0)

Submission status: Accepted

Solution code:
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

w,h,n = readInts()
xya = [readInts() for i in range(n)]

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

for x,y,a in xya:
  if a==1:
    xmin = max(x,xmin)
  elif a==2:
    xmax = min(x,xmax)
  elif a==3:
    ymin = max(y,ymin)
  else:
    ymax = min(y,ymax)

print(max(0,xmax-xmin)*max(0,ymax-ymin))

Submission status: Accepted

Solution code:
w,h,n = map(int, input().split())
x1,x2,y1,y2 = 0,w,0,h
for _ in range(n):
  xi,yi,ai = map(int, input().split())
  if ai==1: x1 = max(xi,x1)
  elif ai==2: x2 = min(xi,x2)
  elif ai==3: y1 = max(yi,y1)
  else: y2 = min(yi,y2)
dx = max(0, x2-x1)
dy = max(0, y2-y1)
print(dx*dy)

Submission status: Accepted

Solution code:
import numpy as np

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

area = np.ones((W, H))

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

    if a == 1:
        area[:x, :] = 0
    elif a == 2:
        area[x:, :] = 0
    elif a == 3:
        area[:, :y] = 0
    elif a == 4:
        area[:, y:] = 0

print(int(np.sum(area)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#数学的に解く
w,h,n = map(int,input().split())
cnt = 0
X = 0
Y = 0
while(cnt < n):
    x,y,a = map(int,input().split())
    
    if(a == 1):
        X = max(X,x)
    elif(a == 2):
        w = min(w,x)
    elif(a == 3):
        Y = max(Y,y)
    elif(a == 4):
        h = min(h,y)
    #print(w,h,X,Y)
    cnt += 1
print(max(w-X,0)*max(h-Y,0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
R = [list(map(int, input().split())) for _ in range(N)]
X,Y = [0, W],[0, H]
for r in R:
  if r[2]==1:
    X[0] = max(X[0], r[0])
  elif r[2]==2:
    X[1] = min(X[1], r[0])
  elif r[2]==3:
    Y[0] = max(Y[0], r[1])
  else:
    Y[1] = min(Y[1], r[1])
print(max(0, (X[1]-X[0]))*max(0, (Y[1]-Y[0])))

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
point_lst = [list(map(int, input().split())) for _ in range(N)]
x_1 = 0
x_2 = W
y_1 = 0
y_2 = H

for point in point_lst:
    if point[2] == 1:
        if point[0] > x_1:
            x_1 = point[0]

    elif point[2] == 2:
        if point[0] < x_2:
            x_2 = point[0]
    elif point[2] == 3:
        if point[1] > y_1:
            y_1 = point[1]
    else:
        if point[1] < y_2:
            y_2 = point[1]

width = x_2 - x_1 if x_2 > x_1 else 0
height = y_2 - y_1 if y_2 > y_1 else 0
print(width*height)

Submission status: Accepted

Solution code:
s = input().split()

w = int(s[0])
h = int(s[1])
n = int(s[2])

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

x = []
y = []
a = []

for num in range(n):
    v = input().split()
    x.append(int(v[0]))
    y.append(int(v[1]))
    a.append(int(v[2]))

for num in range(n):
    if a[num] == 1:
        if x[num] > min_x:
            min_x = x[num]
    elif a[num] == 2:
        if x[num] < max_x:
            max_x = x[num]
    elif a[num] == 3:
        if y[num] > min_y:
            min_y = y[num]
    else:
        if y[num] < max_y:
            max_y = y[num]

y_length = max_y - min_y
if y_length < 0:
    y_length = 0
x_length = max_x - min_x
if x_length < 0:
    x_length = 0
answer = x_length * y_length

print(answer)

Submission status: Accepted

Solution code:
import sys
import numpy as np
# from decimal import Decimal
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

w, h, n = map(int, readline().split())
left = 0
right = w
up = h
down = 0

s = w * h
for i in range(n):
    x, y, a = map(int, readline().split())
    if (a == 1):
        left = max(x, left)
    elif (a == 2):
        right = min(x, right)
    elif (a == 3):
        down = max(y, down)
    else:
        up = min(y, up)

    if (right - left <= 0) or (up - down <= 0):
        print(0)
        exit()

ans = (right - left) * (up - down)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
w, h, n, *Q = map(int, open(0).read().split())
B = np.ones((h, w), dtype=int)
for x, y, a in zip(Q[::3], Q[1::3], Q[2::3]):
    if a == 1:
        for i in range(x):
            B[:, i] = 0
    elif a == 2:
        for i in range(x, w):
            B[:, i] = 0
    elif a == 3:
        for i in range(y):
            B[i, :] = 0
    else:
        for i in range(y, h):
            B[i, :] = 0
print(np.sum(B))

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
left, right = 0, W
down, up = 0, H

for i in range(N):
  x, y, a = map(int, input().split())
  if a == 1:
    left = max(left, x)
  elif a == 2:
    right = min(right, x)
  elif a == 3:
    down = max(down, y)
  else:
    up = min(up, y)
    
w, h = 0, 0
if right-left > 0:
  w = right - left
if up-down > 0:
  h = up-down
ans = w * h
print(ans)

Submission status: Accepted

Solution code:
import sys

def nextrec(coor,pt):
    if pt[2]==1:
        coor[0]=min(max(coor[0],pt[0]),coor[2])
    elif pt[2]==2:
        coor[2]=max(min(coor[2],pt[0]),coor[0])
    elif pt[2]==3:
        coor[1]=min(max(coor[1],pt[1]),coor[3])
    elif pt[2]==4:
        coor[3]=max(min(coor[3],pt[1]),coor[1])
def main(w,h,n,pts):
    rec=[0,0,w,h]
    for x in range(n):
        nextrec(rec,pts[x])
    return (rec[0]-rec[2])*(rec[1]-rec[3])

w,h,n=map(int,sys.stdin.readline().strip().split())
pts=[list(map(int,sys.stdin.readline().strip().split())) \
    for x in range(n)]

print(main(w,h,n,pts))

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

w, h, n = rm()
xleft = 0
xright = w
ytop = h
ybottom = 0
for _ in range(n):
  x, y, a = rm()
  if a == 1:
    xleft = max(xleft, x)
  elif a == 2:
    xright = min(xright, x)
  elif a == 4:
    ytop = min(ytop, y)
  else:
    ybottom = max(ybottom, y)
if xleft >= xright or ybottom >= ytop:
  print(0)
else:
  print((xright-xleft)*(ytop-ybottom))

Submission status: Accepted

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

ans = 0            
for i in range(h):
    ans += cell[i].count(0)
print(ans)