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:
import numpy as np
w, h, n = map(int, input().split())
loc = [input() for _ in range(n) ]

def black(x, y, i):
    if i == 1:
        mtx[:x,] = 0
    elif i == 2:
        mtx[x:,] = 0
    elif i == 3:
        mtx[:, :y] = 0
    elif i == 4:
        mtx[:, y:] = 0

        
mtx = np.ones((w, h), dtype=int)
for l in loc:
    x, y, i = map(int, l.split())
    black(x, y, i)
print(mtx.sum())

Submission status: Accepted

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

X = [[i+1, "w"] for i in range(W)]
Y = [[i+1, "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(len(X)):
            if X[j][0] <= x:
                X[j][1] = "b"
    elif a == 2:
        for j in range(len(X)):
            if X[j][0] > x:
                X[j][1] = "b"
    elif a == 3:
        for j in range(len(Y)):
            if Y[j][0] <= y:
                Y[j][1] = "b"
    elif a == 4:
        for j in range(len(Y)):
            if Y[j][0] > y:
                Y[j][1] = "b"
x_w = 0
y_w = 0
for i in range(len(X)):
    if X[i][1] == "w":
        x_w += 1
for i in range(len(Y)):
    if Y[i][1] == "w":
        y_w += 1
print(x_w * y_w)

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
l,r,b,t=0,W,0,H
for _ 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:
        b=max(b,y)
    else:
        t=min(t,y)
if l<r and b<t:
    print((r-l)*(t-b))
else:
    print(0)

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
ans = [[0 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):
            ans[j][:x] = [1 for _ in range(x)]
    if a == 2:
        for j in range(h):
            ans[j][x:] = [1 for _ in range(w-x)]
    if a == 3:
        for j in range(h-y,h):
            ans[j] = [1 for _ in range(w)]
    if a == 4:
        for j in range(h-y):
            ans[j] = [1 for _ in range(w)]
cnt = 0
for k in ans:
    cnt += k.count(0)
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

point_list = []
for h in range(H):
  list_ = []
  for w in range(W):
    list_.append(1)
  point_list.append(list_)

for input_ in input_list:
  x, y, a = input_
  if a == 1:
    for h in range(H):
      for i in range(x):
        point_list[h][i] = 0
  if a == 2:
    for h in range(H):
      for i in range(x, W):
        point_list[h][i] = 0
  if a == 3:
    for i in range(y):
      for w in range(W):
        point_list[i][w] = 0
  if a == 4:
    for i in range(y, H):
      for w in range(W):
        point_list[i][w] = 0

ans = sum([sum(point) for point in point_list])
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

a1,a2,a3,a4 = -1,101,-1,101
for i in range(N):
  x,y,a = map(int,input().split())
  if a == 1:
    a1 = max(a1,x)
  elif a == 2:
    a2 = min(a2,x-1)
  elif a == 3:
    a3 = max(a3,y)
  else:
    a4 = min(a4,y-1)
    
mass = [[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
  for j in range(W):
    if i < a3 or a4 < i:
      mass[i][j] += 1
    if j < a1 or a2 < j:
      mass[i][j] += 1
      
cnt = 0
for k in mass:
  cnt += k.count(0)
  
print(cnt)

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
right, left, lower, upper = 0, w, 0, h
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        right = max(right, x)
    if a == 2:
        left = min(left, x)
    if a == 3:
        lower = max(lower, y)
    if a == 4:
        upper = min(upper, y)

a = left - right
b = upper - lower

if a <= 0 or b <= 0:
    print(0)
else:
    print(a*b)

Submission status: Accepted

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


def main():
    W, H, N = map(int, input().split())
    X = Y = 0
    for i in range(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)
        else:
            H = min(H, y)
    print(max(W - X, 0) * max(H - Y, 0))


main()

Submission status: Accepted

Solution code:
import sys
import math


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())


w, h, n = inintm()

ll = [0,0]
rh = [w,h]

for i in range(n):
    x, y, a = inintm()
    if a == 1:
        ll[0] = max(ll[0], x)
    elif a == 2:
        rh[0] = min(rh[0], x)
    elif a == 3:
        ll[1] = max(ll[1], y)
    else:
        rh[1] = min(rh[1], y)

if rh[0]-ll[0] < 0 or rh[1]-ll[1] < 0:
    print(0)
else:
    print((rh[0]-ll[0])*(rh[1]-ll[1]))

Submission status: Accepted

Solution code:
num_line = input().split(" ")
x_num = int(num_line[0])
y_num = int(num_line[1])
num = int(num_line[2])

tangle = [[1]*x_num for i in range(y_num)]

#print(tangle)

for i in range(num):
    line = input().split(" ")
    x_tem = int(line[0])
    y_tem = int(line[1])
    index = int(line[2])
    
    if(index == 1):
        for j in range(y_num):
            for k in range(x_tem):
                tangle[j][k] = 0
        #print(tangle)            
        
    elif(index == 2):
        for j in range(y_num):
            for k in range(x_num - x_tem):
                tangle[j][k + x_tem] = 0
        #print(tangle)
        
    elif(index == 3):
        for j in range(y_tem):
            for k in range(x_num):
                tangle[j][k] = 0
        #print(tangle)
        
    else:
        for j in range(y_num - y_tem):
            for k in range(x_num):
                tangle[j + y_tem][k] = 0
        #print(tangle)
        
result = 0
for i in range(y_num):
    for j in range(x_num):
        result += tangle[i][j]
        
print(result)

Submission status: Accepted

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


for i in range(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)
    else:
        H = min(H,y)
print(max(W-X,0)*max(H-Y,0))

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
a = []
for i in range(N):
    b = list(map(int,input().split()))
    a.append(b)
xs = 0
xe = W
ys = 0
ye = H
for i in range(N):
    if a[i][2] == 1 and xs < a[i][0]:
        xs = a[i][0]
    elif a[i][2] == 2 and xe > a [i][0]:
        xe = a[i][0]
    elif a[i][2] == 3 and ys < a[i][1]:
        ys = a[i][1]
    elif a[i][2] == 4 and ye > a[i][1]:
        ye = a[i][1]
if xs < xe:
    w = xe - xs
else:
    w = 0
if ys < ye:
    h = ye - ys
else:
    h = 0
print(w*h)

Submission status: Accepted

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

xmin = 0
xmax = W
ymin = 0
ymax = H
for i in range(N):

    if array[i][2] == 1:
        xmin = max(xmin, array[i][0])
    elif array[i][2] == 2:
        xmax = min(xmax, array[i][0])
    elif array[i][2] == 3:
        ymin = max(ymin, array[i][1])
    elif array[i][2] == 4:
        ymax = min(ymax, array[i][1])
area = (xmax-xmin)*(ymax-ymin)
if area <= 0 or xmax < xmin or ymax < ymin:
    print(0)
else:
    print(area)

Submission status: Accepted

Solution code:
W, H, N = [int(x) for x in input().split()]
x_min, x_max, y_min, y_max = 0, W, 0, H
num_lists = [[int(x) for x in input().split()] for _ in range(N)]

for num_list in num_lists:
    if num_list[2] == 1 and num_list[0] > x_min:
        x_min = num_list[0]
    if num_list[2] == 2 and num_list[0] < x_max:
        x_max = num_list[0]
    if num_list[2] == 3 and num_list[1] > y_min:
        y_min = num_list[1]
    if num_list[2] == 4 and num_list[1] < y_max:
        y_max = num_list[1]

if x_min > x_max or y_min > y_max:
    print(0)
else:
    print((x_max-x_min)*(y_max-y_min))

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc047/tasks/abc047_b

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

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

for _ in range(n):
    x, y, a = [int(i) for i in input().split()]
    if a == 1:
        left = max(left, x)
    elif a == 2:
        right = min(right, x)
    elif a == 3:
        bottom = max(bottom, y)
    elif a == 4:
        top = min(top, y)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
A,B,C,D=[0],[W],[0],[H]

for i in range(N):
    x,y,a=map(int,input().split())
    if a==1:
        A.append(x)
    elif a==2:
        B.append(x)
    elif a==3:
        C.append(y)
    elif a==4:
        D.append(y)

W=min(B)-max(A)
H=min(D)-max(C)

if W<0 or H<0:
    ans=0
else:
    ans=H*W
print(ans)

Submission status: Accepted

Solution code:
w,h,n=[int(i) for i in input().split()]
#二次元配列の作成
list_2d=[[0]*w for i in range(h)]


def nurie(x,y,a):
   if a==1:
       for i in range(h):
           for j in range(x):
               list_2d[i][j]=1
   elif a==2:
       for i in range(h):
           for j in range(x,w):
               list_2d[i][j]=1
               

   elif a==3:
       for i in range(y):
           for j in range(w):
               list_2d[i][j]=1
              
   else:
       for i in range(y,h):
           for j in range(w):
               list_2d[i][j]=1
   return list_2d
               
for i in range(n):
   x,y,a=[int(i) for i in input().split()]
   nurie(x,y,a)
   
sum=0
for i in range(h):
   sum+=list_2d[i].count(0)
   
print(sum)

Submission status: Accepted

Solution code:
w,h,n=map(int, input().split()) #初期値
lx=0
ly=0
rx=w
ry=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 rx>x:
           rx=x
           
   elif a==3:
       if ly<y:
           ly=y
   
   else:
       if ry>y:
           ry=y
# 出力
print(max(rx-lx,0)*max(ry-ly,0))

Submission status: Accepted

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

# 左下の座標
X=Y=0

for i in range(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)
  else:
    H=min(H,y)

# 出力
print(max(W-X,0)*max(H-Y,0))

Submission status: Accepted

Solution code:
w,h,n = map(int, input().split())
s = [[1 for i in range(w)] for j in range(h)]
b = [[1,2,3,4,5],[6,7,8,9,10]]
alist = []
for i in range(n):
    x,y,a = map(int, input().split())
    alist.append(a)
    if a == 1:
        for j in range(h):
            for k in range(0,x):
                s[j][k] = 0
    if a == 2:
        for j in range(h):
            for k in range(x,w):
                s[j][k] = 0
    if a == 3:
        for k in range(w):
            for j in range(0,y):
                s[j][k] = 0
    if a == 4:
        for k in range(w):
            for j in range(y,h):
                s[j][k] = 0
ans = 0
for i in range(h):
    ans = ans + s[i].count(1)
print(ans)

Submission status: Accepted

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

    x_min = 0
    x_max = w
    y_min = 0
    y_max = h

    for _ in range(n):
        x, y, a = map(int, input().split())
        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)

    print(
        (x_max - x_min) * (y_max - y_min)
        if x_min < x_max and y_min < y_max else 0
    )


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(N):
    x, y, a = list(map(int, input().split()))
    if a == 1:
        for i in range(x):
            for j in range(H):
                r[i][j] = 0
    if a == 2:
        for i in range(x,W):
            for j in range(H):
                r[i][j] = 0
    if a == 3:
        for i in range(W):
            for j in range(y):
                r[i][j] = 0
    if a == 4:
        for i in range(W):
            for j in range(y,H):
                r[i][j] = 0
print(sum(sum(R) for R in r))

Submission status: Accepted

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

x_min = 0
x_max = W
y_min = 0
y_max = H

for i in range(N):
    x, y, a = [int(x) for x in input().split()]
    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: # a == 4
        y_max = min(y_max, y)

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

print(area)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
xmin=0
xmax=w
ymin=0
ymax=h
for i in range(n):
    x,y,a=map(int,input().split())
    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())
l, r, t, b = 0, w, h, 0
for i in range(n):
  x, y, a = map(int, input().split())
  if a == 1:
    l = max(x, l)
  elif a == 2:
    r = min(x, r)
  elif a == 3:
    b = max(y, b)
  else:
    t = min(y, t)
if (r - l) <= 0 or (t - b) <= 0:
  print(0)
else:
  print((r - l) * (t - b))

Submission status: Accepted

Solution code:
X, Y, N = map(int, input().split())
lst = [[0 for i in range(X)] for j in range(Y)]

for i in (range(N)):
    x, y, a = map(int, input().split())
    if a == 1:
        for j in range(Y):
            for k in range(x):
                lst[j][k] = 1
    elif a == 2:
        for j in range(Y):
            for k in range(X-1, x-1, -1):
                lst[j][k] = 1
    elif a == 3:
        for j in range(y):
            for k in range(X):
                lst[j][k] = 1
    elif a == 4:
        for j in range(Y-1, y-1, -1):
            for k in range(X):
                lst[j][k] = 1

count = 0
for i in lst:
    count += i.count(0)
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

min_x, min_y, max_x, max_y = 0, 0, w, h
for _ in range(n):
    x, y, a = map(int, input().split())

    if a == 1:
        min_x = max(min_x, x)
    elif a == 2:
        max_x = min(max_x, x)
    elif a == 3:
        min_y = max(min_y, y)
    else:
        max_y = min(max_y, y)

if min_x < max_x and min_y < max_y:
    print((max_x - min_x) * (max_y - min_y))
else:
    print(0)

Submission status: Accepted

Solution code:
def main():
    W,H,N = map(int,input().split())
    X = 0 #a=1初期値
    Y = 0 #a=3初期値
    for _ in range(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)
    #Sを求める
    S = max((W-X),0) * max((H-Y),0)
    print(S)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np

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

X=Y=0
for i in range(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)
    else:
        H=min(H,y)

S=max((W-X),0)*max((H-Y),0)

print(S)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
W,H,N = (int(T) for T in input().split())
XYA = [[0],[W],[0],[H]]
for TN in range(0,N):
    X,Y,A = (int(T) for T in input().split())
    if A in [1,2]:
        XYA[A-1].append(X)
    else:
        XYA[A-1].append(Y)
CW = min(XYA[1])-max(XYA[0])
CH = min(XYA[3])-max(XYA[2])
if CW>=0 and CH>=0:
    print(CW*CH)
else:
    print(0)

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
c=[]
for i in range(n):
    x,y,a=map(int,input().split())
    c.append([x,y,a])
s=w*h
ans=0
for j in range(s):
    x=j%w
    y=j//w
    t=0
    for i in range(n):
        if c[i][2]==1:
            if x<c[i][0]:
                t+=1
                break
        if c[i][2]==2:
            if x>=c[i][0]:
                t+=1
                break
        if c[i][2]==3:
            if y<c[i][1]:
                t+=1
                break
        if c[i][2]==4:
            if y>=c[i][1]:
                t+=1
                break
    if t==0:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
a1 = []
a2 = []
a3 = []
a4 = []
for i in range(N):
    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)
    else:
        a4.append(y)
a1.sort(reverse=True)
a2.sort()
a3.sort(reverse=True)
a4.sort()
if a1:
    l = a1[0]
else:
    l = 0
if a2:
    r = a2[0]
else:
    r = W
if a3:
    d = a3[0]
else:
    d = 0
if a4:
    u = a4[0]
else:
    u = H
if r >= l and u >= d:
    print((r-l)*(u-d))
else:
    print(0)

Submission status: Accepted

Solution code:
W,H,N=list(map(int, input().split()))
wl=[0]
wh=[W]
hl=[0]
hh=[H]
for i in range(N):
  l=list(map(int, input().split()))
  if l[2]==1:
    wl.append(l[0])
  elif l[2]==2:
    wh.append(l[0])
  elif l[2]==3:
    hl.append(l[1])
  else:
    hh.append(l[1])
w=min(wh)-max(wl)
h=min(hh)-max(hl)
if w>0 and h>0:
  print(w*h)
else:
  print(0)

Submission status: Accepted

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

l, r, b, t = 0, w, 0, h
for x, y, a in xya:
    if a == 1:
        l = max(x, l)
    elif a == 2:
        r = min(x, r)
    elif a == 3:
        b = max(y, b)
    elif a == 4:
        t = min(y, t)
print(max(0, r - l) * max(0, t - b))

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
x_pos = [0, w]
y_pos = [0, h]
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        x_pos[0] = max(x_pos[0], x)
    elif a == 2:
        x_pos[1] = min(x_pos[1], x)
    elif a == 3:
        y_pos[0] = max(y_pos[0], y)
    else:
        y_pos[1] = min(y_pos[1], y)
ans = max(0, (x_pos[1] - x_pos[0])) * max(0, (y_pos[1] - y_pos[0]))
print(ans)

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
x_pos = [0, w]
y_pos = [0, h]
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        x_pos[0] = max(x_pos[0], x)
    elif a == 2:
        x_pos[1] = min(x_pos[1], x)
    elif a == 3:
        y_pos[0] = max(y_pos[0], y)
    else:
        y_pos[1] = min(y_pos[1], y)
if x_pos[1] - x_pos[0] < 0 or y_pos[1] - y_pos[0] < 0:
    ans = 0
else:
    ans = (x_pos[1] - x_pos[0] ) * (y_pos[1] - y_pos[0])
print(ans)

Submission status: Accepted

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

sx = [0, w]
sy = [0, h]

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

print(max(0, max(0, (sx[1] - sx[0])) * max(0, (sy[1] - sy[0]))))

Submission status: Accepted

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

w_min, w_max, h_min, h_max = 0, w, 0, h

for i in range(n):
    if plots[i][2] == 1:
        w_min = max(w_min, plots[i][0])
    elif plots[i][2] == 2:
        w_max = min(w_max, plots[i][0])
    elif plots[i][2] == 3:
        h_min = max(h_min, plots[i][1])
    else:
        h_max = min(h_max, plots[i][1])

print(max(0, (w_max - w_min)) * max(0, (h_max - h_min)))

Submission status: Accepted

Solution code:
# coding = SJIS

w, h, n = map(int, input().split())
points = []
area = [0, w, 0, h]

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

for i in range(n):
    if points[i][2] == 1:
        area[0] = max(area[0], points[i][0])
    if points[i][2] == 2:
        area[1] = min(area[1], points[i][0])
    if points[i][2] == 3:
        area[2] = max(area[2], points[i][1])
    if points[i][2] == 4:
        area[3] = min(area[3], points[i][1])

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

print(ans)

Submission status: Accepted

Solution code:
H,W,N=map(int,input().split())
sita,hidari=0,0
ue,migi=W,H
for i in range(N):
  x,y,a=map(int,input().split())
  if a==1:
    hidari=max(x,hidari)
  elif a==2:
    migi=min(migi,x)
  elif a==3:
    sita=max(sita,y)
  else:
    ue=min(ue,y)
print(max(0,(migi-hidari))*max(0,(ue-sita)))

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(max(0,(r-l))*max(u-d, 0))

Submission status: Accepted

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

x_min = 0
x_max = w
y_min = 0
y_max = h

for _ in range(n):
  x, y, a = map(int, input().split())
  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)

