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().strip().split(" "))
paint = [0] * 4
paint[0] = -1
paint[1] = W
paint[2] = -1
paint[3] = H

for i in range(N):
    x, y, a = map(int, input().strip().split(" "))
    if a == 1:
        paint[a-1] = max(paint[a-1], x)
    elif a == 2:
        paint[a-1] = min(paint[a-1], x)
    elif a == 3:
        paint[a-1] = max(paint[a-1], y)
    elif a == 4:
        paint[a-1] = min(paint[a-1], y)

s = 0
for x in range(W):
    for y in range(H):
        if x >= paint[0] and x < paint[1] and y >= paint[2] and y < paint[3]:
            s += 1

print(s)

Submission status: Accepted

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

import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    w, h, n = mi()
    xmin, xmax, ymin, ymax = 0, w, 0, h

    for _ in range(n):
        x, y, a = mi()
        if a == 1:
            xmin = max(xmin, x)
        elif a == 2:
            xmax = min(xmax, x)
        elif a == 3:
            ymin = max(ymin, y)
        else:
            ymax = min(ymax, y)
        
    if xmin >= xmax or ymin >= ymax:
        print(0)
    else:
        print((xmax - xmin) * (ymax - ymin))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
h,w,n = map(int,input().split())
d = {1:0,2:h,3:0,4:w}
for _ in range(n):
  x,y,a = map(int,input().split())
  if a %2:
    d[a] = max(d[a],[x,y][a//2]) 
  else:
    d[a] = min(d[a],[x,y][a//2-1])

if d[1] > d[2] or d[3] > d[4]:
  print(0)
else:
  ans = (d[2]-d[1]) * (d[4]-d[3])
  print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
W,H,N=list(map(int,input().split()))
l=[[0]*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):
            l[k][j] = 1
   elif a == 2:
      for j in range(x,W):
         for k in range(H):
            l[k][j] = 1
   elif a == 3:
      for j in range(0,y):
         l[j] = [1]*W
   elif a == 4:
      for j in range(y,H):
         l[j] = [1]*W
ans=W*H
for i in range(H):
   ans-=l[i].count(1)
print(ans)

Submission status: Accepted

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

grid = np.array([[1] * W for _ in range(H)])

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

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

print(np.count_nonzero(grid.ravel()))

Submission status: Accepted

Solution code:
w,h,n = map(int, input().split())
min_x, max_x, min_y, max_y = 0, w, 0, 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 if max_x>=min_x else 0)*(max_y-min_y if max_y>=min_y else 0))

Submission status: Accepted

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

sx,sy = 0,0
gx,gy = w,h
for i in range(n):
    a,x,y = a_li[i],x_li[i],y_li[i]
    if a==1:
        sx=max(sx,x)
    if a==2:
        gx=min(gx,x)
    if a==3:
        sy=max(sy,y)
    if a==4:
        gy=min(gy,y)
x = max(0,gx-sx)
y = max(0,gy-sy)
print(x*y)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(n)]
 
xmin,xmax,ymin,ymax = 0,w,0,h
 
for a in A:
  if a[2] == 1:
    xmin = max(xmin, a[0])
  if a[2] == 2:
    xmax = min(xmax, a[0])
  if a[2] == 3:
    ymin = max(ymin, a[1])
  if a[2] == 4:
    ymax = min(ymax, a[1])
    
S = (xmax-xmin) * (ymax-ymin)
if S < 0 or xmin > xmax or ymin > ymax:
  S = 0
print(S)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
W, H, N = map(int, input().split())
area = [[1] * H for i in range(W)]

def fill(x0, y0, x1, y1):
    for j in range(x1 - x0):
        for k in range(y1 - y0):
            area[x0+j][y0+k] = 0
  
for i in range(N):
    x, y, a = map(int, input().split())
    x0 = x if a == 2 else 0
    y0 = y if a == 4 else 0
    x1 = x if a == 1 else W
    y1 = y if a == 3 else H
    fill(x0, y0, x1, y1)

print(sum(map(sum, area)))

Submission status: Accepted

Solution code:
a,b,c=map(int,input().split())
x1=0
x2=a
y1=0
y2=b
for i in range(c):
    e,f,g=map(int,input().split())
    if g==1:
        if x1<e:
            x1=e
    elif g==2:
        if x2>e:
            x2=e
    elif g==3:
        if y1<f:
            y1=f
    else:
        if y2>f:
            y2=f
if (0>(x2-x1))or(0>(y2-y1)):
    print(0)
else:
    print((x2-x1)*(y2-y1))

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
lis = []
for i in range(n):
  lis.append(list(map(int, input().split())))
x=0
y=0

for i in lis:
  if i[2] == 1:
    if x < i[0]:
      x=i[0]
  elif i[2] == 2:
    if i[0] < w:
      w=i[0]
  elif i[2] == 3:
    if y < i[1]:
      y=i[1]
  else:
    if i[1] < h:
      h=i[1]
x_a = w-x
y_a= h-y
if x_a < 0 or y_a < 0:
  print(0)
  exit()
print(x_a*y_a)

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
lis = []
xi = 0
yi = 0
xj = W
yj = H
for i in range(N):
    #lis.append(list(map(int, input().split())))
    x, y, a = map(int, input().split())
    if (a==1) and (x>xi):
        xi = x
    elif (a==2) and (x<xj):
        xj = x
    elif (a==3) and (y>yi):
        yi = y
    elif (a==4) and (y<yj):
        yj = y

x = W-xi-(W-xj)
if x<0:
    x = 0
y = H-(H-yj)-yi
if y<0:
    y = 0

print(x*y)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
x1, x2, y1, y2 = 0, W, 0, H

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

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

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
X=[list(map(int,input().split())) for _ in range(N)]
x1=0
x2=W
y1=0
y2=H
for i in range(N):
    if X[i][2]==1:
        x1=max(x1,X[i][0])
    elif X[i][2]==2:
        x2=min(x2,X[i][0])
    elif X[i][2]==3:
        y1=max(y1,X[i][1])
    else:
        y2=min(y2,X[i][1])
print((y2-y1)*(x2-x1) if (y2-y1)>0 and (x2-x1)>0 else 0)

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 = max(a1, x)
    elif a==2:
        a2 = min(a2, x)
    elif a==3:
        a3 = max(a3, y)
    elif a==4:
        a4 = min(a4, y)
        
if a1 <= a2 and a3 <= a4:
    print((a2-a1) * (a4-a3))
else:
    print(0)

Submission status: Accepted

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

limit = [0, w, 0, h]

for i in range(n):
  x, y, a = map(int, input().split())
  a -= 1
  if a == 0:
    limit[a] = max(limit[a], x)
  if a == 1:
    limit[a] = min(limit[a], x)
  if a == 2:
    limit[a] = max(limit[a], y)
  if a == 3:
    limit[a] = min(limit[a], y)
    
dx = max(0, limit[1] - limit[0])
dy = max(0, limit[3] - limit[2])
print(dx * dy)

Submission status: Accepted

Solution code:
import sys

W, H, N = map(int, sys.stdin.readline().strip().split())
opes = []
for _ in range(N):
    x, y, a = map(int, sys.stdin.readline().strip().split())
    opes.append((x, y, a))

x_min = 0
x_max = W
y_min = 0
y_max = H
for (x, y, a) in opes:
    if a == 1:
        x_min = max(x_min, x)
    elif 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)

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())
xya = [[int(i) for i in input().split()] for i in range(N)]
Lower_left = [0, 0]
Top_right = [W, H]
ans = 0
for x, y, a in xya:
    if a == 1:
        if x > Lower_left[0]:
            Lower_left[0] = x
    elif a == 2:
        if x < Top_right[0]:
            Top_right[0] = x
    elif a == 3:
        if y > Lower_left[1]:
            Lower_left[1] = y
    elif a == 4:
        if y < Top_right[1]:
            Top_right[1] = y

    if Top_right[0] > Lower_left [0] and Top_right[1] > Lower_left[1]:
        ans = (Top_right[0] - Lower_left[0]) * (Top_right[1] - Lower_left[1])
    else:
        ans = 0

