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

print(w*h - count)

Submission status: Accepted

Solution code:
from typing import List


def answer(w: int, h: int, n: int, xyas: List[List[int]]) -> int:
    bottom_left_corner_of_white = {'x': 0, 'y': 0}
    top_right_corner_of_white = {'x': w, 'y': h}

    for xya in xyas:
        x, y, a = xya
        if a == 1:
            if bottom_left_corner_of_white['x'] < x:
                bottom_left_corner_of_white['x'] = x
        if a == 2:
            if x < top_right_corner_of_white['x']:
                top_right_corner_of_white['x'] = x
        if a == 3:
            if bottom_left_corner_of_white['y'] < y:
                bottom_left_corner_of_white['y'] = y
        if a == 4:
            if y < top_right_corner_of_white['y']:
                top_right_corner_of_white['y'] = y

    width_of_white = max(0, top_right_corner_of_white['x'] - bottom_left_corner_of_white['x'])
    height_of_white = max(0, top_right_corner_of_white['y'] - bottom_left_corner_of_white['y'])

    return width_of_white * height_of_white


def main():
    w, h, n = map(int, input().split())
    xyas = [list(map(int, input().split())) for _ in range(n)]
    print(answer(w, h, n, xyas))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
answ=set(range(w+1)) 
ansh=set(range(w+1))
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    answ=answ & set(range(x,w+1))
  elif a==2:
    answ=answ & set(range(x+1))
  elif a==3:
    ansh=ansh & set(range(y,h+1))
  elif a==4:
    ansh=ansh & set(range(y+1))
if len(answ) == 0 or len(ansh)==0:
  print(0)
else:
  print((max(answ)-min(answ))*(max(ansh)-min(ansh)))

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
p = [0]
q = [w]
r = [0]
s = [h]
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        p.append(x)
    elif a == 2:
        q.append(x)
    elif a == 3:
        r.append(y)
    else:
        s.append(y)
if max(p) <= min(q) and max(r) <= min(s):
    print((min(q) - max(p))*(min(s) - max(r)))
else:
    print(0)

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
r_w = w
l_w = 0
u_h = h
d_h = 0

for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        l_w = max(l_w, x)
    elif a == 2:
        r_w = min(r_w, x)
    elif a == 3:
        d_h = max(d_h, y)
    elif a == 4:
        u_h = min(u_h, y)

res = max(0, r_w - l_w) * max(0, u_h - d_h)
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(4100000)
import math
import itertools
INF = float('inf')
from heapq import heapify, heappop, heappush
import collections
import bisect

def main():
    w,h,n = map(int, input().split())
    X = []
    Y = []
    A = []
    for i in range(n):
        x,y,a = map(int, input().split())
        X.append(x)
        Y.append(y)
        A.append(a)

    plots = [[0,0], [w,0], [w,h], [0,h]]
    for i in range(n):
        if A[i] == 1:
            plots[0][0] = max(plots[0][0], X[i])
            plots[3][0] = max(plots[3][0], X[i])
        elif A[i] == 2:
            plots[1][0] = min(plots[1][0], X[i])
            plots[2][0] = min(plots[2][0], X[i])
        elif A[i] == 3:
            plots[0][1] = max(plots[0][1], Y[i])
            plots[1][1] = max(plots[1][1], Y[i])
        else:
            plots[2][1] = min(plots[2][1], Y[i])
            plots[3][1] = min(plots[3][1], Y[i])
    width = plots[1][0] - plots[0][0]
    height = plots[2][1] - plots[1][1]
    if width <= 0 or height <= 0:
        print(0)
        return
    print(width * height)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
c = [list(map(int,input().split())) for i in range(n)]
xmin = 0
xmax = w 
ymin = 0
ymax = h
for i in c:
    if i[2]==1:
        xmin = max(xmin,i[0])
    elif i[2]==2:
        xmax = min(xmax,i[0])
    elif i[2]==3:
        ymin = max(ymin,i[1])
    elif i[2]==4:
        ymax = min(ymax,i[1])
if xmax>xmin and ymax>ymin:
    print((xmax-xmin)*(ymax-ymin))
