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())
xya = [list(map(int, input().split())) for _ in range(N)]

w = [0, W]
h = [0, H]
for x, y, a in xya:
  if a == 1 and w[0] < x:
    w[0] = x
  elif a == 2 and w[1] > x:
    w[1] = x
  elif a == 3 and h[0] < y:
    h[0] = y
  elif a == 4 and h[1] > y:
    h[1] = y

if w[0] < w[1] and h[0] < h[1]:
  print(abs(w[0] - w[1]) * abs(h[0] - h[1]))
else: print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

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

grid = np.zeros((H, W), dtype=int)
for _ in range(N):
    x, y, a = map(int, input().split())

    if a == 1:
        grid[:, :x] = 1
    elif a == 2:
        grid[:, x:] = 1
    elif a == 3:
        grid[:y, :] = 1
    else:
        grid[y:, :] = 1

ans = H * W - np.count_nonzero(grid)
print(ans)

Submission status: Accepted

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

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

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(xya[i][0],X[0])
    if xya[i][2]==2:
        X[1]=min(xya[i][0],X[1])
    if xya[i][2]==3:
        Y[0]=max(xya[i][1],Y[0])
    if xya[i][2]==4:
        Y[1]=min(xya[i][1],Y[1])
if X[0] >= X[1] or Y[0] >= Y[1]:
    print(0)
else:
    print((X[1]-X[0]) * (Y[1]-Y[0]))

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
minx,maxx = 0,W
miny,maxy = 0,H

for i in range(N):
    x,y,a = map(int,input().split())
    if a == 1:
        minx = max(minx,x)
    elif a == 2:
        maxx = min(maxx,x)
    elif a == 3:
        miny = max(miny,y)
    elif a == 4:
        maxy = min(maxy,y)

if minx >= maxx or miny >= maxy:
    print(0)
else:
    print((maxy-miny)*(maxx-minx))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

W,H,N = [int(i) for i in input().split()]

x = np.ones(N)
y = np.ones(N)
a = np.ones(N)

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


init_s = np.zeros([H+1,W+1])

ind_a_1 = [ind for ind,v in enumerate(a) if v == 1]
ind_a_2 = [ind for ind,v in enumerate(a) if v == 2]
ind_a_3 = [ind for ind,v in enumerate(a) if v == 3]
ind_a_4 = [ind for ind,v in enumerate(a) if v == 4]

if len(ind_a_1)==0:
    x_1 = 0
else:
    x_1=x[int(ind_a_1[0])]
    for i in ind_a_1:
        int_ind = int(i)
        if x_1<x[int_ind]:
            x_1=x[int_ind]
    
if len(ind_a_3)==0:
    y_3 = 0
else:
    y_3=y[int(ind_a_3[0])]
    for i in ind_a_3:
        int_ind = int(i)
        if y_3<y[int_ind]:
            y_3=y[int_ind]  
            
if len(ind_a_2)==0:
    x_2 = W
else:
    x_2=x[int(ind_a_2[0])]
    for i in ind_a_2:
        int_ind = int(i)
        if x_2>x[int_ind]:
            x_2=x[int_ind]
            
if len(ind_a_4)==0:
    y_4 = H
else:
    y_4=y[int(ind_a_4[0])]
    for i in ind_a_4:
        int_ind = int(i)
        if y_4>y[int_ind]:
            y_4=y[int_ind]
            
            
if (x_2-x_1>0) & (y_4-y_3>0):
    ans =int((x_2-x_1)*(y_4-y_3))
else:
    ans = int(0)
print(ans)

Submission status: Accepted

Solution code:
#047_B
w,h,n=map(int,input().split())
W=set(range(w))
H=set(range(h))

for _ in range(n):
    x,y,a=map(int,input().split())
    if a==1:W&=set(range(x,w))
    if a==2:W&=set(range(0,x))
    if a==3:H&=set(range(y,h))
    if a==4:H&=set(range(0,y))

print(len(W)*len(H))

Submission status: Accepted

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

a1,a2,a3,a4 = 0,w,0,h
for i in range(n):
    if l[i][2] == 1:
        a1 = max(l[i][0], a1)
    elif l[i][2] == 2:
        a2 = min(l[i][0], a2)
    elif l[i][2] == 3:
        a3 = max(l[i][1], a3)
    else:
        a4 = min(l[i][1], a4)