print(
  (x_max - x_min) * (y_max - y_min)
  if x_min < x_max and y_min < y_max else 0
)

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

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

lx = 0
rx = W
by = 0
ty = H
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        lx = max(lx, x)
    if a == 2:
        rx = min(rx, x)
    if a == 3:
        by = max(by, y)
    if a == 4:
        ty = min(ty, y)
if rx - lx < 0 or ty - by < 0:
    print(0)
else:
    s = (rx - lx) * (ty - by)
    print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

w,h,n = map(int,input().split())
b = np.zeros((h,w),dtype=np.int)

for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        b[:,:x] = 1
    elif a == 2:
        b[:,x:] = 1
    elif a == 3:
        b[:y,:] = 1
    else:
        b[y:,:] = 1
print(np.count_nonzero(b < 1))

Submission status: Accepted

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

list = [0, w, 0, h]

for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1 and list[0] <= x:
        list[0] = x
    elif a == 2 and list[1] >= x:
        list[1] = x
    elif a == 3 and list[2] <= y:
        list[2] = y
    elif a == 4 and list[3] >= y:
        list[3] = y
    else:
        pass

if list[0] > list[1] or list[2] > list[3]:
    print(0)
else:
    print((list[0] - list[1]) * (list[2] - list[3]))

Submission status: Accepted