print(ans)

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
XY = [1 for i in range(W * H)]
for n in range(N):
  x, y, a = map(int, input().split())
  if a == 1:
    for i in range(W * H):
      if i % W < x :
      	XY[i] = 0 
  if a == 2:
    for i in range(W * H):
      if i % W >= x:
      	XY[i] = 0
  if a == 3:
    for i in range(y * W):
      XY[i] = 0 
  if a == 4:
    for i in range(y * W, W * H):
      XY[i] = 0 
print(sum(XY))

Submission status: Accepted

Solution code:
W, H, N = map(int,input().split())
xya = [list(map(int,input().split())) for _ in range(N)]
ls = list(range(1,W*H+1))
for n in range(N):
  if xya[n][2] == 1:
    ls = [K for K in ls if (K-1)%W >= xya[n][0]]
  if xya[n][2] == 2:
    ls = [K for K in ls if (K-1)%W < xya[n][0]]
  if xya[n][2] == 3:
    ls = [K for K in ls if (K-1)/W >= xya[n][1]]
  if xya[n][2] == 4:
    ls = [K for K in ls if (K-1)/W <= xya[n][1]]
print(len(ls))

Submission status: Accepted

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

    corners = [0, 0, w, h]

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

        if a == 1:
            if x > corners[0]:
                corners[0] = x
        elif a == 2:
            if x < corners[2]:
                corners[2] = x
        elif a == 3:
            if y > corners[1]:
                corners[1] = y
        else:
            if y < corners[3]:
                corners[3] = y
    
    width = corners[2] - corners[0]
    height = corners[3] - corners[1]

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

