Problem:


Score : 200 points

Problem Statement

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

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

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

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

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

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

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

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

Constraints

1 ≦ W, H ≦ 100

1 ≦ N ≦ 100

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

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

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

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

Input

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

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

Output

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

Sample Input 1

5 4 2
2 1 1
3 3 4

Sample Output 1

9

The figure below shows the rectangle before Snuke starts painting.

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

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

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

Sample Input 2

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

Sample Output 2

0

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

Sample Input 3

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

Sample Output 3

64



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


Sample output:
9

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
ll_x, ll_y, tr_x, tr_y = 0, 0, w, h
for q in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        ll_x = max(ll_x, x)
    elif a == 2:
        tr_x = min(tr_x, x)
    elif a == 3:
        ll_y = max(ll_y, y)
    elif a == 4:
        tr_y = min(tr_y, y)
ans = (tr_x - ll_x) * (tr_y - ll_y)
if (ll_x > tr_x) or (ll_y > tr_y):
    ans = 0
print(ans if ans > 0 else 0)

Submission status: Accepted

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

min_w = 0
max_w = w
min_h = 0
max_h = h

for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        min_w = max(x,min_w)
    elif a == 2:
        max_w = min(x,max_w)
    elif a == 3:
        min_h = max(y,min_h)
    elif a == 4:
        max_h = min(y,max_h)

if (max_h - min_h) <= 0 or (max_w - min_w) <= 0:
    print(0)
else:
    print((max_h - min_h)*(max_w - min_w))

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
m=[[0]*W for i in range(H)]
ans=W*H

def c(a,b):
    global ans
    if m[a][b]==0:
        m[a][b]=1
        ans-=1
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): c(j,k)
    if a==2:
        for j in range(H):
            for k in range(x,W): c(j,k)
    if a==3:
        for j in range(y):
            for k in range(W): c(j,k)
    if a==4:
        for j in range(y,H):
            for k in range(W):c(j,k)
print(ans)

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
x = []
y = []
a = []
for i in range(n):
  xi, yi, ai = map(int, input().split())
  x.append(xi)
  y.append(yi)
  a.append(ai)
xmin = 0
xmax = w
ymin = 0
ymax = h
for i in range(n):
  if a[i] == 1:
    xmin = max(xmin, x[i])
  elif a[i] == 2:
    xmax = min(xmax, x[i])
  elif a[i] == 3:
    ymin = max(ymin, y[i])
  else:
    ymax = min(ymax, y[i])
print(max(0, xmax - xmin) * max(0, ymax - ymin))

Submission status: Accepted

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

ans = 0
f = 0
for e in xya:
  x = e[0]
  y = e[1]
  a = e[2]
  if a == 1:
    ld[0] = max(x, ld[0])
  elif a == 2:
    ru[0] = min(x, ru[0])
  elif a == 3:
    ld[1] = max(y, ld[1])
  elif a == 4:
    ru[1] = min(y, ru[1])

  if ld[0] < ru[0] and ld[1] < ru[1]:
    next
  else:
    f = 1
    break

if f == 1:
  ans = 0
else:
  ans = abs(ru[0] - ld[0]) * abs(ru[1] - ld[1])
print(ans)

Submission status: Accepted

Solution code:
def area(x1,y1,x2,y2):
    if x1 >= x2 or y1 >= y2:
        ans = 0
    else:
        ans = (x2-x1)*(y2-y1)
    return(ans)
w,h,n = map(int,input().split())
xy = [0]*n
for i in range(n):
    xy[i] = list(map(int,input().split()))

x1,y1 = 0,0
x2,y2 = w,h
for x,y,a in xy:
    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(area(x1,y1,x2,y2))

Submission status: Accepted

Solution code:
W, H, count = map(int, input().split(" "))
W0 = 0
H0 = 0

li = [list(map(int, input().split(" "))) for s in range(count)]

for i in li:
  if i[2] == 1:
    if i[0] > W0:
      W0 = i[0]
  elif i[2] == 2:
    if i[0] < W:
      W = i[0]
  elif i[2] == 3:
    if i[1] > H0:
      H0 = i[1]
  elif i[2] == 4:
    if i[1] < H:
      H = i[1]
      
