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:
from collections import defaultdict

def main():
    W,H,N = [int(x) for x in input().split()]
    x1,y1 = 0,0
    x2,y2 = W,H
    x3,y3 = 0,0
    x4,y4 = W,H
    A = defaultdict(list)
    for _ in range(N):
        x,y,a = [int(x) for x in input().split()]
        A[a].append((x,y))
    if A[1]:
        x1,y1 = max(A[1], key=(lambda x: x[0]))
    if A[2]:
        x2,y2 = min(A[2], key=(lambda x: x[0]))
    if A[3]:
        x3,y3 = max(A[3], key=(lambda x: x[1]))
    if A[4]:
        x4,y4 = min(A[4], key=(lambda x: x[1]))
    if x1 >= x2 or y3 >= y4:
        print(0)
    else:
        print((x2-x1)*(y4-y3))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(N):
    x, y, a = xya[i]
    if a == 1:
        for w in range(x):
            for h in range(H):
                field[h][w] = 0
    elif a == 2:
        for w in range(x, W):
            for h in range(H):
                field[h][w] = 0

    elif a == 3:
        for w in range(W):
            for h in range(y):
                field[h][w] = 0

    elif a == 4:
        for w in range(W):
            for h in range(y, H):
                field[h][w] = 0
ans = 0
for i in field:
    ans += sum(i)
print(ans)

Submission status: Accepted

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

S = [[1] * W for _ in range(H)]
for x, y, a in xya:
    if a == 1:
        for i in range(H):
            for j in range(x):
                S[i][j] = 0
    elif a == 2:
        for i in range(H):
            for j in range(x, W):
                S[i][j] = 0
    elif a == 3:
        for i in range(y):
            for j in range(W):
                S[i][j] = 0
    else:
        for i in range(y, H):
            for j in range(W):
                S[i][j] = 0
A = 0
for i in range(H):
    A += sum(S[i])
print(A)

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(max(0,R-L)*max(0,U-D))

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
RCT = list(list(map(int, input().split())) for _ in range(n))
l = 0
r = w
dn = 0
up = h
for i in RCT:
    if i[2] == 1:
        l = max(l, i[0])
    if i[2] == 2:
        r = min(r, i[0])
    if i[2] == 3:
        dn = max(dn, i[1])
    if i[2] == 4:
        up = min(up, i[1])
print(0 if r - l <= 0 or up - dn <= 0 else (r - l) * (up - dn))

Submission status: Accepted

Solution code:
X,Y,N=map(int,input().split())
max_X=X
max_Y=Y
current_min_x=0
current_min_y=0
current_max_x=X
current_max_y=Y
xy=[list(map(int,input().split())) for _ in range(N)]
for x,y,a in xy:
  n=0
  if a==1:
    current_min_x=max(current_min_x, x)
  elif a==2:
    current_max_x=min(current_max_x, x)
  elif a==3:
    current_min_y=max(current_min_y, y)
  elif a==4:
    current_max_y=min(current_max_y, y)
result=(current_max_x-current_min_x)*(current_max_y-current_min_y)
print(max(current_max_x-current_min_x,0)*max(current_max_y-current_min_y,0))

Submission status: Accepted

Solution code:


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    W, H, N = read_ints()
    x0, y0, x1, y1 = 0, 0, W, H
    for _ in range(N):
        x, y, a = read_ints()
        if a == 1:
            x0 = min(max(x, x0), x1)
        if a == 2:
            x1 = max(min(x, x1), x0)
        if a == 3:
            y0 = min(max(y, y0), y1)
        if a == 4:
            y1 = max(min(y, y1), y0)
    return (x1-x0)*(y1-y0)


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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log,gcd
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')

#Pythonを用いる場合
#numpy 1.18.0, scipy 1.4.1, scikit-learn 0.22, numba 0.47.0, networkx 2.4
 
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix

 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
w,h,n=mii()

mat=np.array([[1]*w for _ in range(h)])

for _ in range(n):
    x,y,a=mii()
    if a==1:
        mat[:,:x]=0
    elif a==2:
        mat[:,x:]=0
    elif a==3:
        mat[:y,:]=0
    else:
        mat[y:,:]=0
#print(mat)
print(np.sum(mat))

Submission status: Accepted

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

