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

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

width = max_x - min_x
height = max_y - min_y

for n in range(N):
    x, y, a = map(int,input().split())
    if a == 1:
        if min_x < x:
            min_x = x
    elif a == 2:
        if max_x > x:
            max_x = x
    elif a == 3 :
        if min_y < y:
            min_y = y
    else :
        if max_y > y:
            max_y = y
    
if min_x >= max_x or min_y >= max_y:
    output = 0
else:
    output = (max_x - min_x) * (max_y - min_y)

print(output)

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
ab = [-1]*2
cd = [10000]*2
for _ in range(n):
    x, y, a = (int(x) for x in input().split())
    if a == 1:
        ab[0] = max(ab[0],x)
    elif a == 3:
        ab[1] = max(ab[1],y)
    elif a == 2:
        cd[0] = min(cd[0],x)
    elif a == 4:
        cd[1] = min(cd[1],y)

if ab[0] != -1 and cd[0] != 10000:
    if cd[0] <= ab[0]:
        yoko = 0
    else:
        yoko = cd[0]-ab[0]
elif ab[0] != -1:
    yoko = w-ab[0]
elif cd[0] != 10000:
    yoko = cd[0]
else:
    yoko = w

if ab[1] != -1 and cd[1] != 10000:
    if cd[1] <= ab[1]:
        tate = 0
    else:
        tate = cd[1]-ab[1]
elif ab[1] != -1:
    tate = h-ab[1]
elif cd[1] != 10000:
    tate = cd[1]
else:
    tate = h

print(yoko*tate)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
w,h,n=[int(i) for i in input().split()]
leftdown=[0,0]
righttop=[w,h]


def minimize(leftdown,righttop,x,y,a):
    if a==1:
        leftdown[0]=min(max(x,leftdown[0]),righttop[0])
    elif a==2:
        righttop[0]=max(min(x,righttop[0]),leftdown[0])
    elif a==3:
        leftdown[1]=min(max(y,leftdown[1]),righttop[1])
    else:
        righttop[1]=max(min(y,righttop[1]),leftdown[1])
    
for i in range(n):
    x,y,a=[int(i) for i in input().split()]
    minimize(leftdown,righttop,x,y,a)
print(max(0,(righttop[0]-leftdown[0])*(righttop[1]-leftdown[1])))

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def main():
    W, H, N = map(int, input().split())
    xmin, xmax, ymin, ymax = 0, W, 0, H
    for i in range(N):
        x, y, a = map(int, input().split())
        if a == 1:
            xmin = max(xmin, x)
        elif a == 2:
            xmax = min(xmax, x)
        elif a == 3:
            ymin = max(ymin, y)
        elif a == 4:
            ymax = min(ymax, y)

    if (xmax <= xmin) or (ymax <= ymin):
        ans = 0
    else:
        ans = (xmax - xmin) * (ymax - ymin)
    print(ans)


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 == 2:
        right = min(right, x)
    if a == 1:
        left = max(left, x)
    if a == 3:
        down = max(down, y)
    if a == 4:
        up = min(up, y)
# print(left, right, down, up)
if right >= left and up >= down:
    print((right-left)*(up-down))
else:
    print(0)

Submission status: Accepted

Solution code:
# ABC 047: B – すぬけ君の塗り絵 2 イージー / Snuke's Coloring 2 (ABC Edit)
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 = [int(s) for s in input().split()]

    if a == 1:
        x_min.append(x)
    elif a == 2:
        x_max.append(x)
    elif a == 3:
        y_min.append(y)
    elif a == 4:
        y_max.append(y)

width = min(x_max) - max(x_min)
height = min(y_max) - max(y_min)
print(width * height if width >= 0 and height >= 0 else 0)

Submission status: Accepted

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

l, r, b, t = 0, w, 0, h
for i in range(n):
    if p[i][2] == 1:
        l = max(l, p[i][0])
    if p[i][2] == 2:
        r = min(r, p[i][0])
    if p[i][2] == 3:
        b = max(b, p[i][1])
    if p[i][2] == 4:
        t = min(t, p[i][1])

W = r-l if r > l else 0
H = t-b if t > b else 0
print(W*H)

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
xya = [list(map(int, input().split())) for _ in range(N)]
area = W * H
X = [0] * W
Y = [0] * H
for x, y, a in xya:
    if a == 1:
        for i in range(x):
            X[i] = 1
    elif a == 2:
        for i in range(x, W):
            X[i] = 1
    elif a == 3:
        for i in range(y):
            Y[i] = 1
    elif a == 4:
        for i in range(y, H):
            Y[i] = 1