if W - W0 <= 0 or H - H0 <= 0:
  print(0)
else:
  print((W - W0) * (H - H0))

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
left_x = 0
right_x = w
up_y = h
down_y = 0
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        left_x = max(left_x, x)
    elif a == 2:
        right_x = min(right_x, x)
    elif a == 3:
        down_y = max(down_y, y)
    else:
        up_y = min(up_y, y)

if right_x - left_x > 0 and up_y - down_y > 0:
    ans = (right_x - left_x) * (up_y - down_y)
else:
    ans = 0
print(ans)

Submission status: Accepted

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

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

    if a == 2:
        for i in range(h):
            for j in range(w):
                if j >= x:
                    area[i][j] = 1

    if a == 3:
        for i in range(h):
            for j in range(w):
                if i < y:
                    area[i][j] = 1

    if a == 4:
        for i in range(h):
            for j in range(w):
                if i >= y:
                    area[i][j] = 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())

x_lt = 0
x_rt = W

y_lt = 0
y_rt = H

for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        x_lt = max(x, x_lt)
    elif a == 2:
        x_rt = min(x, x_rt)
    elif a == 3:
        y_lt = max(y, y_lt)
    else:
        y_rt = min(y, y_rt)

res = max(x_rt - x_lt, 0) * max(y_rt - y_lt, 0)

print(res)

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
D = [0, W, 0, H]
#D={0:max 1:min 2:max 3:min}

for _ in range(N):
    x, y, a = map(int, input().split())
    if a==1:
        if x > D[0]:
            D[0] = x
    if a==2:
        if x < D[1]:
            D[1] = x
    if a==3:
        if y > D[2]:
            D[2] = y
    if a==4:
        if y < D[3]:
            D[3] = y
ANS = (D[1] - D[0])*(D[3] - D[2])
if (D[1] - D[0] < 0) | (D[3] - D[2] < 0):
    ANS = 0
print(ANS)

Submission status: Accepted

Solution code:
def square() : 
  
  W , H, N = tuple(map(int, input().split()))
  
  leftrange = 0
  lowrange = 0
  rightrange = W
  upperrange = H
  
  for i in range(N) : 
    x, y, a = tuple(map(int, input().split()))
    if a == 1 :
      if x > leftrange : 
        leftrange = x
    if a == 2 : 
      if x < rightrange : 
        rightrange = x
    if a == 3 :
      if y > lowrange : 
        lowrange = y
    if a == 4 : 
      if y < upperrange : 
        upperrange = y
        
  return leftrange, rightrange, lowrange, upperrange

def answer(x1, x2, y1, y2) : 
  if (x1 >= x2 or y1 >= y2) : 
    return 0
  return (x2 - x1) * (y2 - y1)

def main() : 
  leftrange, rightrange, lowrange, upperrange = square()
  print(answer(leftrange, rightrange, lowrange, upperrange))
  
  
main()

Submission status: Accepted

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

rx, uy = W, H
lx, dy = 0, 0
for v in P:
    x, y, a = v
    if a == 1:
        lx = max(lx, x)
    elif a == 2:
        rx = min(rx, x)
    elif a == 3:
        dy = max(dy, y)
    elif a == 4:
        uy = min(uy, y)
print(max(rx - lx, 0) * max(uy - dy, 0))

Submission status: Accepted

Solution code:
X, Y, N = map(int, input().split())
canvas = [[1 for _ in range(X)]for _ in range(Y)]

for i in range(N):
    x,y,a = map(int,input().split())
    if a == 1:
        for j in range(Y):
            for k in range(x):
                canvas[j][k] = 0
    if a == 2:
        for j in range(Y):
            for k in range(x,X):
                canvas[j][k] = 0
    if a == 3:
        for j in range(X):
            for k in range(y):
                canvas[k][j] = 0
    if a == 4:
        for j in range(X):
            for k in range(y,Y):
                canvas[k][j] = 0
print(sum([sum(i) for i in canvas]))

Submission status: Accepted

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

if end[0] - start[0] > 0 and end[1] - start[1] > 0:
    print((end[0] - start[0])*(end[1] - start[1]))
else:
    print(0)

Submission status: Accepted

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
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 S(): return input()
def LS(): return input().split()