print(0) if a2-a1 <= 0 or a4-a3 <= 0 else print((a2-a1)*(a4-a3))

Submission status: Accepted

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

a1,a2,a3,a4 = 0,w,0,h
for i in range(n):
    if l[i][2] == 1:
        a1 = max(l[i][0], a1)
    elif l[i][2] == 2:
        a2 = min(l[i][0], a2)
    elif l[i][2] == 3:
        a3 = max(l[i][1], a3)
    else:
        a4 = min(l[i][1], a4)

if a2-a1 <= 0 or a4-a3 <= 0:
    print(0)
else:
    print((a2-a1)*(a4-a3))

Submission status: Accepted

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

a1,a2,a3,a4 = 0,w,0,h
for i in range(n):
    if l[i][2] == 1:
        a1 = max(l[i][0], a1)
    elif l[i][2] == 2:
        a2 = min(l[i][0], a2)
    elif l[i][2] == 3:
        a3 = max(l[i][1], a3)
    elif l[i][2] == 4:
        a4 = min(l[i][1], a4)

if a2-a1 <= 0 or a4-a3 <= 0:
    print(0)
else:
    print((a2-a1)*(a4-a3))

Submission status: Accepted

Solution code:
list=[]
W,H,N=map(int,input().split())
for a in range(N):
    x,y,a=map(int,input().split())
    list.append([x,y,a])
yoko=[d for d in range(W+1)]
tate=[e for e in range(H+1)]
for f in range(N):
    if list[f][2]==1:
        yoko=[g for g in yoko if g>=list[f][0]]
    elif list[f][2]==2:
        yoko=[h for h in yoko if h<=list[f][0]]
    elif list[f][2]==3:
        tate=[i for i in tate if i>=list[f][1]]
    else:
        tate=[j for j in tate if j<=list[f][1]]
if len(yoko)==0 or len(tate)==0:
    print(0)
else:
    nyoko = max(yoko) - min(yoko)
    ntate = max(tate) - min(tate)
    print(ntate * nyoko)

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
c = [0]*N
max_x,min_x = 0,W
max_y,min_y = 0,H
for _ 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)
  if min_x <= max_x or min_y <= max_y:
      print(0)
      exit()
print((min_x-max_x)*(min_y-max_y))

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
z = [input().split() for i in range(n)]
w = list(range(w+1))
h = list(range(h+1))
for i in range(n):
    if z[i][2] == '1':
        w = [j for j in w if j >= int(z[i][0])]
    elif z[i][2] == '2':
        w = [j for j in w if j <= int(z[i][0])]
    elif z[i][2] == '3':
        h = [j for j in h if j >= int(z[i][1])]
    elif z[i][2] == '4':
        h = [j for j in h if j <= int(z[i][1])]
if w == [] or h == []:
    print(0)
else:
    dh = max(h)-min(h)
    dw = max(w)-min(w)
    print(dh * dw)

Submission status: Accepted

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

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

for x,y,a in xya:
  #print(x,y,a)
  if a == 1:
    for i in range(x):
      for j in range(H):
        Result[i][j] = 0
  elif a == 2:
    for i in range(x, W):
      for j in range(H):
        Result[i][j] = 0
  elif a == 3:
    for i in range(W):
      for j in range(y):
        Result[i][j] = 0
  elif a == 4:
    for i in range(W):
      for j in range(y, H):
        Result[i][j] = 0
#print(Result)

Result = [flatten for inner in Result for flatten in inner]
print(sum(Result))

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
xya = [[0] * 3 for i in range(n)]
for i in range(n):
    x, y, a = map(int, input().split())
    xya[i][0], xya[i][1], xya[i][2] = x, y, a

area = [[False] * w for i in range(h)]
for i in xya:
    if i[2] == 1:
        for row in range(h):
            for col in range(0, i[0]):
                area[row][col] = True
    elif i[2] == 2:
        for row in range(h):
            for col in range(i[0], w):
                area[row][col] = True
    elif i[2] == 3:
        for row in range(0, i[1]):
            for col in range(w):
                area[row][col] = True
    else:
        for row in range(i[1], h):
            for col in range(w):
                area[row][col] = True

ans = 0
for row in range(h):
    for col in range(w):
        if not area[row][col]:
            ans += 1
print(ans)

Submission status: Accepted

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