wl=0
wr=W
hd=0
hu=H
for x,y,a in xya:
    if a==1:
        wl=max(wl,x)
    elif a==2:
        wr=min(wr,x)
    elif a==3:
        hd=max(hd,y)
    else:
        hu=min(hu,y)

ans=max(wr-wl,0)*max(hu-hd,0)
print(ans)

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
xs = 0
ys = 0
xe = w
ye = h
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 2:
        xe = min(xe,x)
    elif a == 1:
        xs = max(xs,x)
    elif a == 4:
        ye = min(ye,y)
    else:
        ys = max(ys,y)
if xs < xe and ys < ye:
    print(abs(xs-xe)*abs(ys-ye))
else:
    print(0)

Submission status: Accepted

Solution code:
# Problem: https://atcoder.jp/contests/abc047/tasks/abc047_b
# Python 1st Try

import sys
import numpy
# import pprint
# from collections import defaultdict
# import heapq,copy
# from collections import deque
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solver(Width, Height, Point, x_position, y_position, control_id):
    result = 0
    # surface = [[0] * (Width+1) for _ in range(0, Height+1, +1)]
    surface = numpy.zeros((Width, Height), dtype=numpy.int)
    # pprint.pprint(surface)
    # algorithm
    # pprint.pprint(surface)
    for j in range(0, Point, +1):
        if control_id[j] == 1:
            for x in range(0, x_position[j], +1):
                for y in range(0, Height, +1):
                    surface[x][y] = 1
        elif control_id[j] == 2:
            for x in range(x_position[j], Width, +1):
                for y in range(0, Height, +1):
                    surface[x][y] = 1
        elif control_id[j] == 3:
            for x in range(0, Width, +1):
                for y in range(0, y_position[j], +1):
                    surface[x][y] = 1
        else:  # control_id[X] == 4
            for x in range(0, Width, +1):
                for y in range(y_position[j], Height, +1):
                    surface[x][y] = 1
    #  pprint.pprint(surface)
    for x in range(0, Width, +1):
        for y in range(0, Height, +1):
            if surface[x][y] == 0:
                result = result + 1
    return result


if __name__ == "__main__":
    W, H, N = MI()
    x_position = list()
    y_position = list()
    control_id = list()
    for j in range(0, N, +1):
        x_tmp, y_tmp, a_tmp = MI()
        x_position.append(x_tmp)
        y_position.append(y_tmp)
        control_id.append(a_tmp)
    print("{}".format(solver(W, H, N, x_position, y_position, control_id)))

Submission status: Accepted

Solution code:
w,h,n = list(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)
    elif a == 4:
        maxY = min(maxY, y)

print(max(0, maxX-minX)*max(0, maxY-minY))

Submission status: Accepted

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

o,p,q,r = 0,0,0,0
for _ in range(n):
  x,y,a = map(int, input().split())
  if a == 1:
    o = max(o, x)
  elif a == 2:
    p = max(p, w-x)
  elif a == 3:
    q = max(q, y)
  elif a == 4:
    r = max(r, h-y)

w -= o+p
h -= q+r
if w <= 0 or h <= 0:
  print(0)
else:
  print(w*h)

Submission status: Accepted

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

s = [list(map(int, input().split())) for i in range(n)]

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

for i in range(n):
  if s[i][2] == 1:
    if s[i][0] > min_x:
      min_x = s[i][0]

  elif s[i][2] == 2:
    if s[i][0] < max_x:
      max_x = s[i][0]
      
  elif s[i][2] == 3:
    if s[i][1] > min_y:
      min_y = s[i][1]
      
  else:
    if s[i][1] < max_y:
      max_y = s[i][1]

if (max_x - min_x) > 0 and (max_y - min_y) > 0:
  print((max_x - min_x) * (max_y - min_y))
  
else:
  print(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)
    elif a == 4:
        maxY = min(maxY, y)

print(max(0, maxX-minX)*max(0, maxY-minY))

Submission status: Accepted

Solution code:
import numpy as np
W,H,N=map(int,input().split())
A=np.zeros((W,H))
B=[list(map(int,input().split())) for _ in range(N)]
for b in B:
    if b[2]==1:
        A[:b[0],:]=1
    elif b[2]==2:
        A[b[0]:,:]=1
    elif b[2]==3:
        A[:,:b[1]]=1
    elif b[2]==4:
        A[:,b[1]:]=1