Solution code:
#
# abc047 b
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """5 4 2
2 1 1
3 3 4"""
        output = """9"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """5 4 3
2 1 1
3 3 4
1 4 2"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """10 10 5
1 6 1
4 1 3
6 9 4
9 4 2
3 1 3"""
        output = """64"""
        self.assertIO(input, output)


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


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
a=[[int(i)for i in input().split()]for j in range(n)]
S=[[0,w],[0,h]]
for i in a:
    if i[2]==1:
        S[0][0]=max(i[0],S[0][0])

    if i[2]==2:
        S[0][1]=min(i[0],S[0][1])

    if i[2]==3:
        S[1][0]=max(i[1],S[1][0])

    if i[2]==4:
        S[1][1]=min(i[1],S[1][1])

ans=max(0,(S[0][1]-S[0][0]))*max(0,(S[1][1]-S[1][0]))
print(ans)

Submission status: Accepted

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

X = [True]*W
Y = [True]*H

for i in range(N):
    x, y, a = map(int,input().split())
    if a == 1:
        for j in range(x):
            X[j] = False
    if a == 2:
        for j in range(x,W):
            X[j] = False
    if a == 3:
        for j in range(y):
            Y[j] = False
    if a == 4:
        for j in range(y,H):
            Y[j] = False

ans = 0
for i in range(W):
    for j in range(H):
        if X[i] and Y[j]:
            ans += 1
            
print(ans)

Submission status: Accepted

Solution code:
W, H, n = map(int, input().split())
l = [[True]*W]*H
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        for h in range(H):
            for w in range(x):
                l[h][w] = False
    elif a == 2:
        for h in range(H):
            for w in range(x, W):
                l[h][w] = False
    elif a == 3:
        for h in range(y):
            l[h] = [False]*W
    else:
        for h in range(y, H):
            l[h] = [False]*W

ans = 0
for i in range(H):
    for j in range(W):
        if l[i][j]:
            ans += 1
print(ans)