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:
def main():
    import sys
    input = sys.stdin.buffer.readline
    W, H, N = (int(i) for i in input().split())
    XYA = [[int(i) for i in input().split()] for j in range(N)]
    seen = [[True]*W for _ in range(H)]
    for x, y, a in XYA:
        if a == 1:
            for h in range(H):
                for w in range(x):
                    seen[h][w] = False
        elif a == 2:
            for h in range(H):
                for w in range(x, W):
                    seen[h][w] = False
        elif a == 3:
            for h in range(y):
                for w in range(W):
                    seen[h][w] = False
        elif a == 4:
            for h in range(y, H):
                for w in range(W):
                    seen[h][w] = False
    ans = 0
    for h in range(H):
        for w in range(W):
            if seen[h][w]:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

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

    if a == 1:
        for x_ in range(x):
            for y_ in range(H):
                G[x_][y_] = 0

    if a == 2:
        for x_ in range(x, W):
            for y_ in range(H):
                G[x_][y_] = 0
    
    if a == 3:
        for x_ in range(W):
            for y_ in range(y):
                G[x_][y_] = 0
    
    if a == 4:
        for x_ in range(W):
            for y_ in range(y, H):
                G[x_][y_] = 0

ans = 0
for g in G:
    # print (g)
    ans += sum(g)

print (ans)

Submission status: Accepted

Solution code:
def examA():
    C = [SI()for _ in range(3)]
    ans = C[0][0]+C[1][1]+C[2][2]
    print(ans)
    return

def examB():
    N, M = LI()
    P = [0]*N
    S = [LSI()for _ in range(M)]
    pena = 0
    ac = set()
    for p,s in S:
        p = int(p)-1
        if s=="WA":
            P[p] += 1
        else:
            if p in ac:
                continue
            ac.add(p)
            pena += P[p]

    print(len(ac),pena)
    return