w, h, n = LI()
ws = list(range(w + 1))
hs = list(range(h + 1))
for _ in range(n):
    x, y, a = LI()
    if a == 1:
        ws = [i for i in ws if x <= i]
    elif a == 2:
        ws = [i for i in ws if i <= x]
    elif a == 3:
        hs = [i for i in hs if y <= i]
    else:
        hs = [i for i in hs if i <= y]
if len(ws) == 0 or len(hs) == 0:
    ans = 0
else:
    ans = (ws[-1] - ws[0]) * (hs[-1] - hs[0])
print(ans)

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
a1, a2, a3, a4 = [], [], [], []
dispatch = {1: a1, 2: a2, 3: a3, 4: a4}
for _ in range(N):
    x, y, a = map(int, input().split())
    dispatch[a].append((x, y))

a1x = max(a1, key=lambda x: x[0])[0] if a1 else 0
a2x = min(a2, key=lambda x: x[0])[0] if a2 else W
a3y = max(a3, key=lambda x: x[1])[1] if a3 else 0
a4y = min(a4, key=lambda x: x[1])[1] if a4 else H

if a2x - a1x > 0 and a4y - a3y > 0:
    print((a2x - a1x) * (a4y - a3y))
else:
    print(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(x,x1)
    elif a == 2:
        x2 = min(x,x2)
    elif a == 3:
        y1 = max(y,y1)
    else:
        y2 = min(y,y2)
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())

up=h
down=0
left=0
right=w


for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        left=max(left,x)
    if a==2:
        right=min(right,x)
    if a==3:
        down=max(down,y)
    if a==4:
        up=min(up,y)

   
if right>left and up>down:
    print((right-left)*(up-down))
else:
    print(0)

Submission status: Accepted

Solution code:
# -*- coding : utf-8 -*- 

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


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

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
a1, a2, a3, a4 = 0, W, 0, H
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        a1 = max(a1,x)
    elif a == 2:
        a2 = min(a2,x)
    elif a == 3:
        a3 = max(a3, y)
    else:
        a4 = min(a4, y)
if a1>=a2 or a3>=a4:
    print(0)
else:
    print((a2-a1)*(a4-a3))

Submission status: Accepted

Solution code:
import numpy as np

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


BW = np.zeros([H,W])

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        BW[:, :x] = 1
    elif a == 2:
        BW[:, x:] = 1
    elif a == 3:
        BW[H-y:, :] = 1
    elif a == 4:
        BW[:H-y, :] = 1
print(np.count_nonzero(BW-1))

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(n)]
a,b,c,d=0,w,0,h
for x,y,A in l:
    if A==1:
        a=max(a,x)
    elif A==2:
        b=min(b,x)
    elif A==3:
        c=max(c,y)
    else:
        d=min(d,y)
if b-a>=0 and d-c>=0:
    print((b-a)*(d-c))
else:
    print(0)

Submission status: Accepted

Solution code:
import numpy as np

n,m,l = map(int,input().split())
X = [1]*n
Y = [1]*m

for i in range(l):
    x,y,a = map(int,input().split())
    if a == 1:
        for i in range(x):
            X[i] = 0
    elif a == 3:
        for i in range(y):
            Y[i] = 0
    elif a == 2:
        for i in range(x,n):
            X[i] = 0
    else:
        for i in range(y,m):
            Y[i] = 0

c_x = 0
c_y = 0
for x in X:
    if x == 1:
        c_x += 1

for y in Y:
    if y == 1:
        c_y += 1

print(c_x*c_y)

Submission status: Accepted

Solution code:
import sys
def v():
    W,H,N=tuple(map(int,sys.stdin.readline().split()))
    lx,ux,ly,uy=0,W,0,H
    for _ in [0]*N:
        x,y,a=tuple(map(int,sys.stdin.readline().split()))
        if a==1 and lx<x:lx=x
        elif a==2 and ux>x:ux=x
        elif a==3 and ly<y:ly=y
        elif a==4 and uy>y:uy=y
    if lx<ux and ly<uy:print((ux-lx)*(uy-ly))
    else:print(0)
if __name__=='__main__':v()

Submission status: Accepted

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

l = [0, W, 0, H]