print(np.count_nonzero(A==0))

Submission status: Accepted

Solution code:
import sys
import numpy as np
import random
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache

sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
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)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

def main():
	w, h, n = LI()
	left_x, right_x, lower_y, upper_y = 0, w, 0, h
	for _ in range(n):
		x, y, a = LI()
		if a == 1:
			left_x = max(x, left_x)
		elif a == 2:
			right_x = min(x, right_x)
		elif a == 3:
			lower_y = max(y, lower_y)
		elif a == 4:
			upper_y = min(y, upper_y)
	if right_x > left_x and upper_y > lower_y:
		print((right_x-left_x)*(upper_y-lower_y))
	else:
		print(0)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

rect = [["W" for i in range(W)] for j in range(H)]

for x in check:
    if x[2] == 1:
        for h1 in range(H):
            for w1 in range(x[0]):
                rect[h1][w1] = "B"

    elif x[2] == 2:
        for h2 in range(H):
            for w2 in range(x[0], W, 1):
                rect[h2][w2] = "B"
    elif x[2] == 3:
        for h3 in range(x[1]):
            for w3 in range(W):
                rect[h3][w3] = "B"

    elif x[2] == 4:
        for h3 in range(x[1], H, 1):
            for w3 in range(W):
                rect[h3][w3] = "B"


count = 0
for y in rect:
    count += y.count("W")
print(count)

Submission status: Accepted

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

def isBlack(h, w):
    for x, y, a in XYA:
        if a == 1 and w < x:
            return True
        if a == 2 and w >= x:
            return True
        if a == 3 and h < y:
            return True
        if a == 4 and h >= y:
            return True
    return False

ans = H * W
for w in range(W):
    for h in range(H):
        ans -= 1 if isBlack(h, w) else 0
print(ans)

Submission status: Accepted

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

A = [[0]*w for i in range(h)]

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):
                A[i][j] = 1
    elif a == 2:
        for i in range(h):
            for j in range(x,w):
                A[i][j] = 1
    elif a == 3:
        for i in range(y):
            for j in range(w):
                A[i][j] = 1                
    else:            
        for i in range(y,h):
            for j in range(w):
                A[i][j] = 1                

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

print(ans)

Submission status: Accepted

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

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

for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    x_min=max(x_min,x)
  elif a==2:
    x_max=min(x_max,x)
  elif a==3:
    y_min=max(y_min,y)
  elif a==4:
    y_max=min(y_max,y)

width=max(x_max-x_min,0)
height=max(y_max-y_min,0)

print(int(width*height))

Submission status: Accepted

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

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

for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    x_min=max(x_min,x)
  if a==2:
    x_max=min(x_max,x)
  if a==3:
    y_min=max(y_min,y)
  if a==4:
    y_max=min(y_max,y)

y_ok=y_max-y_min
x_ok=x_max-x_min

if y_ok>=0 and x_ok>=0:
  print(y_ok*x_ok)
else:
  print(0)

Submission status: Accepted

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

y_min = 0
y_max = h

x_min = 0
x_max = w

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

  if a == 1:
    x_min = max(x_min, x)

  if a == 2:
    x_max = min(x_max, x)

  if a == 3:
    y_min = max(y_min, y)

  if a == 4:
    y_max = min(y_max, y)

white = (y_max - y_min) * (x_max - x_min)
if (y_max - y_min)>=0 and (x_max - x_min)>=0:
  print(max(white, 0))
else:
  print(0)

Submission status: Accepted

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

lst = []
for i in range(N):
    lst.append(list(map(int,input().split())))


x_left,x_right = 0, W
y_under, y_up = 0,H

for i in range(N):
    x,y = lst[i][0], lst[i][1]
    if lst[i][2] == 1:
        if x_left < x: 
            x_left = x
    elif lst[i][2] == 2:
        if x_right > x:
            x_right = x
            if x_right == 0:
                print(0)
                exit()
    elif lst[i][2] == 3:
        if y_under < y:
            y_under = y
    elif lst[i][2] == 4:
        if y_up > y:
            y_up = y
            if y_up == 0:
                print(0)
                exit()