def examC():
    W, H, N = LI()
    lx, rx, ly, ry = 0, W, 0, H
    A = [LI()for _ in range(N)]
    for x,y,a in A:
        if a==1:
            lx = max(lx,x)
        elif a==2:
            rx = min(rx,x)
        elif a==3:
            ly = max(ly,y)
        elif a==4:
            ry = min(ry,y)
    ans = max(0,rx-lx)*max(0,ry-ly)
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(readline())
def LI(): return list(map(int,readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examC()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Submission status: Accepted

Solution code:

import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/abc047/tasks/abc047_b
# a=1のなかで一番大きい値をXとするとき、x<Xはすべて黒く塗られる
# a=2のなかで一番小さい値Xとするとき、X<xはすべて黒く塗られる
# a=3→一番大きいY、y<Y
# a=4→一番小さいY、Y<y は塗る
W, H, N = read_ints()
A = [0, W, 0, H]
for _ in range(N):
    x, y, a = read_ints()
    a -= 1
    if a == 0:
        A[a] = max(x, A[a])
    if a == 1:
        A[a] = min(x, A[a])
    if a == 2:
        A[a] = max(y, A[a])
    if a == 3:
        A[a] = min(y, A[a])

if A[1] - A[0] > 0 and A[3] - A[2] > 0:
    print((A[1] - A[0]) * (A[3] - A[2]))
else:
    print(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 xya:
  if i[2] == 1:
    if x[0] < i[0]:
      x[0] = i[0]
  if i[2] == 2:
    if x[1] > i[0]:
      x[1] = i[0]
  if i[2] == 3:
    if y[0] < i[1]:
      y[0] = i[1]
  if i[2] == 4:
    if y[1] > i[1]:
      y[1] = i[1]
if x[0] < x[1] and y[0] < y[1]:
  print((x[1]-x[0])*(y[1]-y[0]))
else:
  print(0)

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
l, t, r, b = 0, 0, W, H
for _ in range(N):
  x, y, a = map(int, input().split())
  if a == 1: l = min(max(l, x), r)
  if a == 2: r = max(min(r, x), l)
  if a == 3: t = min(max(t, y), b)
  if a == 4: b = max(min(b, y), t)

print((r-l)*(b-t))

Submission status: Accepted

Solution code:
import numpy as np

W, H, N = map(int, input().split())
Map = np.zeros([W, H], dtype=int)

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

print(H*W - Map.sum())

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
minx=0
maxx=W
miny=0
maxy=H
for i in range(1,N+1):
    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)
ans=(maxx-minx)*(maxy-miny)
if maxx>=minx and maxy>=miny:
    print(ans)
elif maxx<=minx and maxy>=miny:
    print("0")
elif maxx>=minx and maxy<=miny:
    print("0")
elif maxx<=minx and maxy<=miny:
    print("0")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
W, H, N = map(int, readline().split())
XYA = [tuple(map(int, readline().split())) for _ in range(N)]


def f(i, j, xya):
    x, y, a = xya
    if ((a == 1 and i > x) or
        (a == 2 and i <= x) or 
        (a == 3 and j > y) or
        (a == 4 and j <= y)):
        return True
    else:
        return False

ans = 0
for i in range(1, W+1):
    for j in range(1, H+1):
        if all(f(i, j, xya) for xya in XYA):
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
x=[]
y=[]
a=[]
for i in range(n):
    a1,b,c=map(int,input().split())
    x.append(a1)
    y.append(b)
    a.append(c)

w1=0#左の削り
w2=0#右の削り
h1=0#下の削り
h2=0#上の削り
for i in range(n):
    if a[i]==1:
        w1=max(w1,x[i])
    if a[i]==2:
        w2=max(w2,w-x[i])
    if a[i]==3:
        h1=max(h1,y[i])
    if a[i]==4:
        h2=max(h2,h-y[i])


if (w-w1-w2)<0 and (h-h1-h2)<0:
    print(0)
else:
    print(max(0,(w-w1-w2)*(h-h1-h2)))

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
X = [0]*N
Y = [0]*N
A = [0]*N
X_max= W
X_min= 0
Y_max= H
Y_min= 0
for i in range(N):
	X[i],Y[i],A[i] = map(int,input().split())
for i in range(N):
	if A[i]==1:
		X_min=max(X_min,X[i])
	elif A[i]==2:X_max=min(X_max,X[i])
	elif A[i]==3:Y_min=max(Y_min,Y[i])
	else:Y_max=min(Y_max,Y[i])

if X_max-X_min>0 and Y_max-Y_min>0:
	print((X_max-X_min)*(Y_max-Y_min))
else: print(0)

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
X0 = 0
X = W
Y0 = 0
Y = H
for _ in range(N):
    x,y,a = map(int,input().split())
    if a == 1:
        X0 = max(X0,x)
    elif a == 2:
        X = min(X,x)
    elif a == 3:
        Y0 = max(Y0,y)
    else: # a == 4
        Y = min(Y,y)

if X0 >= X or Y0 >= Y:
    print (0)
else:
    print ((X-X0)*(Y-Y0))

Submission status: Accepted

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

Submission status: Accepted

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

x_list = []
for i in range(w+1):
    x_list += [i]
    
y_list = []
for i in range(h+1):
    y_list += [i]  

for i in range(q):
    a, b, c = map(int, input().split())
    if (c == 1):
        x_list = [x for x in x_list if x >= a]
    elif (c == 2):
        x_list = [x for x in x_list if x <= a]
    elif (c == 3):
        y_list = [y for y in y_list if y >= b]
    elif (c == 4):
        y_list = [y for y in y_list if y <= b]

output = 0
if (x_list != [] and y_list != []):
    output = (max(x_list)-min(x_list)) * (max(y_list)-min(y_list))
    
print(output)

Submission status: Accepted

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

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

x = (0, W)
y = (0, H)
for xya in XYA:
    a = xya[2]
    if a == 1:
        if x[0] < xya[0]:
            x = (xya[0], x[1])
    elif a == 2:
        if xya[0] < x[1]:
            x = (x[0], xya[0])
    elif a == 3:
        if y[0] < xya[1]:
            y = (xya[1], y[1])
    else:
        if xya[1] < y[1]:
            y = (y[0], xya[1])

res = (x[1] - x[0]) * (y[1] - y[0])
if x[1] - x[0] < 0 or y[1] - y[0] < 0:
    res = 0

print(res)

Submission status: Accepted

Solution code:
left = 0 
down = 0
right , up , n =map(int,input().split())
for _ in range(n):
	x,y,a = map(int,input().split())
	if a==1:
		if x>left:
			left = x
	elif a==2:
		if right>x:
			right = x
	elif a==3:
		if y>down:
			down = y
	elif a==4:
		if up>y:
			up = y
if abs(right)>=abs(left) and abs(up)>=abs(down):
	h = abs(up)-abs(down)
	w = abs(right)-abs(left)
	print(h*w)
else:
	print(0)

Submission status: Accepted

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

for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        x0 = max(x0, x) 
    elif a == 2:
        x1 = min(x1, x)
    elif a == 3:
        y0 = max(y0, y)
    elif a == 4:
        y1 = min(y1, y)

print((x1 - x0) * (y1 - y0) if x1-x0 > 0 and y1 - y0 > 0 else 0)

Submission status: Accepted

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

x1,x2,y1,y2 = 0,w,0,h
for _ in range(n):
    x,y,a = map(int, input().split())
    if a==1:
        x1 = max(x1,x)
    elif a==2:
        x2 = min(x2,x)
    elif a==3:
        y1 = max(y1,y)
    else:
        y2 = min(y2,y)

if x1>=x2:
    print(0)
    exit()
if y1>=y2:
    print(0)
    exit()

print((x2-x1)*(y2-y1))

Submission status: Accepted

Solution code:
w, h, n = map(int,input().split())
a_1 = 0
a_2 = w
a_3 = 0
a_4 = h
for i in range(n):
    x, y, a = map(int,input().split())
    if a == 1:
        a_1 = max(a_1,x)
    elif a == 2:
        a_2 = min(a_2,x)
    elif a == 3:
        a_3 = max(a_3,y)
    else:
        a_4 = min(a_4,y)

if a_1 > a_2:
    print(0)
elif a_3 > a_4:
    print(0)
else:
    print((a_2-a_1)*(a_4-a_3))

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
max1=0
min2=W
max3=0
min4=H
for i in range(N):
    x, y, a = map(int, input().split())
    if (a==1 and max1<x):
        max1=x
    elif(a==2 and min2>x):
        min2=x
    elif(a==3 and max3<y):
        max3=y
    elif(a==4 and min4>y):
        min4=y

if (max1>=min2 or max3>=min4):
    print(0)
else:
    print((min2-max1)*(min4-max3))

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 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)
    else:
        y_max = min(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())

x, y, a = [0] * n, [0] * n, [0] * n

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

start, end  = [0, 0], [w, h]

for i in range(n):
    if a[i] == 1 and x[i] > start[0]:
        start[0] = x[i]
    elif a[i] == 2 and x[i] < end[0]:
        end[0] = x[i]
    elif a[i] == 3 and start[1] < y[i]:
        start[1] = y[i]
    elif a[i] == 4 and end[1] > y[i]:
        end[1] = y[i]
    
if (end[0] - start[0]) <= 0 or (end[1] - start[1]) <= 0:
    print(0)
else:
    print( (end[0] - start[0]) * (end[1] - start[1]))

Submission status: Accepted

Solution code:

w, h, n = map(int, input().split())
x, y, a = [0] * n, [0] * n, [0] * n

for i in range(n):
    x[i], y[i], a[i] = map(int, input().split())
fill_area = [[0] * w for _ in range(h)]

def fill(l, r, d, u, area):
    for i in range(d, u):
        for j in range(l, r):
            if area[i][j] == 0:
                area[i][j] = 1
        
    

for i in range(n):
    if a[i] == 1:
        fill(0, x[i], 0,  h, fill_area)
    elif a[i] == 2:
        fill(x[i], w, 0, h, fill_area)
    elif a[i] == 3:
        fill(0, w, h - y[i], h, fill_area)
    else:
        fill(0, w, 0, h - y[i], fill_area)
    """
    for j in range(h):
        print(fill_area[j])
    print()
    """
#print(sum(map(sum, fill_area)))
print(h * w - sum(map(sum, fill_area)))

Submission status: Accepted

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

def draw(x0, x1, y0, y1):
    for y in range(y0, y1 + 1):
        for x in range(x0, x1 + 1):
            field[y][x] = "#"

for i in range(n):
    X, Y, a = map(int, input().split())
    if a == 1:
        draw(0, X - 1, 0, h - 1)
    elif a == 2:
        draw(X, w - 1, 0, h - 1)
    elif a == 3:
        draw(0, w - 1, 0, Y - 1)
    elif a == 4:
        draw(0, w - 1, Y, h - 1)

c = 0
for y in range(h):
    for x in range(w):
        if field[y][x] == "":
            c += 1

print(c)

Submission status: Accepted

Solution code:
#Beginner 047 B
W, H, N = map(int, input().split())

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

lst = [[1 for i in range(W)] for j in range(H)]

for i in range(N):
    if S[i][2] == 1:
        for j in range(0,S[i][0]):
            for k in range(H):
                lst[k][j] = 0
    if S[i][2] == 2:
        for j in range(S[i][0],W):
            for k in range(H):
                lst[k][j] = 0
    if S[i][2] == 3:
        for j in range(0,S[i][1]):
            for k in range(W):
                lst[j][k] = 0
    if S[i][2] == 4:
        for j in range(S[i][1],H):
            for k in range(W):
                lst[j][k] = 0

print(sum(lst,[]).count(1))

Submission status: Accepted

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

    grid = [[0]*(W + 1) for _ in range(H + 1)]
    for x, y, a in XYA:
        sx = 1
        sy = 1
        fx = W
        fy = H
        if a == 1:
            fx = x
        elif a == 2:
            sx = x + 1
        elif a == 3:
            fy = y
        else:
            sy = y + 1
        for i in range(sx, fx + 1):
            for j in range(sy, fy + 1):
                grid[j][i] = 1
    ans = W*H
    for i in range(1, W + 1):
        for j in range(1, H + 1):
            if grid[j][i]:
                ans -= 1
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

X_min = 0
X_max = W
Y_min = 0
Y_max = H

for 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)
print(max([(X_max-X_min),0])*max([(Y_max-Y_min),0]))

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
x_max = W
x_min = 0
y_max = H
y_min = 0
for i in range(N):
    x,y,a = map(int,input().split())
    if a == 1 and x>x_min:
        x_min = x
    elif a==2 and x<x_max:
        x_max = x
    elif a==3 and y>y_min:
        y_min = y
    elif a==4 and y<y_max:
        y_max = y