print(X.count(0) * Y.count(0))

Submission status: Accepted

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

Wmin = 0
Wmax = W
Hmin = 0
Hmax = H

for i in range(N):
    x, y, z = map(int,input().split())
    if z == 1:
        Wmin = max(x, Wmin)
    if z == 2:
        Wmax = min(x, Wmax)
    if z == 3:
        Hmin = max(y, Hmin)
    if z == 4:
        Hmax = min(y, Hmax)
if Wmax < Wmin or  Hmax < Hmin:
    print(0)
else:
    print((Wmax-Wmin)*(Hmax-Hmin))

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
a_1 = [0]
a_2 = [0]
a_3 = [0]
a_4 = [0]
for i in range(n):
  x,y,a = map(int,input().split())
  if a == 1:
    a_1.append(x)
  if a==2:
    a_2.append(w-x)
  if a==3:
    a_3.append(y)
  if a==4:
    a_4.append(h -y)
if w - (max(a_1) + max(a_2))<=0:
  print(0)
elif h - (max(a_3) + max(a_4))<=0:
  print(0)
else:
  print((w - (max(a_1) + max(a_2))) * (h - (max(a_3) + max(a_4))))

Submission status: Accepted

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

Submission status: Accepted

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

P=[[1 for i in range(h)] for j in range(w)]

for i in range(n):
  x,y,a=map(int,input().split())
  
  if a==1:
    for k in range(x):
      for l in range(h):
        P[k][l]=0
  
  elif a==2:
    for k in range(x,w):
      for l in range(h):
        P[k][l]=0
  
  elif a==3:
    for k in range(w):
      for l in range(y):
        P[k][l]=0
  
  else:
    for k in range(w):
      for l in range(y,h):
        P[k][l]=0
         
ans=0
for g in range(w):
  for f in range(h):
    ans+=P[g][f]
print(ans)

Submission status: Accepted

Solution code:
w,h,n = list(map(int, input().split()))
xya = [list(map(int, input().split())) for _ in range(n)]
left = 0
right = w
down = 0
up = h
for i in xya:
    if i[2]==1:
        left = max(i[0], left)
    elif i[2]==2:
        right = min(i[0], right)
    elif i[2]==3:
        down = max(i[1], down)
    else:
        up = min(i[1], up)

print(max(up-down, 0) * max(right-left, 0))

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
xya = [list(map(int, input().split())) for _ in range(N)]
xs = 0
ys = 0
for i in range(N):
    if W - xs <= 0 or H - ys <= 0:
        print(0)
        quit()
    if xya[i][2] == 1:
        xs = max(xs, xya[i][0])
    elif xya[i][2] == 2:
        W = min(W, xya[i][0])
    elif xya[i][2] == 3:
        ys = max(ys, xya[i][1])
    else:
        H = min(H, xya[i][1])
if W - xs <= 0 or H - ys <= 0:
    print(0)
else:
    print((W - xs) * (H - ys))

Submission status: Accepted

Solution code:
#in1 = '10 10 5'
#in2 = ['1 6 1','4 1 3','6 9 4','9 4 2','3 1 3']

rx, uy, n = map(int, input().split())
#rx, uy, n = map(int, in1.split())

dy = 0
lx = 0

for idx1 in range(n):
    x, y, a = map(int, input().split())
    #x, y, a = map(int, in2[idx1].split())
    if a == 1:
        lx = max(lx, x)
    elif a == 2:
        rx = min(rx, x)
    elif a == 3:
        dy = max(dy, y)
    else:
        uy = min(uy, y)

if rx >= lx and uy >= dy:
    print((uy - dy) * (rx - lx))
else:
    print(0)

Submission status: Accepted

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

tW = W
tH = H

minx = 0
miny = 0

for x, y, a in xya:
    if a == 1:
        minx = max(minx, x)
    elif a == 2:
        tW = min(tW, x)
    elif a == 3:
        miny = max(miny, y)
    else:
        tH = min(tH, y)

if tW - minx >= 0 and tH - miny >= 0:
    print((tW - minx) * (tH - miny))
else:
    print(0)

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
w = {_ for _ in range(W+1)}
h = {_ for _ in range(H+1)}
x,y,a =[0]*N, [0]*N, [0]*N

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