yoko = x_right - x_left
tate = y_up - y_under
if tate * yoko <= 0:
    print(0)
else:
    print(tate * yoko)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

W, H, N = mapint()
x1, y1 = 0, 0
x2, y2 = W, H
for _ in range(N):
    x, y, a = mapint()
    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)

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

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)
  if a==2:
    x2=min(x2,x)
  if a==3:
    y1=max(y1,y)
  if a==4:
    y2=min(y2,y)
if x2<x1 or y2<y1:
  print(0)
else:
  print((x2-x1)*(y2-y1))

Submission status: Accepted

Solution code:
w,h,n = map(int, input().split())
xya = [list(map(int, input().split())) for _ in range(n)]
X = [0,w]
Y = [0,h]
for x,y,a in xya:
    if a == 1:
        X[0] = max(X[0], x)
    elif a == 2:
        X[1] = min(X[1], x)
    elif a == 3:
        Y[0] = max(Y[0], y)
    else:
        Y[1] = min(Y[1], y)
if X[0] >= X[1] or Y[0] >= Y[1]: print(0)
else: print(abs(X[0]-X[1])*abs(Y[0]-Y[1]))

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**6)

w,h,n=map(int,input().split())
u,d,r,l=h,0,w,0
for _ in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        if l<x: l=x
    elif a==2:
        if r>x: r=x
    elif a==3:
        if d<y: d=y
    elif a==4:
        if u>y: u=y

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

Submission status: Accepted

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

W,H,N = map(int,readline().split())
minX = 0
minY = 0
maxX = W
maxY = H

for i in range(N):
  x,y,a = map(int,readline().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)

print(max(0,maxX - minX) * max(0,maxY - minY))

Submission status: Accepted

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

xl, xr, yd, yu = 0, w, 0, h
for _ 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:
        yd = max(yd, y)
    else:
        yu = min(yu, y)

width = max(xr-xl, 0)
height = max(yu-yd, 0)
print(width*height)

Submission status: Accepted

Solution code:
[w, h, n] = list(map(int, input().split()))
list_x1 = []
list_x2 = []
list_y3 = []
list_y4 = []
for i in range(n):
  xya = list(map(int, input().split()))
  if xya[2] == 1:
    list_x1.append(xya[0])
  if xya[2] == 2:
    list_x2.append(xya[0])
  if xya[2] == 3:
    list_y3.append(xya[1])
  if xya[2] == 4:
    list_y4.append(xya[1])
try:
  min_x = min(list_x2)
except ValueError:
  pass  
try:
  max_x = max(list_x1)
except ValueError:
  pass  
try:
  min_y = min(list_y4)
except ValueError:
  pass  
try:
  max_y = max(list_y3)
except ValueError:
  pass  
try:
  w =min_x
except NameError:
  pass
try:
  w -= max_x
except NameError:
  pass
try:  
  h = min_y
except NameError:
  pass
try:
  h -= max_y
except NameError:
  pass
if w > 0 and h > 0:
  print(w*h)
else:
  print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
W, H, N = map(int, input().split())
g = np.zeros((H, W))

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        g[:, :x] = 1
    elif a == 2:
        g[:, x:] = 1
    elif a == 3:
        g[abs(H-y):, :] = 1
    else:
        g[:abs(H-y), :] = 1

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

Submission status: Accepted

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

a = []
for i in range(N):
    l = list(map(int, input().split()))
    a.append(l)

X = 0 #左から引く領域
Y = 0 #下から引く領域

for j in range(N):
    if a[j][2] == 1: #xより小さい領域を塗りつぶす
        if a[j][0] > X:
            X = a[j][0]
        else:
            pass
    elif a[j][2] == 2: #xより大きい領域を塗りつぶす
        if a[j][0] < W:
            W = a[j][0]
        else:
            pass
    elif a[j][2] == 3: #yより小さい領域を塗りつぶす
        if a[j][1] > Y:
            Y = a[j][1]
        else:
            pass
    elif a[j][2] == 4: #yより大きい領域を塗りつぶす
        if a[j][1] < H:
            H = a[j][1]
        else:
            pass
    else:
        print('Error')

W = W - X
H = H - Y

if W <= 0:
    W = 0
else:
    pass