print((x_max-x_min)*(y_max-y_min) if x_max-x_min>=0 and y_max-y_min>=0 else 0)

Submission status: Accepted

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

Submission status: Accepted

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

min_x = 0
max_x = W
min_y = 0
max_y = H

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

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

Submission status: Accepted

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

def main():
    W, H, N = map(int, readline().rstrip().split())
    p = [[1] * W for _ in range(H)]
    for _ in range(N):
        x, y, a = map(int, readline().rstrip().split())
        if a == 1:
            for yi in range(H):
                for xi in range(x):
                    p[yi][xi] = 0
        elif a == 2:
            for yi in range(H):
                for xi in range(x, W):
                    p[yi][xi] = 0
        elif a == 3:
            for xi in range(W):
                for yi in range(y):
                    p[yi][xi] = 0
        else:
            for xi in range(W):
                for yi in range(y, H):
                    p[yi][xi] = 0
    
    print(sum([sum(l) for l in p]))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
W,H,N = map(int, input().split())
abc = [list(map(int, input().split())) for _ in range(N)]
w1=0
h1=0
w2=W
h2=H

for i in range(0,N):
    if abc[i][2] ==1:
        w1 = max(w1,abc[i][0])
    elif abc[i][2] ==2:
        w2 = min(w2,abc[i][0])
    elif abc[i][2] ==3:
        h1 = max(h1,abc[i][1])
    elif abc[i][2] ==4:
        h2 = min(h2,abc[i][1])

