Problem:


Score : 200 points

Problem Statement

There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white.

Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i).

Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows:

If a_i = 1, he painted the region satisfying x < x_i within the rectangle.

If a_i = 2, he painted the region satisfying x > x_i within the rectangle.

If a_i = 3, he painted the region satisfying y < y_i within the rectangle.

If a_i = 4, he painted the region satisfying y > y_i within the rectangle.

Find the area of the white region within the rectangle after he finished painting.

Constraints

1 ≦ W, H ≦ 100

1 ≦ N ≦ 100

0 ≦ x_i ≦ W (1 ≦ i ≦ N)

0 ≦ y_i ≦ H (1 ≦ i ≦ N)

W, H (21:32, added), x_i and y_i are integers.

a_i (1 ≦ i ≦ N) is 1, 2, 3 or 4.

Input

The input is given from Standard Input in the following format:

W H N
x_1 y_1 a_1
x_2 y_2 a_2
:
x_N y_N a_N

Output

Print the area of the white region within the rectangle after Snuke finished painting.

Sample Input 1

5 4 2
2 1 1
3 3 4

Sample Output 1

9

The figure below shows the rectangle before Snuke starts painting.

First, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x < 2 within the rectangle:

Then, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y > 3 within the rectangle:

Now, the area of the white region within the rectangle is 9.

Sample Input 2

5 4 3
2 1 1
3 3 4
1 4 2

Sample Output 2

0

It is possible that the whole region within the rectangle is painted black.

Sample Input 3

10 10 5
1 6 1
4 1 3
6 9 4
9 4 2
3 1 3

Sample Output 3

64



Sample input:
5 4 2
2 1 1
3 3 4