W, H, N = map(int, input().split(' '))
field = [[0 for _ in range(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):
                field[i][j] = 1
    elif a == 2:
        for i in range(H):
            for j in range(x, W):
                field[i][j] = 1
    elif a == 3:
        for i in range(y):
            field[i] = [1] * (W)
    elif a == 4:
        for i in range(y, H):
            field[i] = [1] * (W)
ans = 0
for i in range(H):
    for j in range(W):
        if field[i][j] == 0:
            ans += 1
print(ans)

Submission status: Accepted

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

W, H, N = map(int, input().split(' '))
bound = {'l': 0, 'r': W, 'd': 0, 'u': H}
for _ in range(N):
    x, y, a = map(int, input().split(' '))
    if a == 1 and bound['l'] < x:
        bound['l'] = x
    elif a == 2 and bound['r'] > x:
        bound['r'] = x
    elif a == 3 and bound['d'] < y:
        bound['d'] = y
    elif a == 4 and bound['u'] > y:
        bound['u'] = y

w = max(0, bound['r']-bound['l'])
h = max(0, bound['u']-bound['d'])
print(w * h)

Submission status: Accepted

Solution code:
#オンオフについてのimos法
W,H,N=map(int,input().split())
L,R = 0,W
D,T = 0,H
for i in range(N):
    x,y,a = map(int,input().split())
    if a == 1:
        if R <= x:
            L,R = 0,0
        elif L <= x:
            L = x
    elif a == 2:
        if x <= L:
            L,R = 0,0
        elif x <= R:
            R = x
    elif a == 3:
        if T <= y:
            D,T = 0,0
        elif D <= y:
            D = y
    else:
        if y <= D:
            D,T = 0,0
        elif y <= T:
            T = y
print( ( R - L ) * ( T - D ) )

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
c = [[True] * w for i in range(h)]
l = [list(map(int, input().split())) for i in range(n)]
ans = 0
for i in range(n):
    if l[i][2] == 1:
        for j in range(w):
            for k in range(h):
                if j < l[i][0]:
                    c[k][j] = False
    elif l[i][2] == 2:
        for j in range(w):
            for k in range(h):
                if j > l[i][0]-1:
                    c[k][j] = False
    elif l[i][2] == 3:
        for j in range(w):
            for k in range(h):
                if k < l[i][1]:
                    c[k][j] = False
    else:
        for j in range(w):
            for k in range(h):
                if k > l[i][1]-1:
                    c[k][j] = False
for i in range(h):
    ans += c[i].count(True)
print(ans)

Submission status: Accepted

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

import numpy as np

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

x_list = []
y_list = []
a_list = []

field = np.ones((H, W), dtype=np.int)

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):
                field[j, i] = 0
    elif a == 2:
        for i in range(x, W):
            for j in range(H):
                field[j, i] = 0
    elif a == 3:
        for i in range(y):
            for j in range(W):
                field[i, j] = 0
    elif a == 4:
        for i in range(y, H):
            for j in range(W):
                field[i, j] = 0

print(np.count_nonzero(field == 1))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
# input = sys.stdin.readline
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    w,h,N=mis()
    s,t=0,0
    for i in range(N):
        x,y,a=mis()
        if a==1 and s<x: s=x
        elif a==2 and w>x: w=x
        elif a==3 and t<y: t=y
        elif a==4 and h>y: h=y
    print(0 if h-t<=0 or w-s<=0 else (h-t)*(w-s))



if __name__ == "__main__":
    main()

Submission status: Accepted

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

w_min, w_max = 0, W
h_min, h_max = 0, H

for _ in range(N) :
    x, y, a = map(int, input().split())
    
    if (a == 1):
        w_min = max(w_min, x)
    elif (a == 2):
        w_max = min(w_max, x)
    elif (a == 3):
        h_min = max(h_min, y)
    else:
        h_max = min(h_max, y)

# max > min が成立しない場合0
if (w_max < w_min or h_max < h_min):
    print(0)
else:
    area = (w_max - w_min) * (h_max - h_min)
    print(area)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
x=[0]*N
y=[0]*N
a=[0]*N
minX=0
maxX=W
minY=0
maxY=H
for i in range(N):
  x[i],y[i],a[i]=map(int,input().split())
  if a[i]==1:
    minX=max(minX,x[i])
  if a[i]==2:
    maxX=min(maxX,x[i]) 
  if a[i]==3:
    minY=max(minY,y[i])
  if a[i]==4:
    maxY=min(maxY,y[i]) 

ans=(maxX-minX)*(maxY-minY)
if maxX<minX or maxY<minY:
  ans=0
print(ans)

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
a1,a2,a3,a4=0,w,0,h
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)
    elif a==3:
        a3=max(a3,y)
    else:
        a4=min(a4,y)