res = max((w2-w1),0)*max((h2-h1),0)
print(res)

Submission status: Accepted

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

left_x = bottom_y = 0
right_x = w
top_y = h
for x, y, a in xya:
    if a == 1:
        left_x = max(left_x, x)
    elif a == 2:
        right_x = min(right_x, x)
    elif a == 3:
        bottom_y = max(bottom_y, y)
    else:
        top_y = min(top_y, y)
if right_x <= left_x or top_y <= bottom_y:
    print(0)
else:
    print((right_x - left_x) * (top_y - bottom_y))

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:
        w1 = max(w1, x)
    elif a == 2:
        w2 = min(w2, x)
    elif a == 3:
        h1 = max(h1, y)
    elif a == 4:
        h2 = min(h2, y)
print(max(0, w2 - w1) * max(0, h2 - h1))

Submission status: Accepted

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

def view(now):
    s = ''
    now = list(reversed(now))
    for i in range(h):
        for j in range(w):
            s += str(now[i][j])
        else:
            s += '\n'
    return s
mapp = [[1]*(w)] * (h)

for i in range(n):
    if xy[i][2] == 1 or xy[i][2] == 2:
        for j in range(h):
            if xy[i][2] == 1:
                mapp[j][:xy[i][0]] = [0]*xy[i][0]

            elif xy[i][2] == 2:
                mapp[j][xy[i][0]:] = [0]*(w-xy[i][0])

    elif xy[i][2] == 3:
        for s in range(xy[i][1]):
            mapp[s] = [0] * w

    elif xy[i][2] == 4:
        for s in range(xy[i][1],h):
            mapp[s] = [0] * w

    #print(view(mapp))
ans = 0
for i in range(h):
    ans += mapp[i].count(1)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    w, h, n = map(int, input().split())
    left = 0
    right = w
    top = 0
    bottom = h
    for i in range(n):
        x, y, a = map(int, input().split())
        if a == 1:
            left = max(left, x)
        elif a == 2:
            right = min(right, x)
        elif a == 3:
            top = max(top, y)
        else:
            bottom = min(bottom, y)
    res = max(0, right - left) * max(0, bottom - top)
    print(res)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