p1 = (0, 0)
p2 = (w, h)

for i in range(n):
    x, y, a = list(map(int, input().split()))
    if a == 1:
        if p1[0] < x:
            p1 = (x, p1[1])
    elif a == 2:
        if p2[0] > x:
            p2 = (x, p2[1])
    elif a == 3:
        if p1[1] < y:
            p1 = (p1[0], y)
    elif a == 4:
        if p2[1] > y:
            p2 = (p2[0], y)

area = (max(p2[0]-p1[0], 0))*(max(p2[1]-p1[1], 0))
print(area)

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):
    a,b,c=map(int,input().split())
    if c==1:
        w1=max(a,w1)
    elif c==2:
        w2=min(a,w2)
    elif c==3:
        h1=max(b,h1)
    elif c==4:
        h2=min(b,h2)
if w2<=w1 or h2<=h1:
    print(0)
else:
    print(max(0,(w2-w1)*(h2-h1)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
w,h,n=map(int,input().split())
li=[list(map(int,input().split())) for i in range(n)]
#[[x1,y1,a1],[x2,y2,a2]]
a=np.zeros((h,w))

for i in range(n):
    lis=li[i]
    if lis[2]==1:
        a[:,:lis[0]]=1
    elif lis[2]==2:
        a[:,lis[0]:]=1
    elif lis[2]==3:
        a[:lis[1],:]=1
    elif lis[2]==4:
        a[lis[1]:,:]=1

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
import numpy as np

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

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

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

for this_order in inputs:
    if this_order[2] == 1:
        maps[0:, :this_order[0]+1] = 1
    elif this_order[2] == 2:
        maps[0:, this_order[0]+1:] = 1
    elif this_order[2] == 3:
        maps[:this_order[1]+1] = [1] * (W+1)
    else:
        maps[this_order[1]+1:] = [1] * (W+1)

ans = 0
for i in range(1, H+1):
    for j in range(1, W+1):
        if maps[i][j] == 0:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]
M = [[0] * W for i in range(H)]
for x in X:
    if x[2] == 1:
        for i in range(0, x[0]):
            for j in range(H):
                M[j][i] = 1
    elif x[2] == 2:
        for i in range(x[0], W):
            for j in range(H):
                M[j][i] = 1
    elif x[2] == 3:
        for i in range(0, x[1]):
            for j in range(W):
                M[i][j] = 1
    elif x[2] == 4:
        for i in range(x[1], H):
            for j in range(W):
                M[i][j] = 1
c = 0
for i in range(W):
    for j in range(H):
        if M[j][i] == 0:
            c += 1
print(c)

Submission status: Accepted

Solution code:
def cin():
	return map(int,input().split())

def cino(test=False):
    if not test:
        return int(input())
    else:
        return input()
def cina():
  return list(map(int,input().split()))


a,b,c  = cin()
p = -1
q = 1e9
r = -1
s = 1e9
for i in range(c):
  x,y,z = cin()
  if z==1:
    p = max(x,p)
  elif z==2:
    q = min(x,q)
  elif z==3:
    r = max(r,y)
  else:
    s = min(s,y)

if p==-1:
    p = 0
if q==1e9:
    q = a
if r==-1:
    r=0
if s==1e9:
    s=b

ans = (q-p)*(s-r)
if p>q or r>s:
    print(0)
else:
    print(ans)

Submission status: Accepted

Solution code:
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===
def main():
    w, h, n = ns()

    max_x = -1
    min_x = INF
    max_y = -1
    min_y = INF

    for _ in range(n):
        x, y, a = ns()

        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)
        elif a == 4:
            min_y = min(min_y, y)

    if max_x == -1:
        max_x = 0
    if min_x == INF:
        min_x = w
    if max_y == -1:
        max_y = 0
    if min_y == INF:
        min_y = h

    len_x = max(0, min_x - max_x)
    len_y = max(0, min_y - max_y)

    print(len_x * len_y)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