Sample output:
9

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
x = [0 for i in range(N)]
y = [0 for i in range(N)]
a = [0 for i in range(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 and x[i] >= xmin:
        xmin = x[i]
    elif a[i] == 2 and x[i] <= xmax:
        xmax = x[i]
    elif a[i] == 3 and y[i] >= ymin:
        ymin = y[i]
    elif a[i] == 4 and y[i] <= ymax:
        ymax = y[i]
        
if xmax >= xmin and ymax >= ymin:
    print((xmax-xmin)*(ymax-ymin))
else:
    print(0)

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
x=[]
y=[]
a=[]
w=[i for i in range(W+1)]
h=[i for i in range(H+1)]
S=W*H

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

for i in range(len(x)):
    if a[i]==1 and len(w)!=0:
        for j in range(x[i]):
            if j in w: w.remove(j)
    if a[i]==2 and len(w)!=0:
        for j in reversed(range(x[i]+1,w[-1]+1)):
            if j in w: w.remove(j)
    if a[i]==3 and len(h)!=0:
        for j in range(y[i]):
            if j in h: h.remove(j)
    if a[i]==4 and len(h)!=0:
        for j in reversed(range(y[i]+1,h[-1]+1)):
            if j in h: h.remove(j)
if len(w)==0 or len(h)==0:
    print(0)
else:
    S_f = (w[-1]-w[0]) * (h[-1]-h[0])
    print(S_f)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
mat = [list(map(int,input().split())) for i in range(N)]
tmp = [0]*W
tmp = [tmp]*H
for i in range(N):
    if mat[i][2] == 1:
        for j in range(H):
            for k in range(mat[i][0]):
                tmp[j][k] = 1
    elif mat[i][2] == 2:
        for j in range(H):
            for k in range(mat[i][0],W):
                tmp[j][k] = 1
    elif mat[i][2] == 3:
        for j in range(0,mat[i][1]):
            tmp[j] = [1]*W
    else:
        for j in range(mat[i][1],H):
            tmp[j] = [1]*W
print(max([W*H-sum(list(map(sum,tmp))),0]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
min_x = 0
min_y = 0
w = W
h = H
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1: min_x = max(min_x, x)
    elif a == 2: w = min(w, x)
    elif a == 3: min_y = max(min_y, y)
    elif a == 4: h = min(h, y)
print((w-min_x)*(h-min_y) if (w-min_x)>0 and (h-min_y)>0 else 0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
W, H, N = [int(x) for x in input().split()]
matrix = np.array([[1 for i in range(W)] for j in range(H)])
rects = []
for i in range(N):
    rects.append([int(x) for x in input().split()])
for rect in rects:
    if rect[2] == 1:
        matrix[:, :rect[0]] = 0
    elif rect[2] == 2:
        matrix[:, rect[0]:] = 0
    elif rect[2] == 3:
        matrix[:rect[1], :] = 0
    elif rect[2] == 4:
        matrix[rect[1]:, :] = 0
print(sum(sum(matrix)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
u = H
d = 0
r = W
l = 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)
h = u - d
w = r - l
if h < 0:
    ans = 0
elif w < 0:
    ans = 0
else:
    ans = w*h
print(ans)

Submission status: Accepted

Solution code:
# python3 (3.4.3)
import sys
input = sys.stdin.readline

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

x_lb,x_ub,y_lb,y_ub = 0,W,0,H

for x,y,a in XYA:
    if a==1:
        x_lb = max(x_lb,x)
    elif a==2:
        x_ub = min(x_ub,x)
    elif a==3:
        y_lb = max(y_lb,y)
    else:
        y_ub = min(y_ub,y)

x = max(0, x_ub - x_lb)
y = max(0, y_ub - y_lb)

print(x*y)

Submission status: Accepted

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

    R = []
    for _ in range(N):
        R.append(tuple(map(int, input().split())))

    # print("W, H, N", W, H, N)
    # print(R)

    table = [[0 for x in range(W + 1)] for y in range(H + 1)]

    for x, y, a in R:
        # print(x, y, "|", a)
        y = H - y
        # 1: x より小さい左側の領域
        if a == 1:
            for yi in range(H + 1):
                for xi in range(x):
                    table[yi][xi] = "*"
        # 2: x より大きい右側の領域
        elif a == 2:
            for yi in range(H + 1):
                for xi in range(x + 1, W + 1):
                    table[yi][xi] = "*"
        # 3: 長方形の H < y を塗る
        elif a == 3:
            for yi in range(y + 1, H + 1):
                for xi in range(W + 1):
                    table[yi][xi] = "*"
        # 4: 長方形の H > y を塗る
        elif a == 4:
            for yi in range(y - 1, -1, -1):
                for xi in range(W + 1):
                    table[yi][xi] = "*"

    # 白い長方形の左下の座標を探す
    left_bottom = -1, -1
    is_found = False
    for yi in range(H + 1):
        yii = H - yi
        for xi in range(W + 1):
            if table[yii][xi] == 0:
                left_bottom = xi, yi
                is_found = True
                break
        if is_found:
            break

    # 白い長方形の右上の座標を探す
    right_top = -1, -1
    is_found = False
    for yi in range(H + 1):
        for xi in range(W, -1, -1):
            if table[yi][xi] == 0:
                right_top = xi, H - yi
                is_found = True
                break
        if is_found:
            break

    # print(left_bottom, right_top)
    if left_bottom == (-1, -1) and right_top == (-1, -1):
        return 0
    else:
        return (right_top[0] - left_bottom[0]) * (right_top[1] - left_bottom[1])


if __name__ == '__main__':
    res = solve()
    print(res)

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
ux=w
lx=0
uy=h
ly=0
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        lx=max(lx,x)
    if a==2:
        ux=min(ux,x)
    if a==3:
        ly=max(ly,y)
    if a==4:
        uy=min(uy,y)
print(max(ux-lx,0)*max(uy-ly,0))

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
xyalist = [tuple(map(int, input().split())) for _ in range(N)]
points = [[0, 0], [W, H]]
for x, y, a in xyalist:
    if a == 1:
        if x > points[0][0]:
            points[0][0] = x
    elif a == 2:
        if x < points[1][0]:
            points[1][0] = x
    elif a == 3:
        if y > points[0][1]:
            points[0][1] = y
    elif a == 4:
        if y < points[1][1]:
            points[1][1] = y
area = -1
if (points[1][0] - points[0][0]) > 0 and (points[1][1] - points[0][1]) > 0:
    area = (points[1][0] - points[0][0]) * (points[1][1] - points[0][1])

print(area if area > 0 else 0)

Submission status: Accepted

Solution code:
def examB():
    W, H, N = LI()
    height = [0,H]; width = [0,W]
    for i in range(N):
        x, y, a = LI()
        if a==1:
            width[0] = max(width[0],x)
        elif a==2:
            width[1] = min(width[1],x)
        elif a==3:
            height[0] = max(height[0],y)
        elif a==4:
            height[1] = min(height[1],y)
    ans = max(width[1]-width[0],0)*max(height[1]-height[0],0)
    print(ans)

import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examB()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

w,h,n = inpl()
a = [inpl() for i in range(n)]
sq = [[False] * w for i in range(h)]
for i in a:
    if i[2] == 1:
        for x in range(i[0]):
            for y in range(h):
                sq[y][x] = True
    elif i[2] == 2:
       for x in range(i[0],w):
            for y in range(h):
                sq[y][x] = True
    elif i[2] == 3:
        for y in range(i[1]):
            for x in range(w):
                sq[y][x] = True
    else:
        for y in range(i[1],h):
            for x in range(w):
                sq[y][x] = True
res = 0
for i in range(h):
    res += sq[i].count(False)
print(res)

Submission status: Accepted

Solution code:
# ABC 047: B – すぬけ君の塗り絵 2 イージー / Snuke's Coloring 2 (ABC Edit)
w, h, n = [int(s) for s in input().split()]

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

w_start = 0
h_start = 0

for i in range(n):
    if a[i] == 1:
        if w_start < x[i]:
            w_start = x[i]
    elif a[i] == 2:
        if w > x[i]:
            if x[i] > w_start:
                w = x[i]
            else:
                w = w_start
    elif a[i] == 3:
        if h_start < y[i]:
            h_start = y[i]
    elif a[i] == 4:
        if h > y[i]:
            if y[i] > h_start:
                h = y[i]
            else:
                h = h_start

print((w - w_start) * (h - h_start))

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
Xl=0
Xr=W
Yu=0
Yh=H

for i in range(N):
    Xt,Yt,At = map(int,input().split())
    if((At==1)and(Xl<Xt)):
        Xl=Xt
    elif((At==2)and(Xr>Xt)):
        Xr=Xt
    elif((At==3)and(Yu<Yt)):
        Yu=Yt
    elif((At==4)and(Yh>Yt)):
        Yh=Yt

if((Xr<=Xl)or(Yh<=Yu)):
    print("0")
else:
    print((Xr-Xl)*(Yh-Yu))

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
ux=w
lx=0
uy=h
ly=0
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    lx=max(lx,x)
  if a==2:
    ux=min(ux,x)
  if a==3:
    ly=max(ly,y)
  if a==4:
    uy=min(uy,y)
print(max(0,ux-lx)*max(0,uy-ly))

Submission status: Accepted

Solution code:
import numpy as np

W,H,N=[int(i) for i in input().split()]
lst=[]
for j in range(N):
    lst.append([int(i) for i in input().split()])
#print(lst)

square=np.zeros(H*W,dtype=np.int64).reshape(H,W)
#print(square)

for i in lst:
    x=i[0]
    y=i[1]
    a=i[2]
    if(a==1):
        for j in range(x):
            for k in range(H):
                square[k][j]=1
        #print(square)
    elif(a==2):
        for j in range(x,W):
            for k in range(H):
                square[k][j]=1
        #print(square)
    elif(a==3):
        for j in range(H-y,H):
            for k in range(W):
                square[j][k]=1
        #print(square)
    else:
        for j in range(H-y-1,-1,-1):
            for k in range(W):
                square[j][k]=1
        #print(square)

print(np.count_nonzero(square ==0))

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
l=0;r=W;d=0;u=H
for i in range(N):
    x,y,a=map(int,input().split())
    if a==1:
        l=max(l,x)
    elif a==2:
        r=min(r,x)
    elif a==3:
        d=max(d,y)
    elif a==4:
        u=min(u,y)
print(max(r-l,0)*max(u-d,0))

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
x_b=w
x_s=0
y_b=h
y_s=0
for i in range(1,n+1):
  x,y,a=map(int,input().split())
  if a==2:
    x_b=min(x,x_b)
  elif a==1:
    x_s=max(x,x_s)
  elif a==4:
    y_b=min(y,y_b)
  else:
    y_s=max(y,y_s)

if x_b<=x_s or y_b<=y_s:
  print(0)
else:  
  print((x_b-x_s)*(y_b-y_s))

Submission status: Accepted

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

ans = 0
for i in range(h):
    for j in range(w):
        if c[i][j] == 0:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
min_x = 0
min_y = 0
max_x = w
max_y = h

for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1 and min_x < x:
        min_x = x
    elif a == 2 and max_x > x:
        max_x = x
    elif a == 3 and min_y < y:
        min_y = y
    elif a == 4 and max_y > y:
        max_y = y

diff_x = max_x - min_x
diff_y = max_y - min_y

if diff_x < 0:
    diff_x = 0
if diff_y < 0:
    diff_y = 0
    
area = diff_x * diff_y
print(area)

Submission status: Accepted

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

l = 0
r = w
d = 0
u = h

for x in li:
    if(x[-1] == 1):
        l = max(l, x[0])
    elif (x[-1] == 2):
        r = min(r, x[0])
    elif (x[-1] == 3):
        d = max(d, x[1])
    else:
        u = min(u, x[1])

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

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
lw=0;rw=w;lh=0;rh=h
for _ in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    lw=max(lw,x)
  elif a==2:
    rw=min(rw,x)
  elif a==3:
    lh=max(lh,y)
  else:
    rh=min(rh,y)
print(max(0,(rh-lh))*max((rw-lw),0))

Submission status: Accepted

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

minx = 0
maxx = W
miny = 0
maxy = H

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

    if a == 1:
        minx = max(minx, x)
    elif a == 2:
        maxx = min(maxx, x)
    elif a == 3:
        miny = max(miny, y)
    else:
        maxy = min(maxy, y)

    ans = (maxx - minx) * (maxy - miny)

print(ans if minx < maxx and miny < maxy else 0)

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

r = w
l = 0
t = h
b = 0

for i in range(n):
    if a[i] == 1 and l < x[i]:
        l = x[i]
    elif a[i] == 2 and r > x[i] :
        r = x[i]
    elif a[i] == 3 and b < y[i]:
        b = y[i]
    elif a[i] == 4 and t > y[i]:
        t = y[i]

area = [[0 for i in range(l, r)] for i in range(b, t)]

area = sum(area, [])

print(area.count(0))

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
G = {1:[],2:[],3:[],4:[]}
for _ in range(N):
    x,y,a = map(int,input().split())
    if a==1 or a==2:
        G[a].append(x)
    else:
        G[a].append(y)
xmin = 0
xmax = W
ymin = 0
ymax = H
if len(G[1])>0:
    xmin = max(G[1])
if len(G[2])>0:
    xmax = min(G[2])
if len(G[3])>0:
    ymin = max(G[3])
if len(G[4])>0:
    ymax = min(G[4])
if xmax>=xmin and ymax>=ymin:
    print((xmax-xmin)*(ymax-ymin))
else:
    print(0)

Submission status: Accepted

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

x_min = 0
y_min = 0
x_max = w
y_max = h
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1 and x_min < x:
        x_min = x
    elif a == 2 and x_max > x:
        x_max = x
    elif a == 3 and y_min < y:
        y_min = y
    elif a == 4 and y_max > y:
        y_max = y
if x_max < x_min or y_max < y_min:
    print(0)
else:
    print((x_max - x_min) * (y_max - y_min))

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
L = []
for i in range(n):
  L.append([int(i) for i in input().split()])
Z = [[1]*w for i in range(h)]

for i in range(n):
  if L[i][2] == 1:
    for j in range(h):
      for k in range(w):
        if k < L[i][0]:
          Z[j][k] = 0
  elif L[i][2] == 2:
    for j in range(h):
      for k in range(w):
        if k >= L[i][0]:
          Z[j][k] = 0
  elif L[i][2] == 3:
    for j in range(h):
      for k in range(w):
        if j < L[i][1]:
          Z[j][k] = 0
  elif L[i][2] == 4:
    for j in range(h):
      for k in range(w):
        if j >= L[i][1]:
          Z[j][k] = 0
          
out = 0
for i in range(h):
  for j in range(w):
    out += Z[i][j]
print(out)

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
x = []
y = []
a = []
l = [0, 0]
r = [w, h]
for i in range(n):
    s, t, u = map(int, input().split())
    x.append(s)
    y.append(t)
    a.append(u)
#白い部分の左下と右上の二点の座標を求める
for j in range(n):
    if a[j] == 1: #左側を黒にする
        if x[j] >= r[0]:
            S = 0
            break
        elif x[j] >= l[0]:
            l[0] = x[j]
    if a[j] == 2: #右側を黒にする
        if x[j] <= l[0]:
            S = 0
            break
        elif x[j]  <= r[0]:
            r[0] = x[j]
    if a[j] == 3: #下側を黒にする
        if y[j] >= r[1]:
            S = 0
            break
        elif y[j] >= l[1]:
            l[1] = y[j]
    if a[j] == 4: #上側を黒にする
        if y[j] <= l[1]:
            S = 0
            break
        elif y[j] <= r[1]:
            r[1] = y[j]
    S = (r[0] - l[0]) * (r[1] - l[1])
print(S)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, atan2, degrees
from operator import mul
from functools import reduce
sys.setrecursionlimit(10**8)

INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


w, h, n = LI()
l, r, u, d = 0, w, h, 0
for _ in range(n):
    x, y, a = LI()
    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)




if u < d or r < l:
    print(0)
else:
    print((u - d) * (r - l))

Submission status: Accepted

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

ll_ur = [0, w, 0, h]  # lower_left, upper_right corner

dic = dict(enumerate(ll_ur, 1))

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1 and dic[a] < x:
        dic[a] = x
    if a == 2 and dic[a] > x:
        dic[a] = x
    if a == 3 and dic[a] < y:
        dic[a] = y
    if a == 4 and dic[a] > y:
        dic[a] = y

if dic[1] < dic[2] and dic[3] < dic[4]:
    ans = (dic[2] - dic[1]) * (dic[4] - dic[3])
else: 
    ans = 0

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

points = []
for x in range(w):
  rows = []
  for y in range(h):
    rows.append(0)
  points.append(rows)

for i in range(n):
  x, y, a = list(map(int, input().split()))
  if a == 1:
    for row_index, row in enumerate(points):
      for col_index, col in enumerate(row):
        if row_index < x:
          points[row_index][col_index] = 1
  if a == 2:
    for row_index, row in enumerate(points):
      for col_index, col in enumerate(row):
        if row_index >= x:
          points[row_index][col_index] = 1
  if a == 3:
    for row_index, row in enumerate(points):
      for col_index, col in enumerate(row):
        if col_index < y:
          points[row_index][col_index] = 1
  if a == 4:
    for row_index, row in enumerate(points):
      for col_index, col in enumerate(row):
        if col_index >= y:
          points[row_index][col_index] = 1

count = 0
for row_index, row in enumerate(points):
  for col_index, col in enumerate(row):
    if points[row_index][col_index] == 0:
      count += 1
print(count)

Submission status: Accepted

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

minX, maxX, minY, maxY = 0, w, 0, h
for i in range(n):
    if x_y_a[i][2] == 1 and x_y_a[i][0] > minX: # paint x < xi
        minX = x_y_a[i][0]
    elif x_y_a[i][2] == 2 and x_y_a[i][0] < maxX: # paint x > xi
        maxX = x_y_a[i][0]
    elif x_y_a[i][2] == 3 and x_y_a[i][1] > minY: # paint y < yi
        minY = x_y_a[i][1]
    elif x_y_a[i][2] == 4 and x_y_a[i][1] < maxY: # paint y > yi
        maxY = x_y_a[i][1]

xl = maxX - minX
yl = maxY - minY
if xl > 0 and yl > 0:
    print(xl * yl)
else:
    print(0)

Submission status: Accepted

Solution code:
# ABC047 B - すぬけ君の塗り絵 2 イージー / Snuke's Coloring 2 (ABC Edit)
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

W,H,N = nl()

ans = 0
x_l,y_u = 0,0
x_r,y_o = 101,101

for i in range(N):
    x,y,a = nl()
    if a==1:
        x_l = max(x_l,x)
    elif a==2:
        x_r = min(x_r,x)
    elif a==3:
        y_u = max(y_u,y)
    elif a==4:
        y_o = min(y_o,y)

if x_r==101:
    x_r = W
if y_o == 101:
    y_o = H

if x_r > x_l and y_o > y_u:
    ans = (x_r-x_l)*(y_o-y_u)
else:
    ans = 0

print(ans)

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
tatemax=[h]
tatemin=[0]
yokomax=[w]
yokomin=[0]
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        yokomin.append(x)      
    elif a==2:
        yokomax.append(x)       
    elif a==3:
        tatemin.append(y)    
    elif a==4:
        tatemax.append(y)
        
tate_max=min(tatemax)
tate_min=max(tatemin)
yoko_max=min(yokomax)
yoko_min=max(yokomin)
if tate_max<=tate_min or yoko_max<=yoko_min:
    print(0)
else:
    print((tate_max-tate_min)*(yoko_max-yoko_min))

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N):
    if ary[i][2] == 1:
        for j in range(W):
            if j < ary[i][0]:
                for k in range(H):
                    rec[k][j] = 0
    elif ary[i][2] == 2:
        for j in range(W):
            if j >= ary[i][0]:
                for k in range(H):
                    rec[k][j] = 0
    elif ary[i][2] == 3:
        for j in range(H):
            if j < ary[i][1]:
                for k in range(W):
                    rec[j][k] = 0
    elif ary[i][2] == 4:
        for j in range(H):
            if j >= ary[i][1]:
                for k in range(W):
                    rec[j][k] = 0
print(sum(sum(i) for i in rec))

Submission status: Accepted

Solution code:
W, H, N = list(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)
    if a==2: r = min(r,x)
    if a==3: d = max(d,y)
    if a==4: 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())
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(x,l)
    elif a == 2:
        r = min(x,r)
    elif a == 3:
        d = max(y,d)
    else:
        u = min(y,u)
print(max((r-l),0)*max((u-d),0))

Submission status: Accepted

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

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

for i in range(N):
    if XYA[i][2]==1:
        X[0]=max(X[0],XYA[i][0])
    elif XYA[i][2]==2:
        X[1]=min(X[1],XYA[i][0])
    elif XYA[i][2]==3:
        Y[0]=max(Y[0],XYA[i][1])
    else:
        Y[1]=min(Y[1],XYA[i][1])

if X[1]-X[0]<=0 or Y[1]-Y[0]<=0:
    print(0)
else:
    print((X[1]-X[0])*(Y[1]-Y[0]))

Submission status: Accepted

Solution code:
import numpy as np
w,h,n=map(lambda x: int(x), input().split())
lec=np.array([[True for _ in range(w)] for _ in range(h)])
for i in range(n):
    x,y,a=map(lambda x: int(x), input().split())
    if a==1:
        lec[:,:x]=False
    elif a==2:
        lec[:,x:]=False
    elif a==3:
        lec[:y,:]=False
    elif a==4:
        lec[y:,:]=False
print(np.count_nonzero(lec))

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(x,l)
    elif a == 2:
        r = min(x,r)
    elif a == 3:
        d = max(y,d)
    else:
        u = min(y,u)
print(max((r-l),0)*max((u-d),0))

Submission status: Accepted

Solution code:
def main():
    W, H, N = map(int, input().split())
    lx = 0
    rx = W
    by = 0
    ty = H

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

        if a == 1:
            lx = max(x, lx)
        if a == 2:
            rx = min(x, W, rx)
        if a == 3:
            by = max(y, by)
        if a == 4:
            ty = min(y, H, ty)

    print(max(rx-lx, 0) * max(ty-by, 0))


main()

Submission status: Accepted

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

def adjust(x, y, a, S, F):
	if a == 1:
		S[0] = max(x, S[0])
	elif a == 2:
		F[0] = min(x, F[0])
	elif a == 3:
		S[1] = max(y, S[1])
	else:
		F[1] = min(y, F[1])

for l in L:
	adjust(l[0], l[1], l[2] ,S ,F)

dX = F[0]-S[0]
dY = F[1]-S[1]

if dX <= 0 or dY <= 0:
	print(0)
else:
	print(dX*dY)

Submission status: Accepted

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

CoordinateList1 = []
CoordinateList2 = []
CoordinateList3 = []
CoordinateList4 = []
for i in range(N):
    x,y,a = map(int, input().split())
    if a == 1:
        CoordinateList1.append(x)
    elif a == 2:
        CoordinateList2.append(x)
    elif a == 3:
        CoordinateList3.append(y)
    elif a == 4:
        CoordinateList4.append(y)
# X
a1 = 0
if sorted(CoordinateList1) != []:
    a1 = sorted(CoordinateList1)[-1]
a2 = W
if sorted(CoordinateList2) != []:
    a2 = sorted(CoordinateList2)[0]

# Y
a3 = 0
if sorted(CoordinateList3) != []:
    a3 = sorted(CoordinateList3)[-1]
a4 = H
if sorted(CoordinateList4) != []:
    a4 = sorted(CoordinateList4)[0]

if (int(a2)-int(a1)) > 0 and (int(a4)-int(a3)) > 0:
    print((int(a2)-int(a1))*(int(a4)-int(a3)))
else:
    print(0)