for _ in range(N):
  x, y, a = map(int, input().split())
  if a == 1:
    if l[0] < x:
      l[0] = x
  elif a == 2:
    if l[1] > x:
      l[1] = x
  elif a == 3:
    if l[2] < y:
      l[2] = y
  else:
    if l[3] > y:
      l[3] = y

if l[0] < l[1] and l[2] < l[3]:
  print((l[1]-l[0])*(l[3]-l[2]))
else:
  print(0)

Submission status: Accepted

Solution code:
import sys

W, H, N = map(int, input().split())
xya = [list(map(int, input().split())) for _ in range(N)]
ans = 0
x_s, y_s, x_e, y_e = 0, 0, W, H

for x, y, a in xya:
    if a == 1:
        if (x_s < x) and (x_e > x):
            x_s = x
        elif x_e <= x:
            print(0)
            sys.exit()
        elif x_s >= x:
            pass
    elif a == 2:
        if (x_s < x) and (x_e > x):
            x_e = x
        elif x_e <= x:
            pass
        elif x_s >= x:
            print(0)
            sys.exit()
    elif a == 3:
        if (y_s < y) and (y_e > y):
            y_s = y
        elif y_e <= y:
            print(0)
            sys.exit()
        elif y_s >= y:
            pass
    elif a == 4:
        if (y_s < y) and (y_e > y):
            y_e = y
        elif y_e <= y:
            pass
        elif y_s >= y:
            print(0)
            sys.exit()
print((x_e - x_s) * (y_e - y_s))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
sq=[0,-w,0,-h]		#左端，右端，下端，上端

for i in range(n):
  x,y,b=map(int,input().split())
  dumy = [x,-x,y,-y]
  a=b-1
  if sq[a]<dumy[a]:
    sq[a]=dumy[a]


if -sq[1]-sq[0]<0:
  s=0
elif -sq[3]-sq[2]<0:
  s=0
else:
  s=(-sq[1]-sq[0])*(-sq[3]-sq[2])

print(s)

Submission status: Accepted

Solution code:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
# import math
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)


w,h,n=l()
r=[i for i in range(w+1)]
c=[i for i in range(h+1)]
for i in range(n):
    # print(r,c)
    a,b,x=l()
    if(x==1):
        r=r[br(r,a-1):]
    elif(x==2):
        r=r[:bl(r,a+1)]
    elif(x==3):
        c=c[br(c,b-1):]
    else:
        c=c[:bl(c,b+1)]
# print(r,c)
if(len(r)==0 or len(c)==0):
    print(0)
    exit()
print((max(r)-min(r))*(max(c)-min(c)))

Submission status: Accepted

Solution code:
w,h,n = map(int, input().split())
x_left = 0
x_right = w
y_up = h
y_down = 0
for _ in range(n):
  x,y,a = map(int, input().split())
  if a==1 and x_left <= x:
    x_left = x
  elif a==2 and x_right >= x:
    x_right = x
  elif a==3 and y_down <= y:
    y_down = y
  elif a==4 and y_up >= y:
    y_up = y

if x_right <= x_left or y_up <= y_down:
  print(0)
else:
  print((x_right - x_left)*(y_up - y_down))

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
W = [0, w]
H = [0, h]
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1 and W[0] < x:
        W[0] = x
    elif a == 2 and W[1] > x:
        W[1] = x
    elif a == 3 and H[0] < y:
        H[0] = y
    elif a == 4 and H[1] > y:
        H[1] = y

if W[1]-W[0] < 0 or (H[1]-H[0]) < 0:
    print(0)
else:
    print((W[1]-W[0]) * (H[1]-H[0]))

Submission status: Accepted

Solution code:
import itertools

w, h, n = map(int,input().split())
now = [[1]*w]*h
li = [list(map(int,input().split())) for i in range(n)]

for x in li:
    if x[2]==1: #x以下を塗りつぶす
        for i in range(h):
            for j in range(x[0]):
                now[i][j] = 0
    if x[2]==2: #x以上を塗りつぶす
        for i in range(h):
            for j in range(w-x[0]):
                now[i][x[0]+j] = 0
    if x[2]==3: #y以下を塗りつぶす
        for i in range(x[1]):
            now[i] = [0]*w
    if x[2]==4: #y以上を塗りつぶす
        for i in range(x[1],h):
            now[i] = [0]*w