for i in range(N):
    if a[i]==1:
        w = w - {_ for _ in range(x[i])}
    elif a[i]==2:
        w = w - {_ for _ in range(x[i]+1,W+1)}
    elif a[i]==3:
        h = h - {_ for _ in range(y[i])}
    else:
        h = h - {_ for _ in range(y[i]+1, H+1)}
s, t = len(w)-1, len(h)-1
print(0 if s<0 or t<0 else s*t)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
xya=[]
for _ in range(N):
    xya.append(tuple(map(int, input().split())))
#print(xya)
left=0
right=W
top=H
bottom=0
for el in xya:
    if el[2]==1:
        if left<el[0]:
            left=el[0]
    if el[2]==2:
        if right>el[0]:
            right=el[0]
    if el[2]==3:
        if bottom<el[1]:
            bottom=el[1]
    if el[2]==4:
        if top>el[1]:
            top=el[1]
    #print(left, right, top, bottom)
if left<right and bottom<top:
    print((right-left) * (top-bottom))
else:
    print(0)

Submission status: Accepted

Solution code:
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

# Written by NoKnowledgeGG @YlePhan

#import math
#mod = 10**9+7

def main():
  w,h,n = map(int,input().split())
  rec = [[0] * w for _ in range(h)] # 0:white, 1:black
  
  # --start
  #for i in range(h):
  #  print('{}'.format(rec[i]))
  
  for _ in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
      for i in range(h):
        for j in range(0,x):
          #print(i,j)
          rec[i][j] = 1 # blacked
    elif a == 2:
       for i in range(h):
        for j in range(x,w):
          #print(i,j)
          rec[i][j] = 1 # blacked
    elif a == 3:
       for i in range(0,y):
        for j in range(w):
          #print(i,j)
          rec[i][j] = 1 # blacked
    if a == 4:
      #print(y)
      for i in range(y,h):
        for j in range(w):
          #print(i,j)
          rec[i][j] = 1 # blacked
      #rec[0][2] = 1
      
      
  # --done?
  """for i in range(h):
    #print(i)
    print('{}'.format(rec[i]))"""
  
  # --search
  sx,sy,gx,gy = -1,-1,-1,-1 #なくてもいい
  flag = False
  for j in range(w): # y = 0 ~ 
    for i in range(h): # x = 0 ~ xをまず求める
      if (not flag) and rec[i][j] == 0:
        flag = True
        sx,sy = j,i
      # to right
      # flaged
      # print(flag)
      if flag:#(8,8)の挙動を調べたい。
        if rec[i][j] == 0:
          gx,gy = j,i
        """if j+1<w:#(1,8)(i,j)
          if rec[i][j+1] == 1:
            if i+1<h:
              if rec[i+1][j] != 0:
                print(j+1,i)
                gx,gy = j+1,i
                continue
              else:
                pass
            else:
              gx,gy = j+1,i
              break
        else:##i方向を調べる
          if i+1<h:
            if rec[i+1][j] == 1:
              gx,gy = j,i+1
              continue"""
          
  #print(sx,sy,gx,gy)
  if gx==sx==-1 and sy==gy==-1:
    print(0)
    exit()
  print((gx-sx+1)*(gy-sy+1))
  
if __name__ == '__main__':
  main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

w, h, n = map(int, readline().split())
xya = [list(map(int, readline().split())) for i in range(n)]
ans = [[0, w], [0, h]]
for x, y, a in xya:
    if a == 1 and ans[0][0] < x:
        ans[0][0] = x
    elif a == 2 and ans[0][1] > x:
        ans[0][1] = x
    elif a == 3 and ans[1][0] < y:
        ans[1][0] = y
    elif a == 4 and ans[1][1] > y:
        ans[1][1] = y
if ans[0][0] > ans[0][1] or ans[1][0] > ans[1][1]:
    print(0)
else:
    print((ans[0][1] - ans[0][0]) * (ans[1][1] - ans[1][0]))

Submission status: Accepted

Solution code:
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque
from decimal import *


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


if __name__ == '__main__':
    w, h,n = map(int, input().split())
    ans = []

    for i in range(h):
        s = [1]*w
        ans.append(s)
    for i in range(n):
        a, b, c = map(int, input().split())
        if c == 1:
           for j in range(0,h):
               for k in range(0,a):
                   ans[j][k] =0
        if c == 2:
           for j in range(0,h):
               for k in range(a,w):
                   ans[j][k] =0
        if c == 3:
           for j in range(0,b):
               for k in range(0,w):
                   ans[j][k] =0
        if c == 4:
           for j in range(b,h):
               for k in range(0,w):
                   ans[j][k] =0

    s = 0
    for  i in ans:
        for j in i:
            s += j

    print(s)