else:
    print(0)

Submission status: Accepted

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

W = int(lst[0])
H = int(lst[1])
N = int(lst[2])

field = [([0] * W)] * H

L = []

for i in range(N):
   L = input().split()
   if L[2] == '1':
      for j in range(H):
         for k in range(int(L[0])):
            field[j][k] = 1
   elif L[2] == '2':
      for j in range(H):
         for k in range(int(L[0]), W):
            field[j][k] = 1
   elif L[2] == '3':
      for j in range(int(L[1])):
         field[j] = [1] * W
   elif L[2] == '4':
      for j in range(int(L[1]), H):
         field[j] = [1] * W

ans = 0

for s in field:
   ans += s.count(0)

print(ans)

Submission status: Accepted

Solution code:
w, h, n = map(int,input().split())
left = 0
right = w
up = h
down = 0
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)
if up-down < 0 and right-left < 0:
    print(0)
else:
    print(max(0,(up-down)*(right-left)))

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
xl = []
yl = []
al = []
for _ in range(n):
  x,y,a = map(int,input().split())
  xl.append(x)
  yl.append(y)
  al.append(a)

sx = 0
gx = w
sy = 0
gy = h

for i in range(len(al)):
  if al[i] == 1 and sx < xl[i]:
      sx = xl[i]
      if sx > gx:
        print(0)
        exit()
  elif al[i] == 2 and gx > xl[i]:
      gx = xl[i]
      if sx > gx:
        print(0)
        exit()
  elif al[i] == 3 and sy < yl[i]:
      sy = yl[i]
      if sy > gy:
        print(0)
        exit()
  elif al[i] == 4 and gy > yl[i]:
      gy = yl[i]
      if sy > gy:
        print(0)
        exit()
  if i == len(al)-1:
    print((gx-sx)*(gy-sy))

Submission status: Accepted

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

s_w = [0, w]
s_h = [0, h]
for _ in range(n):
    x, y, a = list(map(int, input().split()))
    if a == 1 and x > s_w[0]:
        s_w[0] = x
    elif a == 2 and x < s_w[1]:
        s_w[1] = x
    elif a == 3 and y > s_h[0]:
        s_h[0] = y
    elif a == 4 and y < s_h[1]:
        s_h[1] = y

ans_w = s_w[1] - s_w[0]
ans_h = s_h[1] - s_h[0]
print((ans_w * (ans_w > 0)) * (ans_h * (ans_h > 0)))

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
data = list(input().split() for i in range(n))
x_1 = 0
x_2 = w
y_1 = 0
y_2 = h
for i in range(n):
    if int(data[i][2]) == 1:
        if int(data[i][0]) > x_1:
            x_1 = int(data[i][0])
    elif int(data[i][2]) == 2:
        if int(data[i][0]) < x_2:
            x_2 = int(data[i][0])
    elif int(data[i][2]) == 3:
        if int(data[i][1]) > y_1:
            y_1 = int(data[i][1])
    else:
        if int(data[i][1]) < y_2:
            y_2 = int(data[i][1])
if x_2 - x_1 <= 0 or y_2 - y_1 <= 0:
    print(0)
else:
    print((x_2 - x_1) * (y_2 - y_1))

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

def main():
    W, H, N = map(int, input().split())
    X = [0, W]
    Y = [0, H]
    for i in range(N):
        x, y, a = map(int, input().split())
        if a == 1:
            X[0] = max(x, X[0])
        elif a == 2:
            X[1] = min(x, X[1])
        elif a == 3:
            Y[0] = max(y, Y[0])
        else:
            Y[1] = min(y, Y[1])
    if X[1] <= X[0] or Y[1] <= Y[0]:
        ans = 0
    else:
        ans = (X[1] - X[0]) * (Y[1] - Y[0])
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    w,h,n = i_map()

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

    for i in range(n):
        x,y,a = i_map()
        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)
    print(max((up-down),0)*max((right-left),0))

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
class Combination:
    def __init__(self, n, mod):
        self.n = n
        self.mod = mod
        self.fac = [1 for i in range(self.n + 1)]
        self.finv = [1 for i in range(self.n + 1)]
        for i in range(2, self.n+1):
            self.fac[i] = (self.fac[i - 1] * i) % self.mod
            self.finv[i] = (self.finv[i - 1] * pow(i, -1, self.mod)) % self.mod

    def comb(self, n, m):
        return self.fac[n] * (self.finv[n - m] * self.finv[m] % self.mod) % self.mod
        