if H <= 0:
    H = 0
else:
    pass

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

Submission status: Accepted

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

x = list(range(0,w+1))
y = list(range(0,h+1))

for l in ls:
    if len(x)<=1 or len(y)<=1:
        break

    if l[2] == 2:
        x = [i for i in x if i <= l[0]]
    elif l[2] == 1:
        x = [i for i in x if i >= l[0]]
    elif l[2] == 4:
        y = [i for i in y if i <= l[1]]
    elif l[2] == 3:
        y = [i for i in y if i >= l[1]]

if len(x)<=1 or len(y)<=1:
    print(0)
else:
    x = max(x) - min(x)
    y = max(y) - min(y)
    print(x*y)

Submission status: Accepted

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

lstx = [[0], [W]]
lsty = [[0], [H]]

for i in range(N):
    x, y, a = map(int, input().split())
    if a==1 or a==2:
        lstx[a-1].append(x)
    else:
        lsty[a-3].append(y)

xmax = max(lstx[0])
xmin = min(lstx[1])
ymax = max(lsty[0])
ymin = min(lsty[1])

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())
u,d,r,l=h,0,w,0
for _ in range(n):
    x,y,a=map(int,input().split())
    if a==1 and x>l: l=x
    if a==2 and x<r: r=x
    if a==3 and y>d: d=y
    if a==4 and y<u: u=y
if u>d and r>l: print((u-d)*(r-l))
else: print(0)

Submission status: Accepted

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

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

x_edge = max(0, w-x_reg)
y_edge = max(0, h-y_reg)

print(x_edge*y_edge)

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
w1 = 0
w2 = W
h1 = 0
h2 = H
for i in range(N):
  x, y, a = map(int, input().split())
  if a == 1 and w1 < x:
    w1 = x
  elif a == 2 and w2 > x:
    w2 = x
  elif a == 3 and h1 < y:
    h1 = y
  elif a == 4 and h2 > y:
    h2 = y
wa = w2 - w1
if wa < 0:
  wa = 0
ha = h2 - h1
if ha < 0:
  ha = 0
ans = wa * ha
print(ans)

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
xl, xr = 0, w
yd, yu = 0, h
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        if x < xl:
            continue
        elif xl <= x <= xr:
            xl = x
        else:
            xl, xr = 0, 0 # 抜けてた...
    elif a == 2:
        if xr < x:
            continue
        elif xl <= x <= xr:
            xr = x
        else:
            xl, xr = 0, 0
    elif a == 3:
        if y < yd:
            continue
        elif yd <= y <= yu:
            yd = y
        else:
            yd, yu = 0, 0
    elif a == 4:
        if y > yu:
            continue
        elif yd <= y <= yu:
            yu = y
        else:
            yd, yu = 0, 0

print((xr - xl) * (yu - yd))

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
W0=0
H0=0
for i in range(N):
    x1,y1,a1=map(int,input().split())
    if a1 ==1 and W0<x1:
        W0=x1
    elif a1==2 and W>x1:
        W=x1
    elif a1==3 and H0<y1:
        H0=y1
    elif a1==4 and H>y1:
        H=y1

if W-W0>0 and H-H0>0:
    print((W-W0)*(H-H0))
else:
    print(0)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu Jun 11 17:09:47 2020

@author: sd18016
"""   

import sys

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

for i in range(N):
    x = list(map(int, input().split()))
    list_x.append(x)
    
O = [0,0]
MU = [W, H]

for i in range(N):
    if list_x[i][2] == 1:
        if list_x[i][0] > O[0]:
            O[0] = list_x[i][0]
    elif list_x[i][2] == 2:
        if list_x[i][0] < MU[0]:
            MU[0] = list_x[i][0]
    elif list_x[i][2] == 3:
        if list_x[i][1] > O[1]:
            O[1] = list_x[i][1]
    elif list_x[i][2] == 4:
        if list_x[i][1] < MU[1]:
            MU[1] = list_x[i][1]
            
W_ans = MU[0]-O[0]
H_ans = MU[1]-O[1]

if W_ans <0 or H_ans<0:
    print("0")
else:
    ans = W_ans*H_ans
    print(ans)
            



"""
for i in range(N):
    if list_x[i][2] == 1:
        de = list_x[i][0]
        S -= de*H
        W -= de
    elif list_x[i][2] == 2:
        de = W - list_x[i][0]
        S -= de*H
        W -= de
    elif list_x[i][2] == 3:
        de = list_x[i][1]
        S -= de*W
        H -= de
    else:
        de = H - list_x[i][1]
        S -= de*W
        H -= de