Submission status: Accepted

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

x_l = 0
x_r = w
y_l = 0
y_h = h

for i in range(n):
    x, y, a = map(int,input().split())
    if a == 1:
      if x > x_l:
        x_l = x
    elif a == 2:
        if x < x_r:
          x_r = x
    elif a == 3:
        if y > y_l:
          y_l = y
    else:
        if y < y_h:
          y_h = y

menseki = 0
if x_l <= x_r and y_l <= y_h:
  menseki = (y_h - y_l)*(x_r - x_l)

print(menseki)

Submission status: Accepted

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

hani = [0,w,0,h]

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

        hani[0] = max(hani[0],x)
    elif a == 2:
        hani[1] = min(hani[1],x)
    elif a == 3:
        hani[2] = max(hani[2],y)
    else:
        hani[3] = min(hani[3],y)

print(max(0,hani[1]-hani[0]) * max(0,hani[3]-hani[2]))

Submission status: Accepted

Solution code:
#template
from collections import Counter
def inputlist(): return [int(j) for j in input().split()]
#template
W,H,N = inputlist()
flag = [[True]*(H+1) for _ in range(W+1)]
def search(x,y,a):
    if a == 3:
        for i in range(W+1):
            for j in range(y+1):
                flag[i][j] = False
    if a == 4:
        for i in range(W+1):
            for j in range(y+1,H+1):
                flag[i][j] = False
    if a == 2:
        for i in range(x+1,W+1):
            for j in range(H+1):
                flag[i][j] = False
    if a == 1:
        for i in range(x+1):
            for j in range(H+1):
                flag[i][j] = False
for i in range(N):
    x,y,a = inputlist()
    search(x,y,a)
ans = 0
for i in range(1,W+1):
    for j in range(1,H+1):
        if flag[i][j]:
            ans +=1
print(ans)

Submission status: Accepted

Solution code:
W, H ,N = [int(i) for i in input().split()]
X = [0, W]
Y = [0, H]
for _ in range(N):
    x, y, a = [int(i) for i in input().split()]
    if a == 1:
        X = [max(X[0], x), X[1]]
        if X[0] >= X[1]:
            break
    elif a == 2:
        X = [X[0], min(X[1], x)]
        if X[0] >= X[1]:
            break
    elif a == 3:
        Y = [max(Y[0], y), Y[1]]
        if Y[0] >= Y[1]:
            break
    else:
        Y = [Y[0], min(Y[1], y)]
        if Y[0] >= Y[1]:
            break
print(max(0, X[1] - X[0]) * max(0, Y[1] - Y[0]))

Submission status: Accepted

Solution code:
W,H,N = map(int, input().split())
x_M,x_m = 0,W
y_M,y_m = 0,H
for i in range(N):
    x,y,a  = map(int, input().split())
    # 白い部分
    if a == 1:
        x_M = max(x_M, x)
    elif a == 2:
        x_m = min(x_m, x)
    elif a == 3:
        y_M = max(y_M, y)
    else:
        y_m = min(y_m, y)

ans = max(0,x_m-x_M)*max(0,y_m-y_M)
print(ans)

Submission status: Accepted

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

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

cnt = 0
for i in range(h):
  for j in range(w):
    if array[i][j] == 0:
      cnt += 1
      
print(cnt)

Submission status: Accepted

Solution code:
inp = list(map(int,input().split()))
left_max=0
right_min=inp[0]
upper_min=inp[1]
lower_max=0

for i in range(inp[2]):
    inin = list(map(int,input().split()))
    if inin[2] == 1 and inin[0]>left_max:
        left_max=inin[0]
    if inin[2] == 2 and inin[0]<right_min:
        right_min=inin[0]
    if inin[2] == 4 and inin[1]<upper_min:
        upper_min=inin[1]
    if inin[2] == 3 and inin[1]>lower_max:
        lower_max=inin[1]
left_max=min(left_max,right_min)
upper_min=max(upper_min,lower_max)
print((right_min-left_max)*(upper_min-lower_max))

Submission status: Accepted

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

x = [int(i) for i in range(w+1)]
y = [int(i) for i in range(h+1)]

for i in range(n):
    x_i, y_i, a = map(int,input().split())
    if a == 1:
        x = [int(j) for j in x if j >= int(x_i)]
    elif a == 2:
        x = [int(j) for j in x if j <= int(x_i)]
    elif a == 3:
        y = [int(j) for j in y if j >= int(y_i)]
    elif a == 4:
        y = [int(j) for j in y if j <= int(y_i)]