print(max(a2-a1,0)*max(a4-a3,0))

Submission status: Accepted

Solution code:
import sys
# import math
# import decimal
# import queue
# import bisect
# import heapq
# import time
# import itertools
# from fractions import Fraction

mod = int(1e9+7)
INF = 1<<29

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

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
W, H, N = [int(i) for i in input().split()]
top, bottom, left, right = H, 0, 0, W
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)
print(max(right - left, 0) * max(top - bottom, 0))

Submission status: Accepted

Solution code:
def main():
  w, h, n = input_list()
  
  points = []
  for x in range(w):
    row = [True]*h
    points.append(row)
      
  for _ in range(n):
    x, y, a = input_list()
    if a == 1:
      for px, row in enumerate(points):
        for py, v in enumerate(row):
          if px+1 <= x:
            points[px][py] = False
    if a == 2:
      for px, row in enumerate(points):
        for py, v in enumerate(row):
          if px+1 > x:
            points[px][py] = False
    if a == 3:
      for px, row in enumerate(points):
        for py, v in enumerate(row):
          if py+1 <= y:
            points[px][py] = False
    if a == 4:
      for px, row in enumerate(points):
        for py, v in enumerate(row):
          if py+1 > y:
            points[px][py] = False
  ans = 0
  for p in points:
    ans += p.count(True)
  print(ans)

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

import math
main()

Submission status: Accepted

Solution code:
w, h, n = (int(x) for x in input().split())
x = []
s = [[1 for _ in range(w)] for _ in range(h)]
for _ in range(n): x.append([int(i) for i in input().split()])
for x_i in x:
    a = x_i[2]
    if a == 1:
        for h_ in range(h):
            for w_ in range(x_i[0]):
                s[h_][w_] = 0
    elif a == 2:
        for h_ in range(h):
            for w_ in range(x_i[0], w):
                s[h_][w_] = 0
    elif a == 3:
        for h_ in range(x_i[1]):
            for w_ in range(w):
                s[h_][w_] = 0
    else:
        for h_ in range(x_i[1], h):
            for w_ in range(w):
                s[h_][w_] = 0
print(sum([s[i][j] for j in range(w) for i in range(h)]))

Submission status: Accepted

Solution code:
W, H, N = map(int,input().split())
lx, rx = 0, W
dy, uy = 0, H

for i in range(N):
  x, y, a = map(int,input().split())
  if a == 1:
    lx = max(lx, x)
  elif a == 2:
    rx = min(rx, x)
  elif a == 3:
    dy = max(dy, y)
  elif a == 4:
    uy = min(uy, y)

w, h = rx - lx, uy - dy
if w <= 0 or h <= 0:
  print(0)
else:
  print(w*h)

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
W,H,N=map(int, input().split())
s=[[1]*W for i in range(H)]
for i in range(N):
    x,y,n=map(int,input().split())
    if n==1:
        for j in range(x):
            for k in range(H):
                s[k][j]=0
    elif n==2:
        for j in range(x,W):
            for k in range(H):
                s[k][j]=0
    elif n==3:
        for j in range(W):
            for k in range(y):
                s[k][j]=0
    elif n==4:
        for j in range(W):
            for k in range(y,H):
                s[k][j]=0
a=0
for i in s:
    a+=sum(i)
print(a)

Submission status: Accepted

Solution code:
w, h, n = [int(e) for e in input().split()]
x_under, x_lim, y_under, y_lim = 0, w, 0, h
for _ in range(n):
    x, y, a = [int(e) for e in input().split()]
    if a == 1 and x_under < x:
        x_under = x
    elif a == 2 and x < x_lim:
        x_lim = x
    elif a == 3 and y_under < y:
        y_under = y
    elif a == 4 and y < y_lim:
        y_lim = y
x_len = x_lim - x_under
y_len = y_lim - y_under
if x_len < 0 or y_len < 0:
    print('0')