def iparse():
    return list(map(int, input().split()))


if __name__ == "__main__":
    w, h, n = iparse()
    xmax = w
    xmin = 0
    ymin = 0
    ymax = h
    for i in range(n):
        x, y, a = iparse()
        
        if a == 1:
            xmin = max(xmin,x)
        if a == 2:
            xmax = min(xmax,x)
        if a == 3:
            ymin = max(ymin,y)
        if a == 4:
            ymax = min(ymax,y)
        
    print((max(xmax-xmin,0)*(max(0,ymax-ymin))))

Submission status: Accepted

Solution code:
W,H,N= map(int,input().split())
Black = [[True for _ in range(W)] for i in range(H)]
for i in range(N):
    x,y,a = map(int,input().split())
    for j in range(H):
        for k in range(W):
            if a == 1:
                if k < x:
                    Black[j][k] = False
            elif a == 2:
                if k >= x:
                    Black[j][k] = False
            elif a == 3:
                if j < y:
                    Black[j][k] = False
            elif a == 4:
                if j >= y:
                    Black[j][k] = False
                    #print(Black)

c = 0
#print(Black)
for i in range(H):
    c += Black[i].count(True)
print(c)

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
A = [list(map(int,input().split())) for i in range(n)]
sx,sy=0,0
for j in range(n):
    
    if A[j][2]==1 and sx<A[j][0]:
        sx=A[j][0]

    if A[j][2]==2 and w>A[j][0]:
        w=A[j][0]

    if A[j][2]==3 and sy<A[j][1]:
        sy=A[j][1]

    if A[j][2]==4 and h>A[j][1]:
        h=A[j][1]

if (w-sx)<0 or (h-sy)<0 :
    print(0)
else:
    print((w-sx)*(h-sy))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
a1, a2, a3, a4 = [], [], [], []
for _ 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)

max_x = max(a1) if a1 else 0
min_x = min(a2) if a2 else W
max_y = max(a3) if a3 else 0
min_y = min(a4) if a4 else H
ans = max(0, min_x - max_x) * max(0, min_y - max_y)
print(ans)

Submission status: Accepted

Solution code:

url = "https://atcoder.jp//contests/abc047/tasks/abc047_b"

def main():
    w, h, n = list(map(int, input().split()))
    xya = [list(map(int, input().split())) for _ in range(n)]
    x, y = [0, w], [0, h]
    for low in xya:
        if low[2] == 1 and x[0] < low[0]:
            x[0] = low[0]
        elif low[2] == 2 and x[1] > low[0]:
            x[1] = low[0]
        elif low[2] == 3 and y[0] < low[1]:
            y[0] = low[1]
        elif low[2] == 4 and y[1] > low[1]:
            y[1] = low[1]
    xs = x[1] - x[0]
    ys = y[1] - y[0]
    if xs < 0 or ys < 0:
        print(0)
    else:
        ans = xs * ys
        print(ans)



if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(N):
    if a[i] == 1:
        xmin = max(x[i], xmin)
    elif a[i] == 2:
        xmax = min(x[i], xmax)
    elif a[i] == 3:
        ymin = max(y[i], ymin)
    else:
        ymax = min(y[i], ymax)

height = ymax - ymin
width = xmax - xmin

if height <= 0 or width <= 0:
    print(0)
else:
    print(height * width)

Submission status: Accepted

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

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

# print(max_x, max_y)
# print(min_x, min_y)
if(min_x > max_x) and (min_y > max_y):
    print((min_x - max_x) * (min_y - max_y))
else:
    print(0)

Submission status: Accepted

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