if len(x) == 0 or len(y) == 0:
    print('0')
else:
    print((max(x)-min(x)) * (max(y)-min(y)))

Submission status: Accepted

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

Submission status: Accepted

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

minx=0
maxx=w
miny=0
maxy=h

for i in range(n):
    if p[i][2]==1:
        minx=max(minx,p[i][0])
    if p[i][2]==2:
        maxx=min(maxx,p[i][0])
    if p[i][2]==3:
        miny=max(miny,p[i][1])
    if p[i][2]==4:
        maxy=min(maxy,p[i][1])
w=maxx-minx
h=maxy-miny
print(w*h if w>0 and h>0 else 0)

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
xya = [list(map(int, input().split())) for _ in range(n)]
wl,wr,hu,ht=0,w,0,h
for i in range(n):
    if xya[i][2]==1:
        wl=max(wl,int(xya[i][0]))
    elif xya[i][2]==2:
        wr=min(wr,int(xya[i][0]))
    elif xya[i][2]==3:
        hu=max(hu,int(xya[i][1]))
    elif xya[i][2]==4:
        ht=min(ht,int(xya[i][1]))
    else:pass
if wl>wr or hu>ht:print(0)
else:print((wr-wl)*(ht-hu))

Submission status: Accepted

Solution code:
hw,hh,n=map(int,input().split())
lw=lh=0
for _ in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    lw=max(lw,x)
  elif a==2:
    hw=min(hw,x)
  elif a==3:
    lh=max(lh,y)
  else:
    hh=min(hh,y)
print(max(hh-lh,0)*max(hw-lw,0))

Submission status: Accepted

Solution code:

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

for i in range(n):
    x1,y1,a1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
    a.append(a1)

lp=0
x_max=[0]
x_min=[w]
y_max=[0]
y_min=[h]

for aa in a:
    
    if aa== 1:
        x_max.append(x[lp])

    elif aa==2:
        x_min.append(x[lp])

    elif aa==3:
        y_max.append(y[lp])

    elif aa==4:
        y_min.append(y[lp])
    
    lp+=1

x=min(x_min)-max(x_max)
y=min(y_min)-max(y_max)

if x<=0:
    x=0
if y<=0:
    y=0

ans=x*y

print(ans)

Submission status: Accepted

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

left = 0
right = w
high = h
low = 0
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:
        low = max(low, y)
    if a == 4:
        high = min(high, y)

print(max(0, right - left) * max(0, high - low))

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
leftW,leftH=0,0
rightW,rightH=W,H

for i in range(N):
    x,y,a=map(int,input().split())
    if a==1 and leftW<x:
        leftW=x
    elif a==2 and x<rightW:
        rightW=x
    elif a==3 and leftH<y:
        leftH=y
    elif a==4 and y<rightH:
        rightH=y
ansH=rightH-leftH
ansW=rightW-leftW
if ansH<0: ansH=0
if ansW<0: ansW=0
print(ansH*ansW)

Submission status: Accepted

Solution code:
W, H , N = list(map(int, input().split()))
W0 = 0
H0 = 0
X = []
Y = []
A = []
for i in range(N):
    x,y,a=[int(i) for i in input().split()]
    X.append(x)
    Y.append(y)
    A.append(a)
for j in range (N):
    if A[j] == 1:
        if X[j] >=  W0:
            W0 = X[j]
    elif A[j] == 2:
        if X[j] <= W:
            W = X[j]
    elif A[j] == 3:
        if Y[j] >= H0:
            H0 = Y[j]
    elif A[j] == 4:
        if Y[j] <= H:
            H = Y[j]
h = H - H0
w = W - W0
if h >=0 and w >= 0:
    print(h*w)
else:
    print(0)

Submission status: Accepted

Solution code:
w,h,n = [int(x) for x in input().split()]
l = 0
r = w
b = 0
t = h
for _ in range(n):
    x,y,a = [int(x) for x in input().split()]
    if a == 1:
        l = max(x,l)
    elif a == 2:
        r = min(r,x)
    elif a == 3:
        b = max(b,y)
    elif a == 4:
        t = min(t,y)

if r<l or t<b:
    print(0)
else:
    print((r-l) * (t-b))

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
x=[0]*N
y=[0]*N
a=[0]*N
H_min=0
H_max=H
W_min=0
W_max=W