print(sum(list(itertools.chain.from_iterable(now))))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
W,H,N = list(map(int,input().split()))
XYA = [list(map(int,input().split())) for _ in range(N)]
XMAX = W
XMIN = 0
YMAX = H
YMIN = 0
for xya in XYA:
    if xya[2] == 1:
        XMIN = max(XMIN,xya[0])
    elif xya[2] == 2:
        XMAX = min(XMAX,xya[0])
    elif xya[2] == 3:
        YMIN = max(YMIN,xya[1])
    elif xya[2] == 4:
        YMAX = min(YMAX,xya[1])
if XMIN >= XMAX or YMIN >= YMAX:
    print(0)
else:
    print((XMAX-XMIN)*(YMAX-YMIN))

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
ls = [list(map(int,input().split())) for _ in range(n)]
a = 0
b = 0
for i in range(n):
    if ls[i][2] == 1:
        if ls[i][0] > a:
            a = ls[i][0]
    elif ls[i][2] == 2:
        if ls[i][0] < w:
            w = ls[i][0]
    elif ls[i][2] == 3:
        if ls[i][1] > b:
            b = ls[i][1]
    else:
        if ls[i][1] < h:
            h = ls[i][1]
if (a < w) and (b < h):
    print((w-a)*(h-b))
else:
    print(0)

Submission status: Accepted

Solution code:
w1, h1, n = map(int, input().split())
w0 = 0
h0 = 0
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        w0 = max(w0, x)
    elif a == 2:
        w1 = min(w1, x)
    elif a == 3:
        h0 = max(h0, y)
    else:
        h1 = min(h1, y)
print(max(0, (w1 - w0)) * max(0, (h1 - h0)))

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
sx, sy, gx, gy = 0, 0, W, H

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        sx = max(sx, x)
    elif a == 2:
        gx = min(gx, x)
    elif a == 3:
        sy = max(sy, y)
    else:
        gy = min(gy, y)

dx, dy = gx-sx, gy-sy
if dx <= 0 or dy <= 0:
    print(0)
else:
    print(dx*dy)

Submission status: Accepted

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

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

sikaku_x = [0, W]
sikaku_y = [0, H]

for v in lst:
    x, y, a = v[0], v[1], v[2]
    if a == 1:
        if x > sikaku_x[0]:
            sikaku_x[0] = x
    elif a == 2:
        if x < sikaku_x[1]:
            sikaku_x[1] = x
    elif a == 3:
        if y > sikaku_y[0]:
            sikaku_y[0] = y
    else:
        if y < sikaku_y[1]:
            sikaku_y[1] = y
    if sikaku_x[0] >= sikaku_x[1] or sikaku_y[0] >= sikaku_y[1]:
        print(0)
        exit()

print((sikaku_x[1] - sikaku_x[0]) * (sikaku_y[1] - sikaku_y[0]))

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
 
x0, y0 = (0, 0)
x1, y1 = (w, h)
 
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        if x0 < x:
            x0 = x
        if x1 < x:
            x1 = x
    if a == 2:
        if x0 > x:
            x0 = x
        if x1 > x:
            x1 = x
    if a == 3:
        if y0 < y:
            y0 = y
        if y1 < y:
            y1 = y
    if a == 4:
        if y0 > y:
            y0 = y
        if y1 > y:
            y1 = y
 
ans = (x1 - x0) * (y1 - y0)
print(ans)

Submission status: Accepted

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

x0, y0 = (0, 0)
x1, y1 = (w, h)

for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        if x0 < x:
            x0 = x
        if x1 < x:
            x1 = x
    if a == 2:
        if x0 > x:
            x0 = x
        if x1 > x:
            x1 = x
    if a == 3:
        if y0 < y:
            y0 = y
        if y1 < y:
            y1 = y
    if a == 4:
        if y0 > y:
            y0 = y
        if y1 > y:
            y1 = y

ans = (x1 - x0) * (y1 - y0)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import sys
def sinput(): return sys.stdin.readline()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(): return list(imap())
def farr(): return list(fmap())
def sarr(): return sinput().split()