xl, xr = 0, w
yl, yu = 0, h
for i in range(n):
    x, y, a = map(int,input().split())
    if a == 1:
        xl = max(xl, x)
    elif a == 2:
        xr = min(xr, x)
    elif a == 3:
        yl = max(yl, y)
    else:
        yu = min(yu, y)
        
print((xr-xl)*(yu-yl)) if xl < xr and yl < yu else print(0)

Submission status: Accepted

Solution code:
W, H, N = list(map(int, input().split()))
X = []
Y = []
A = []
field = [[0] * W for _ in range(H)]
for i in range(N):
    x, y, a = list(map(int, input().split()))
    X.append(x)
    Y.append(y)
    A.append(a)

for i in range(N):
    if A[i] == 1:
        for j in range(X[i]):
            for k in range(H):
                field[k][j] = 1
    elif A[i] == 2:
        for j in range(X[i], W):
            for k in range(H):
                field[k][j] = 1
    elif A[i] == 3:
        for j in range(W):
            for k in range(Y[i]):
                field[k][j] = 1
    else:
        for j in range(W):
            for k in range(Y[i], H):
                field[k][j] = 1

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

print(Sum)

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
r, l, u, d = w, 0, h, 0
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:
        d = max(d, y)
    else:
        u = min(u, y)
print(max(0, r-l) * max(0, u-d))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 63 B - すぬけ君の塗り絵 2 イージー
W,H,N = map(int,input().split())

X = []
Y = []
A = []
for _ in range(N):
    x,y,a = map(int,input().split())
    x -= 1;y -= 1
    X.append(x)
    Y.append(y)
    A.append(a)

mtrx = [['.']*W for _ in range(H)]

for a,(x,y) in zip(A,zip(X,Y)):
    if a == 1:
        for i in range(H):
            for j in range(x+1):
                mtrx[i][j] = '#'
    if a == 2:
        for i in range(H):
            for j in range(x+1,W):
                mtrx[i][j] = '#'
    if a == 3:
        for i in range(y+1):
            mtrx[i] = ['#']*W
    if a == 4:
        for i in range(y+1,H):
            mtrx[i] = ['#']*W

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

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
x1, x2, y1, y2 = 0, W, 0, H
for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        x1 = max(x1, x)
    elif a == 2:
        x2 = min(x2, x)
    elif a == 3:
        y1 = max(y1, y)
    elif a == 4:
        y2 = min(y2, y)

print(max(0, (y2 - y1)) * max(0, (x2 - x1)))

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x):
        self.setdefault(x,0)
        self[x] += 1

W,H,N = mint()
rec = [[1]*H for _ in range(W)]

for _ in range(N):
    X,Y,a = mint()
    if a==1:
        for x in range(X):
            for y in range(H):
                rec[x][y] = 0
    if a==2:
        for x in range(X,W):
            for y in range(H):
                rec[x][y] = 0
    if a==3:
        for x in range(W):
            for y in range(Y):
                rec[x][y] = 0
    if a==4:
        for x in range(W):
            for y in range(Y,H):
                rec[x][y] = 0
print(sum(map(sum,rec)))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

W, H, N = map(int, input().split())
xs = ys = 0
xe = W
ye = H
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1 and x > xs:
        xs = x
    elif a == 2 and x < xe:
        xe = x
    elif a == 3 and y > ys:
        ys = y
    elif a == 4 and y < ye:
        ye = y

w = xe - xs
h = ye - ys
if w > 0 and h > 0:
    ans = w * h
else:
    ans = 0

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
def input():
    return sys.stdin.readline()[:-1]

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

    lx = 0
    rx = W
    uy = H
    dy = 0
    for i in range(N):
        if a[i] == 1:
            lx = max(lx, x[i])
        if a[i] == 2:
            rx = min(rx, x[i])
        if a[i] == 3:
            dy = max(dy, y[i])
        if a[i] == 4:
            uy = min(uy, y[i])
    X = rx - lx
    Y = uy - dy
    ans = X * Y
    if X < 0 or Y < 0:
        ans = 0
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
s=0
b=w
t=0
c=h

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