WX=[0,W]
HY=[0,H]

i=0
while i<N:
    if XYA[i][2]==1:
        WX[0]=max(WX[0],XYA[i][0])
    elif XYA[i][2]==2:
        WX[1]=min(WX[1],XYA[i][0])
    elif XYA[i][2]==3:
        HY[0]=max(HY[0],XYA[i][1])
    elif XYA[i][2]==4:
        HY[1]=min(HY[1],XYA[i][1])
    i+=1

ans=max(0,WX[1]-WX[0])*max(0,HY[1]-HY[0])
print(ans)

Submission status: Accepted

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

X = Y = 0

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

    if a == 1:
        X = max(X, x)
    elif a == 2:
        W = min(W, x)
    elif a == 3:
        Y = max(Y, y)
    else:
        H = min(H, y)

print(max(W-X, 0)*max(H-Y, 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)
    elif a == 2:
        x2 = min(x2,x)
    elif a == 3:
        y1 = max(y1,y)
    elif a == 4:
        y2 = min(y2,y)

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

Submission status: Accepted

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

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

bottom = 0
left = 0
top = H
right = W

D_LEFT = 1
D_RIGHT = 2
D_BOTTOM = 3
D_TOP = 4

for x, y, direction in points:
    if direction == D_RIGHT:
        right = min(right, x)
    elif direction == D_LEFT:
        left = max(left, x)
    elif direction == D_BOTTOM:
        bottom = max(bottom, y)
    elif direction == D_TOP:
        top = min(top, y)

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

Submission status: Accepted

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

white_check = list()
for a in range(0, h):
    white_check.append([1]*w)

for i in range(0, n):
    a = l[i][2]
    height = l[i][1]
    width = l[i][0]

    if a == 1:
        for y in range(0, h):
            for x in range(0, width):
                white_check[y][x] = 0
    elif a == 2:
        for y in range(0, h):
            for x in range(width, w):
                white_check[y][x] = 0
    elif a == 3:
        for y in range(0, height):
            for x in range(0, w):
                white_check[y][x] = 0
    else:
        for y in range(height, h):
            for x in range(0, w):
                white_check[y][x] = 0

s = 0

for a in range(h):
    s += sum(white_check[a])

print(s)

Submission status: Accepted

Solution code:
W, H, N = [int(i) for i in input().split()]
xx = []
yy = []
aa = []
for _ in range(N):
    x, y, a = [int(i) for i in input().split()]
    xx.append(x)
    yy.append(y)
    aa.append(a)

xs, ys = 0, 0
xe, ye = W, H
for i in range(N):
    if aa[i] == 1:
        xs = max(xs, xx[i])
    elif aa[i] == 2:
        xe = min(xe, xx[i])
    elif aa[i] == 3:
        ys = max(ys, yy[i])
    else:
        ye = min(ye, yy[i])

if xs < xe and ys < ye:
    print((xe - xs) * (ye - ys))
else:
    print(0)

Submission status: Accepted

Solution code:

def myAnswer(W:int,H:int,N:int,X:list,Y:list,A:list) -> int:
   startX = 0
   endX = W
   startY = 0
   endY = H
   for x,y,a in zip(X,Y,A):
      if(a == 1):
         startX = max(startX,x)
      elif(a == 2):
         endX = min(endX,x)
      elif(a == 3):
         startY = max(startY,y)
      elif(a == 4):
         endY = min(endY,y)
   # print(startX,endX,startY,endY)
   return 0 if(startX > endX or startY > endY) else (endX - startX) * (endY - startY)

def modelAnswer():
   return
def main():
   W,H,N = map(int,input().split())
   X = []
   Y = []
   A = []
   for _ in range(N):
      x,y,a = map(int,input().split())
      X.append(x)
      Y.append(y)
      A.append(a)
   print(myAnswer(W,H,N,X,Y,A))
if __name__ == '__main__':
   main()

Submission status: Accepted

Solution code:

def myAnswer(W:int,H:int,N:int,X:list,Y:list,A:list) -> int:
   startX = 0
   endX = W
   startY = 0
   endY = H
   for x,y,a in zip(X,Y,A):
      if(a == 1 and startX < x):
         startX = x
      elif(a == 2 and endX > x):
         endX = x
      elif(a == 3 and startY < y):
         startY = y
      elif(a == 4 and endY > y):
         endY = y
   # print(startX,endX,startY,endY)
   # return (endX - startX) * (endY - startY)
   return 0 if(startX > endX or startY > endY) else (endX - startX) * (endY - startY)

def modelAnswer():
   return
def main():
   W,H,N = map(int,input().split())
   X = []
   Y = []
   A = []
   for _ in range(N):
      x,y,a = map(int,input().split())
      X.append(x)
      Y.append(y)
      A.append(a)
   print(myAnswer(W,H,N,X,Y,A))
if __name__ == '__main__':
   main()

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
left = 0
right = w
down = 0
up = 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:
        down = max(down, y)
    elif a == 4:
        up = min(up, y)

    if right - left <= 0 or up - down <= 0:
        print(0)
        exit()

ans = (right - left) * (up - down)
print(ans)

Submission status: Accepted

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

S = [[0 for j in range(W)] for i in range(H)]

for k in range(N):
  if X[k][2]==1:
    for i in range(H):
      for j in range(X[k][0]):
        S[i][j]=1
    #print(S,'1') 
  elif X[k][2]==2:
    for i in range(H):
      for j in range(X[k][0],W):
        S[i][j]=1
    #print(S,'2') 
  elif X[k][2]==3:
    for i in range(X[k][1]):
      for j in range(W):
        S[i][j]=1
    #print(S,'3') 
  elif X[k][2]==4:
    for i in range(X[k][1],H):
      for j in range(W):
        S[i][j]=1
    #print(S,'4') 
z=0
for i in range(H):
  z+=S[i].count(0)
print(z)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
xyn_list = [list(map(int,input().split())) 
            for nesya in range(n)]
hoge1 = 0
hoge2 = w
hoge3 = 0
hoge4 = h
for xyn in xyn_list:
  a = xyn[2]
  if a == 1:
    if hoge1 < xyn[0]:
      hoge1 = xyn[0]
  elif a == 2:
    if hoge2 > xyn[0]:
      hoge2 = xyn[0]
  elif a ==3:
    if hoge3 < xyn[1]:
      hoge3 = xyn[1]
  else:
    if hoge4 > xyn[1]:
      hoge4 = xyn[1]
if hoge4 > hoge3 and hoge2 > hoge1:
  ans = (hoge4-hoge3)*(hoge2-hoge1)
else:
  ans = 0
print(ans)

Submission status: Accepted

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

x_axis = [0, W]
y_axis = [0, H]

for x, y, a in xya:
    if a == 1 and x_axis[0] <= x:
        x_axis[0] = x

    elif a == 2 and x <= x_axis[1]:
        x_axis[1] = x

    elif a == 3 and y_axis[0] <= y:
        y_axis[0] = y

    elif a == 4 and y <= y_axis[1]:
        y_axis[1] = y

if x_axis[1] - x_axis[0] <=0 or y_axis[1] - y_axis[0] <=0:
    print(int(0))

else:
    print((x_axis[1] - x_axis[0]) * (y_axis[1] - y_axis[0]))

Submission status: Accepted

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9+7


w,h,n = map(int,input().split())
whiteXmin = 0
whiteXmax = w
whiteYmin = 0
whiteYmax = h
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        whiteXmin = max(x,whiteXmin)
    if a == 2:
        whiteXmax = min(x,whiteXmax)
    if a == 3:
        whiteYmin= max(y,whiteYmin)
    if a == 4:
        whiteYmax = min(y,whiteYmax)

if whiteXmax - whiteXmin < 0 or whiteYmax-whiteYmin < 0:
    print(0)
    sys.exit()
print((whiteXmax-whiteXmin)*(whiteYmax-whiteYmin))

Submission status: Accepted

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

xmin,xmax,ymin,ymax = 0,w,0,h

for a in A:
  if a[2] == 1:
    xmin = max(xmin, a[0])
  if a[2] == 2:
    xmax = min(xmax, a[0])
  if a[2] == 3:
    ymin = max(ymin, a[1])
  if a[2] == 4:
    ymax = min(ymax, a[1])
    
S = (xmax-xmin) * (ymax-ymin)
if S < 0 or xmin > xmax or ymin > ymax:
  S = 0
print(S)

Submission status: Accepted

Solution code:
w,h,n = map(int, input().split())
xl, xu, yl, 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:
    xu = min(xu, x)
  elif a == 3:
    yl = max(yl, y)
  else:
    yu = min(yu, y)

if xl >= xu or yl >= yu:
  print(0)
else:
  print((xu-xl)*(yu-yl))

Submission status: Accepted

Solution code:
W, H, N = list(map(int, input().split()))
A = []
for _ in range(N):
  A.append(list(map(int, input().split())))
  
xmax, xmin, ymax, ymin = W, 0, H, 0
for a in A:
  if a[2] == 1:
    xmin = max(xmin, a[0])
  if a[2] == 2:
    xmax = min(xmax, a[0])
  if a[2] == 3:
    ymin = max(ymin, a[1])
  if a[2] == 4:
    ymax = min(ymax, a[1])
    
S = (xmax-xmin) * (ymax-ymin)
if S < 0 or xmin > xmax or ymin > ymax:
  S = 0
print(S)

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)
  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)
  #print(x_min,x_max,y_min,y_max)
print( max(0,x_max-x_min)*max(0,y_max-y_min) )