W, H, N = map(int,input().split())
left = 0
right = W
bottom = 0
top = H
for _ in range(N):
    x, y, a = map(int,input().split())
    if a == 1:
        left = max(left, x)
    elif a == 2:
        right = min(right, x)
    elif a == 3:
        bottom = max(bottom, y)
    else:
        top = min(top, y)
ans = (right - left) * (top - bottom)
if left > right or bottom > top:
    ans = 0
print(ans)

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

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)
    if a == 2: r = min(r, x)
    if a == 3: d = max(d, y)
    if a == 4: u = min(u, y)

ans = max(0, r - l) * max(0, u - d)

print(ans)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

L = 0
R = W
D = 0
U = H

for _ in range(N):
  x,y,a = 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)

x = max(0,R-L)
y = max(0,U-D)
answer = x*y

print(answer)

Submission status: Accepted

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

A=[0,w,0,h]
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        A[0]=max(A[0],x)
    elif a==2:
        A[1]=min(A[1],x)
    elif a==3:
        A[2]=max(A[2],y)
    else:
        A[3]=min(A[3],y)

if (A[1]-A[0])<=0 or (A[3]-A[2])<=0:
    print(0)
else:
    print((A[1]-A[0])*(A[3]-A[2]))

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
S=[0]*N; p=0
for i in range(N):
  x,y,a=map(int,input().split())
  S[i]=[x,y,a]
#print("x,y,a",S)
e=101;w=-1;n=101;s=-1
for i in range(N):
  if S[i][2]==1:
    w=max(w,S[i][0])
  elif S[i][2]==2:
    e=min(e,S[i][0])
  elif S[i][2]==3:
    s=max(s,S[i][1])
  elif S[i][2]==4:
    n=min(n,S[i][1])

#print("w,e,s,n",w,e,s,n)
for i in range(1,H+1):
  for j in range(1,W+1):
    if (j<=w and w>0) or (j>e and e<101) or (i>n and n<101) or (i<=s and s>0):
      p=p+1

print(W*H-p)

Submission status: Accepted

Solution code:
from sys import stdin
import sys

[W, H, N] = list(map(int, stdin.readline().rstrip().split()))


Ws = 0
We = W

Hs = 0
He = H


A = []
for i in range(N):
    A.append(list(map(int, stdin.readline().rstrip().split())))

for i in range(N):
    [x, y, a] = A[i]
    if a == 1:
        Ws = max(Ws, x)
    elif a == 2:
        We = min(We, x)
    elif a == 3:
        Hs = max(Hs, y)
    elif a == 4:
        He = min(He, y)

if (We - Ws) <= 0 or (He - Hs) <=0:
    print(0)
else:
    print((We - Ws) * (He - Hs))

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
list_XY = [ list(map(int,input().split(" "))) for i in range(n)]
a = 0
b = w
c = 0
d = h

for l in list_XY:
    if l[2] == 1:
        a = max(a, l[0])
    elif l[2] == 2:
        b = min(b, l[0])
    elif l[2] == 3:
        c = max(c, l[1])
    elif l[2] == 4:
        d = min(d, l[1])
ans = -1
if b > a and d > c:
    ans = (b-a)*(d-c)
else:
    ans = 0

print(ans)

Submission status: Accepted

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

for i in range(N):
    x, y, a = map(int, input().split())
    a -= 1
    if a <= 1:
        A[a].append(x)
    else:
        A[a].append(y)

x1 = max(A[0])
x2 = min(A[1])
y1 = max(A[2])
y2 = min(A[3])

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

Submission status: Accepted

Solution code:
W,H,N=map(int, input().split())
l=[]
for i in range(N):
  l.append(list(map(int, input().split())))
maxmin=[0,W,0,H]
for i in range(N):
  if l[i][2] == 1 and maxmin[0] < l[i][0]:
    maxmin[0] = l[i][0]
  elif l[i][2] == 2 and maxmin[1] > l[i][0]:
    maxmin[1] = l[i][0]
  elif l[i][2] == 3 and maxmin[2] < l[i][1]:
    maxmin[2] = l[i][1]
  elif l[i][2] == 4 and maxmin[3] > l[i][1]:
    maxmin[3] = l[i][1]
if maxmin[1]-maxmin[0] >= 0 and maxmin[3]-maxmin[2] >= 0:
  print((maxmin[1]-maxmin[0])*(maxmin[3]-maxmin[2]))
else:
  print(0)