Submission status: Accepted

Solution code:
import numpy as np


def main():
    w, h, n = map(int, input().split())
    xyas = [list(map(int, input().split())) for _ in range(n)]
    board = np.array([[0 for i in range(w)] for j in range(h)])
    for x, y, a in xyas:
        if a == 1:
            board[:, :x] = 1
        elif a == 2:
            board[:, x:] = 1
        elif a == 3:
            board[-y:, :] = 1
        elif a == 4:
            board[:-y, :] = 1
    ans = (w*h) - np.sum(board)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

ans=[0,W,0,H]

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

S=(ans[1]-ans[0])*(ans[3]-ans[2])  

if (ans[1]-ans[0])<0:
    print(0)
elif (ans[3]-ans[2])<0:
    print(0)
else:
    print(S)

Submission status: Accepted

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

Submission status: Accepted

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

sx, sy = 0, 0
for x, y, a in query:
    if a == 1:
        sx = max(sx, x)
    elif a == 2:
        w = min(w, x)
    elif a == 3:
        sy = max(sy, y)
    else:
        h = min(h, y)
print(max(0, w - sx) * max(0, h - sy))

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
xya = [list(map(int, input().split())) for _ in range(n)]
x, y, a = zip(*xya)
xl, xr, yb, yt = 0, w, 0, h
for i in range(n):
    if   a[i] == 1: xl = max(xl, x[i])
    elif a[i] == 2: xr = min(xr, x[i])
    elif a[i] == 3: yb = max(yb, y[i])
    else:           yt = min(yt, y[i])
print((xr-xl)*(yt-yb)*(xr>xl and yt>yb))

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
u, U, v, V = 0, W, 0, H
for _ in range(N):
    x, y, a = map(int,input().split())
    if a == 1:
        u = max(u,x)
    if a == 2:
        U = min(U,x)
    if a == 3:
        v = max(v,y)
    if a == 4:
        V = min(V,y)
f = lambda x:x if x > 0 else 0
print(f(U-u)*f(V-v))

Submission status: Accepted

Solution code:
import numpy as np

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

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

print((w*h) - int(area.sum()))

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def main():
    W, H, N = map(int, input().split())
    mat = [[1] * W for _ in range(H)]
    for _ in range(N):
        x, y, a = map(int, input().split())
        if a == 1:
            for i in range(H):
                for j in range(x):
                    mat[i][j] = 0
        if a == 2:
            for i in range(H):
                for j in range(x, W):
                    mat[i][j] = 0
        if a == 3:
            for i in range(y):
                for j in range(W):
                    mat[i][j] = 0
        if a == 4:
            for i in range(y, H):
                for j in range(W):
                    mat[i][j] = 0
    ans = 0
    for i in range(H):
        for j in range(W):
            ans += mat[i][j]
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
bl_x, tr_x, bl_y, tr_y = 0, W, 0, H
for i in range(N):
	x, y, a = map(int, input().split())
	if a == 1:
		bl_x = max(bl_x, x)
	elif a == 2:
		tr_x = min(tr_x, x)
	elif a == 3:
		bl_y = max(bl_y, y)
	elif a == 4:
		tr_y = min(tr_y, y)
print(max(tr_x - bl_x, 0) * max(tr_y - bl_y, 0))

Submission status: Accepted

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    w,h,n = LI()
    board = [[1]*h for _ in range(w)]

    for _ in range(n):
        x,y,a = LI()
        if a == 1:
            for i in range(x):
                board[i] = [0 for _ in range(h)]
        elif a == 2:
            for i in range(x,w):
                board[i] = [0 for _ in range(h)]
        elif a == 3:
            for i in range(w):
                for j in range(y):
                    board[i][j] = 0
        elif a == 4:
            for i in range(w):
                for j in range(y,h):
                    board[i][j] = 0

    ans = 0
    for line in board:
        ans += sum(line)

    print(ans)

    # print(*board,sep="\n")
main()

Submission status: Accepted

Solution code:
# vim: fileencoding=utf-8


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


if __name__ == "__main__":
    main()