w, h, n = imap()
x = [0]*n; y = [0]*n; a = [0]*n
for i in range(n):
    x[i], y[i], a[i] = imap()

xr = yu = 0
xl = w; yd = h
for i in range(n):
    if a[i]==1: xr = max(xr, x[i])
    if a[i]==2: xl = min(xl, x[i])
    if a[i]==3: yu = max(yu, y[i])
    if a[i]==4: yd = min(yd, y[i])
sx = min(w, xr+w-xl)
sy = min(h, yu+h-yd)
print(h*w-(sx*h+sy*w-sx*sy))

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)
  if a == 2:
    maxx = min(maxx,x)
  if a == 3:
    miny = max(miny,y)
  if a == 4:
    maxy = min(maxy,y)

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

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:
        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(r-l, 0)*max(u-d, 0))

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
s=[[0 for _ in range(w)]]*h
#print(s)
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        for j in range(h):
            for k in range(0,x):
                s[j][k]=1
    elif a==2:
        for j in range(h):
            for k in range(x,w):
                s[j][k]=1
    elif a==3:
        for j in range(h-y,h):
            s[j]=[1]*w
    elif a==4:
        for j in range(h-y):
            s[j]=[1]*w
#print(s)
ans=0
for i in range(h):
    for j in range(w):
        if s[i][j]==0:
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
l, r = 0, w
d, u = 0, h
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 l >= r or u <= d:
    print(0) 
else:
    print((r-l)*(u-d))

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
xl, xr = 0, W
yl, yr = 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:
        yl = max(yl, y)
    else:
        yr = min(yr, y)
print(max(0, xr-xl)*max(0, yr-yl))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
minx = miny = 0
maxx = w
maxy = h
for _ in range(n):
    x1, y1, a = map(int, input().split())
    if a == 1:
        minx = max(minx, x1)
    if a == 2:
        maxx = min(maxx, x1)
    if a == 3:
        miny = max(miny, y1)
    if a == 4:
        maxy = min(maxy, y1)

print(max(0, (maxx - minx)) * max(0, (maxy - miny)))

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
xya = [list(map(int, input().split())) for _ in range(n)]
sikaku_x = [0, w]
sikaku_y = [0, h]
for x, y, a in xya:
    if a == 1:
        if sikaku_x[0] < x:
            sikaku_x[0] = x
    elif a == 2:
        if sikaku_x[1] > x:
            sikaku_x[1] = x
    elif a == 3:
        if sikaku_y[0] < y:
            sikaku_y[0] = y
    elif a == 4:
        if sikaku_y[1] > y:
            sikaku_y[1] = y

white_x = sikaku_x[1] - sikaku_x[0]
if white_x < 0:
    white_x = 0
white_y = sikaku_y[1] - sikaku_y[0]
if white_y < 0:
    white_y = 0
print(white_x*white_y)

Submission status: Accepted

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

width = [0, w]
height = [0, h]

for x, y, a in xya:
    if a == 1:
        width = [max(width[0], x), width[1]]
    elif a == 2:
        width = [width[0], min(width[1], x)]
    elif a == 3:
        height = [max(height[0], y), height[1]]
    elif a == 4:
        height = [height[0], min(height[1], y)]

ans = max(0, width[1] - width[0]) * max(0, height[1] - height[0])
print(ans)

Submission status: Accepted

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

for x, y, a in values:
    x_range = (0, W)
    y_range = (0, H)
    if a == 1:
        x_range = (0, x)
    elif a == 2:
        x_range = (x, W)
    elif a == 3:
        y_range = (0, y)
    elif a == 4:
        y_range = (y, H)

    for i in range(*y_range):
        for j in range(*x_range):
            canvas[i][j] = 1

sum_filled = sum([sum(row) for row in canvas])
print(W * H - sum_filled)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *

W, H, N = MAP()

left = 0
right = W
bottom = 0
top = H
 
for _ in range(N):
	x, y, a = MAP()
	if a == 1:
		left = max(x, left)
	elif a == 2:
		right = min(x, right)
	elif a == 3:
		bottom = max(y, bottom)
	elif a == 4:
		top = min(y, top
			)
if right - left < 0 or top - bottom < 0:
	print(0)
else:
	print((right-left)*(top-bottom))