for i in range(N):
  x[i],y[i],a[i] = map(int,input().split())
  if a[i]==1:
    W_min=max(x[i],W_min)
  elif a[i]==2:
    W_max=min(x[i],W_max)
  elif a[i]==3:
    H_min=max(y[i],H_min)
  else:
    H_max=min(y[i],H_max)

height = max(0,H_max-H_min)
width = max(0,W_max-W_min)
print(height*width)

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
L=0
R=W
B=0
T=H
for i in range(N):
	x,y,a=map(int,input().split())
	if a==1:
		L=max(x,L)
	if a==2:
		R=min(R,x)
	if a==3:
		B=max(B,y)
	if a==4:
		T=min(T,y)
if R<L or  T<B:
	print(0)
else:
	print((R-L)*(T-B))

Submission status: Accepted

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

xl, xr, yb, yt = 0, w, 0, h

for i in range(n):
    if xya[i][2] == 1:
        xl = max(xl, xya[i][0])
    elif xya[i][2] == 2:
        xr = min(xr, xya[i][0])
    elif xya[i][2] == 3:
        yb = max(yb, xya[i][1])
    else:
        yt = min(yt, xya[i][1])

if xr - xl <= 0 or yt - yb <= 0:
    print(0)
else:
    print((xr - xl)*(yt - yb))

Submission status: Accepted

Solution code:
W,H,N=list(map(int,input().split()))
L=[]
for h in range(H):
    L.append([])
    for w in range(W):
        L[h].append(0)

X=[]
Y=[]
A=[]
for i in range(N):
    x,y,a=list(map(int,input().split()))
    X.append(x)
    Y.append(y)
    A.append(a)

for i in range(N):
    if A[i]==1:
        for h in range(H):
            for w in range(W):
                if 0<=w<X[i]:
                    L[h][w]=1
    elif A[i]==2:
        for h in range(H):
            for w in range(W):
                if X[i]<=w<=W-1:
                    L[h][w]=1
    elif A[i]==3:
        for h in range(H):
            for w in range(W):
                if 0<=h<Y[i]:
                    L[h][w]=1
    elif A[i]==4:
        for h in range(H):
            for w in range(W):
                if Y[i]<=h<=H-1:
                    #print(h,w)
                    L[h][w]=1
                    pass

count=0
for h in range(H-1,-1,-1):
    for w in range(W):
        if L[h][w]==0:
            count+=1
    #print(L[h])
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
left, right, bottom, top = 0, W, 0, 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)
  elif a == 4:
    top = min(top, y)
if right > left and top > bottom:
  ans = (right - left) * (top - bottom)
else:
  ans = 0
print(ans)

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
mat=[[1]*w for _ in range(h)]
#print(mat)
l=[-1]*5
l[2]=float('inf')
l[4]=float('inf')
for _ in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        l[1]=max(l[1],x)
    elif a==2:
        l[2]=min(l[2],x)
    elif a==3:
        l[3]=max(l[3],y)
    else:
        l[4]=min(l[4],y)
#print(l)
for i in range(h):
    for j in range(w):
        #j means x and i means y 
        if j<l[1]:
            mat[i][j]=0
        if l[2]<=j:
            mat[i][j]=0
        if i<l[3]:
            mat[i][j]=0
        if l[4]<=i:
            mat[i][j]=0
#print(mat)
ans=0
for i in range(h):
    for j in range(w):
        ans+=mat[i][j]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    W, H, N = [int(x) for x in input().split()]
    XYA = [[int(x) for x in input().split()] for _ in range(N)]

    sx, sy, lx, ly = 0, 0, W, H
    for x, y, a in XYA:
        if a == 1:
            sx = max(sx, x)
        elif a == 2:
            lx = min(lx, x)
        elif a == 3:
            sy = max(sy, y)
        else:
            ly = min(ly, y)

    print(max(0, lx - sx) * max(0, ly - sy))
    

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
W,H,N = list(map(int, input().split()))
p = [0] * 3
s = [0] * 2
e = [W, H]
for i in range(N):
    p = list(map(int, input().split()))
    if p[2] == 1 and p[0] > s[0]:
        s[0] = p[0]
    elif p[2] == 2 and p[0] < e[0]:
        e[0] = p[0]
    elif p[2] == 3 and p[1] > s[1]:
        s[1] = p[1]
    elif p[2] == 4 and p[1] < e[1]:
        e[1] = p[1]

if e[0] >= s[0] and e[1] >= s[1]:
    print((e[0] - s[0]) * (e[1] - s[1]))
else:
    print(0)

Submission status: Accepted

Solution code:
import numpy as np

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

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