else:
    print(x_len * y_len)

Submission status: Accepted

Solution code:
def main():
    width, height, point_num = map(int, input().split())
    points = [tuple(map(int, input().split())) for _ in range(point_num)]
    white_range = [[0, 0], [width, height]]
    for point in points:
        if point[2] == 1:
            white_range[0][0] = max(point[0], white_range[0][0])
        elif point[2] == 2:
            white_range[1][0] = min(point[0], white_range[1][0])
        elif point[2] == 3:
            white_range[0][1] = max(point[1], white_range[0][1])
        else:
            white_range[1][1] = min(point[1], white_range[1][1])
    if white_range[1][0] < white_range[0][0] or white_range[1][0] < white_range[0][0]:
        print(0)
    else:
        print((white_range[1][0] - white_range[0][0]) * (white_range[1][1] - white_range[0][1]))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for _ in range(n):
  x,y,a = map(int,input().split())
  
  if a==1:
    W+=list(range(x))
  elif a==2:
    W+=list(range(x+1, w+1))
  elif a==3:
    H+=list(range(y))
  elif a==4:
    H+=list(range(y+1, h+1))

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

Submission status: Accepted

Solution code:
def I(): return int(input())
def MI(): return map(int, input().split())
def LMI(): return list(map(int, input().split()))
MOD = 10 ** 9 + 7


W, H, N = MI()
m = [0, 0, W, 0, H]
for _ in range(N):
    x, y, a = MI()
    if a == 1:
        m[a] = max(m[a], x)
    elif a == 2:
        m[a] = min(m[a], x)
    elif a == 3:
        m[a] = max(m[a], y)
    else:
        m[a] = min(m[a], y)
print(max(0, m[2] - m[1]) * max(0, m[4] - m[3]))

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

x_min = 0
x_max = W
y_min = 0
y_max = H
for i in range(len(a)):
    if a[i] == 1:
        if x_min < x[i]:
            x_min = x[i]
    elif a[i] == 2:
        if x_max > x[i]:
            x_max = x[i]
    elif a[i] == 3:
        if y_min < y[i]:
            y_min = y[i]
    else:
        if y_max > y[i]:
            y_max = y[i]
        
x_len = x_max-x_min
y_len = y_max-y_min
result = x_len*y_len
if (x_len<0)|(y_len<0):
    result = 0

print(result)

Submission status: Accepted

Solution code:
import numpy as np

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

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

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

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

print(np.sum(ze))

Submission status: Accepted

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

x = [0,w]
y = [0,h]
for i in range(len(xya)):
    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]:
    x[0]=x[1]
if y[1]<y[0]:
    y[0]=y[1]
print((x[1]-x[0])*(y[1]-y[0]))

Submission status: Accepted

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

a = 0
b = w
c = 0
d = h

for i,j,k in l:
    if k == 1:
        a = max(a,i)
    elif k == 2:
        b = min(b,i)
    elif k==3:
        c = max(c,j)
    else:
        d = min(d,j)

    if a >= b or c >= d:
        print(0)
        exit()
print((b-a)*(d-c))

Submission status: Accepted

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

points = []
for i in range(n):
    points.append(list(map(int, input().split(' '))))

mx = 0
my = 0
xx = w
xy = h
    
for point in points:
    if point[2] == 1 and mx < point[0]:
        mx = point[0]
    elif point[2] == 2 and xx > point[0]:
        xx = point[0]
    elif point[2] == 3 and my < point[1]:
        my = point[1]
    elif point[2] == 4 and xy > point[1]:
        xy = point[1]
        
a = xx - mx if xx - mx > 0 else 0
b = xy - my if xy - my > 0 else 0
print(a * b)

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
min_H = 0
min_W = 0
max_H = H
max_W = W

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

    if a == 1:
        min_W = max(x, min_W)
    elif a == 2:
        max_W = min(x, max_W)
    elif a == 3:
        min_H = max(y, min_H)
    else:
        max_H = min(y, max_H)

if min_W > max_W or min_H > max_H:
    print(0)
else:
    print((max_H - min_H) * (max_W - min_W))

Submission status: Accepted

Solution code:
#B - すぬけ君の塗り絵 2 イージー

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

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

up = H
down = 0
left = 0
right = W

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

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
x1_max = 0
x2_min = w
y3_max = 0
y4_min = h