print(S)
"""

Submission status: Accepted

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

XW = [1] * W
YW = [1] * H

for i in range(N):
  x,y,a = map(int,input().split())
  if a == 1:
    XW[:x] = [0]*x
  elif a == 2:
    XW[x:] = [0]*(W-x)
  elif a == 3:
    YW[:y] = [0]*y
  elif a == 4:
    YW[y:] = [0]*(H-y)
print(sum(XW)*sum(YW))

Submission status: Accepted

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

E = [0,W,0,H]

for x,y,a in XYA:
  a -= 1
  XY = [x,y]
  if a % 2 == 0:
    E[a] = max(E[a],XY[a//2])
  else:
    E[a] = min(E[a],XY[a//2])

ans = 0
if E[0] < E[1] and E[2] < E[3]:
  ans = (E[1] - E[0]) * (E[3] - E[2])
  
print(ans)

Submission status: Accepted

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

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:
        if X1 <= x:
            X1 = x
        else:
            pass
    elif a == 2:
        if x <= X2:
            X2 = x
        else:
            pass
    if a == 3:
        if Y1 <= y:
            Y1 = y
        else:
            pass
    if a == 4:
        if y <= Y2:
            Y2 = y
        else:
            pass
if X1 >= X2 or Y1 >= Y2:
    print(0)
else:
    print((X2 - X1) * (Y2 - Y1))

Submission status: Accepted

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

X = [0] * N
Y = [0] * N
A = [0] * N

for _ in range(N):
    X[_], Y[_], A[_] = list(map(int, input().split()))

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

#solve
xb = 0
xe = W
yb = 0
ye = H

for _ in range(N):
    if A[_] == 1:
        # Xiより小さいを黒
        xb = max([xb, X[_]])
    elif A[_] == 2:
        # Xiより大きいを黒
        xe = min([xe, X[_]])
    elif A[_] == 3:
        # Yiより小さいを黒
        yb = max([yb, Y[_]])
    else:
        # Yiより大きいを黒
        ye = min([ye, Y[_]])
    
    # check
    if (xe - xb) <= 0 or (ye - yb) <= 0:
        print(0)
        import sys
        sys.exit()

ans = (xe - xb) * (ye - yb)
print(ans)

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,w,0,h]
for i in range(n):
  if l[i][2]==1:
    a[0]=max(a[0],l[i][0])
  elif l[i][2]==2:
    a[1]=min(a[1],l[i][0])
  elif l[i][2]==3:
    a[2]=max(a[2],l[i][1])
  else:
    a[3]=min(a[3],l[i][1])
print(max(a[1]-a[0],0)*max(a[3]-a[2],0))

Submission status: Accepted

Solution code:

w, h, n = map(int, input().split())
square_info = [list(map(int, input().split())) for _ in range(n)]

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

for i in range(n):
    if square_info[i][2] == 1:
        min_x = max(min_x, square_info[i][0])
    elif square_info[i][2] == 2:
        max_x = min(max_x, square_info[i][0])
    elif square_info[i][2] == 3:
        min_y = max(min_y, square_info[i][1])
    else:
        max_y = min(max_y, square_info[i][1])

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

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]
xl = 0
xr = w
yh = h
yr = 0
for i in range(n):
    if a[i][2] == 1:
        xl = max(xl,a[i][0])
    elif a[i][2] == 2:
        xr = min(xr,a[i][0])
    elif a[i][2] == 3:
        yr = max(yr,a[i][1])
    else:
        yh = min(yh,a[i][1])

x = xr - xl
y = yh - yr

print(0 if x < 0 or y < 0 else x*y)

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:
        if x1<x:
            x1=x
    elif a==2:
        if x<x2:
            x2=x
    elif a==3:
        if y1<y:
            y1=y
    else:
        if y<y2:
            y2=y

if x2<=x1 or y2<=y1:
    print(0)
else:
    print((x2-x1)*(y2-y1))