for i in range(n):
  x,y,a=map(int, input().split())
  if a==1: x1_max = max(x1_max, x)
  elif a==2: x2_min = min(x2_min, x)
  elif a==3: y3_max = max(y3_max, y)
  elif a==4: y4_min = min(y4_min, y)
    
print((x2_min - x1_max if x1_max < x2_min else 0)*(y4_min - y3_max if y3_max < y4_min else 0))

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]
list_w = [1]*w
list_h = [1]*h

for i in range(n):
  if a[i][2] == 1:
    for j in range(a[i][0]):
      list_w[j] = 0
  elif a[i][2] == 2:
    for j in range(w-1,a[i][0]-1,-1):
      list_w[j] = 0
  elif a[i][2] == 3:
    for j in range(a[i][1]):
      list_h[j] = 0
  elif a[i][2] == 4:
    for j in range(h-1,a[i][1]-1,-1):
      list_h[j] = 0

h = list_h.count(1)
w = list_w.count(1)
print(h*w)

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
canvas=[[0 for j in range(W)] for i in range(H)]
for n in range(N):
    x,y,a=map(int,input().split())
    if a==1:
        for i in range(x):
            for j in range(H):
                canvas[j][i]=1
    if a==2:
        for i in range(x,W):
            for j in range(H):
                canvas[j][i]=1
    if a==3:
        for i in range(W):
            for j in range(y):
                canvas[j][i]=1
    if a==4:
        for i in range(W):
            for j in range(y,H):
                canvas[j][i]=1
                
count=0
for i in range(H):
    count+=canvas[i].count(0)
    
print(count)

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
A=[]
right=W
left=0
top=H
under=0

for i in range(N):
  A.append(list(map(int,input().split())))
  if A[i][2]==1:
    if left<A[i][0]:
      left=A[i][0]
  if A[i][2]==2:
    if right>A[i][0]:
      right=A[i][0]
  if A[i][2]==3:
    if under<A[i][1]:
      under=A[i][1]
  if A[i][2]==4:
    if top>A[i][1]:
      top=A[i][1]

print(max(0,top-under)*max(0,right-left))

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
li=[list(map(int,input().split())) for i in range(n)]
ue=h
sita=0
migi=w
hidari=0
for i in range(n):
    if li[i][2]==1:
        if li[i][0]>hidari:
            hidari=li[i][0]

    if li[i][2]==2:
        if li[i][0]<migi:
            migi=li[i][0]

    if li[i][2]==3:
        if li[i][1]>sita:
            sita=li[i][1]

    if li[i][2]==4:
        if li[i][1]<ue:
            ue=li[i][1]
print(max(0,(ue-sita))*max(0,(migi-hidari)))

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
b = [0, 0, W, 0, H]
for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        b[a] = max(b[a], x)
    elif a == 2:
        b[a] = min(b[a], x)
    elif a == 3:
        b[a] = max(b[a], y)
    else:
        b[a] = min(b[a], y)
# print('b', b)
_W = b[2] - b[1]
_H = b[4] - b[3]
# print('_W, _H', _W, _H)
if _W < 0 or _H < 0:
    print(0)
else:
    print(_W * _H)

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
xya=[list(map(int,input().split())) for _ in range(n)]
xya_1=0
xya_2=w
xya_3=0
xya_4=h
for _ in range(n):
  if xya[_][2]==1:
    xya_1=max(xya_1,xya[_][0])
  elif xya[_][2]==2:
    xya_2=min(xya_2,xya[_][0])
  elif xya[_][2]==3:
    xya_3=max(xya_3,xya[_][1])
  else:
    xya_4=min(xya_4,xya[_][1])
print(max(0,xya_2-xya_1)*max(0,xya_4-xya_3))

Submission status: Accepted

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

new_w = [0] * w
new_h = [0] * h



for i in range(n):
  x , y , a = list(map(int,input().split()))
  if a == 1:
    for t in range(x):
      new_w[t] = 1
  
  elif a == 2:
    for t in range(len(new_w) - x):
      new_w[-1 - t] = 1
  
  elif a == 3:
    for t in range(y):
      new_h[-1-t] = 1
  
  else:
    for t in range(len(new_h) - y):
      new_h[t] = 1

w_long = len(new_w) - sum(new_w)
h_long = len(new_h) - sum(new_h)


print(w_long * h_long)