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:
import sys


def solve(inp):
    (W, H, N) = map(int, inp.readline().split(' '))
    XYA = [list(map(int, inp.readline().split(' '))) for i in range(N)]

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

    dx = max(0, ex - sx)
    dy = max(0, ey - sy)

    return str(dx * dy)


def main():
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

graph = list()
for x in range(0, w + 1):
    graph.append([0 for y in range(0, h + 1)])

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

    if a == 1:
        for dx in range(0, x):
            for dy in range(0, h + 1):
                graph[dx][dy] = 1

    if a == 2:
        for dx in range(x + 1, w + 1):
            for dy in range(0, h + 1):
                graph[dx][dy] = 1

    if a == 3:
        for dx in range(0, w + 1):
            for dy in range(0, y):
                graph[dx][dy] = 1

    if a == 4:
        for dx in range(0, w + 1):
            for dy in range(y + 1, h + 1):
                graph[dx][dy] = 1

all = True
min_x = 1000
max_x = -1
min_y = 1000
max_y = -1
for x in range(0, w + 1):
    # print(graph[x])
    for y in range(0, h + 1):
        if graph[x][y] == 0:
            all = False
            min_x = min(min_x, x)
            max_x = max(max_x, x)
            min_y = min(min_y, y)
            max_y = max(max_y, y)

if all:
    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=[["w" 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(x):
      for j in range(H):
        l[j][i]="b"
  elif a==2:
    for i in range(x,W):
      for j in range(H):
        l[j][i]="b"
  elif a==3:
    for i in range(y):
      for j in range(W):
        l[i][j]="b"
  else:
    for i in range(y,H):
      for j in range(W):
        l[i][j]="b"
cnt=0
for i in range(H):
  cnt+=l[i].count("w")
print(cnt)

Submission status: Accepted

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

X, Y = [0, w], [0, h]
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        X[0] = max(X[0], x)
    if a == 2:
        X[1] = min(X[1], x)
    if a == 3:
        Y[0] = max(Y[0], y)
    if a == 4:
        Y[1] = min(Y[1], y)

if X[1]-X[0] <= 0 or Y[1]-Y[0] <= 0:
    print(0)
else:
    print((X[1] - X[0]) * (Y[1] - Y[0]))

Submission status: Accepted

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

for i in range(n):
    if p[i][2] == 1:
        a = max(a, p[i][0])            
    elif p[i][2] == 2:
        c = min(c, p[i][0])
    elif p[i][2] == 3:
        b = max(b, p[i][1])
    else:
        d = min(d, p[i][1])

if c > a and d > b:
    ans = (c-a)*(d-b)
else:
    ans = 0

print(ans)

Submission status: Accepted

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

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

for x, y, a  in coords:
    if a == 1:
        minx = max(minx, x)
    elif a == 2:
        maxx = min(maxx, x)
    elif a == 3:
        miny = max(miny, y)
    elif a == 4:
        maxy = min(maxy, y)

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())
coords = [list(map(int, input().split())) for _ in range(n)]

pic = [[1 for _ in range(w)] for _ in range(h)]

for x, y, a in coords:
    if a == 1:
        for row in pic:
            for i in range(x):
                row[i] = 0

    elif a == 2:
        for row in pic:
            for i in range(x, w):
                row[i] = 0

    elif a == 3:
        for i in range(y):
            for j in range(w):
                pic[i][j] = 0

    elif a == 4:
        for i in range(y, h):
            for j in range(w):
                pic[i][j] = 0
    

print(sum(sum(i) for i in pic))

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
xl=[0]
xr=[w]
yu=[h]
yd=[0]

for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        xl.append(x)
    elif a==2:
        xr.append(x)
    elif a==3:
        yd.append(y)
    else:
        yu.append(y)
if max(xl)>=min(xr) or max(yd)>=min(yu):
    print(0)
else:
    xb=max(xl)+w-min(xr)
    yb=max(yd)+h-min(yu)
    print(h*w-xb*h-yb*w+xb*yb)

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
x_a=0
y_a=0
x_b=W
y_b=H
for i in range(N):
  x,y,a = map(int,input().split())
  if a ==1:
    x_a=max(x_a,x)
  elif a ==2:
    x_b=min(x_b,x)
  elif a==3:
    y_a=max(y_a,y)
  elif a==4:
    y_b=min(y_b,y)
print((x_b-x_a)*(y_b-y_a) if x_b-x_a > 0 and y_b-y_a > 0 else '0')

Submission status: Accepted

Solution code:
W, H ,N = map(int,input().split())
#白い部分の長方形の左右上下を設定
r = W
l = 0
m = H
n = 0
#左右上下を入力の度に更新
for _ in range(N):
    x, y , a = map(int,input().split())
    if a == 1:
        l = max(x,l)
    if a == 2:
        r = min(x,r)
    if a == 3:
        n = max(y,n)
    if a == 4:
        m = min(y,m)
#長方形ができないときは面積０だよ
if l >= r or n >= m:
    print(0)
else:
    print((r-l)*(m-n))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
p, q, r, s = 0, 0, w, h
for i in range(n):
   x, y, a = map(int, input().split())

   if (a == 1):
      if (x > p):
         p = x
   elif (a == 2):
      if (x < r):
         r = x
   elif (a == 3):
      if (y > q):
         q = y
   else:
      if (y < s):
         s = y

if (r < p or s < q):
   print(0)
else:
   print((r - p)* (s - q))

Submission status: Accepted

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

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

L = 0
B = 0
R,T = W,H

for i in range(N):
    x,y,a = map(int,input().split())
    if a == 1:
        L = max(L,x)
    elif a == 2:
        R = min(R,x)
    elif a == 3:
        B = max(B,y)
    elif a == 4:
        T = min(T,y)

res = (R-L) * (T-B)

# res = max(res,0)

if (R-L <= 0) or (T-B <= 0):
    print(0)
else:
    print(res)

Submission status: Accepted

Solution code:
xya=[]
whn=list(map(int,input().split()))
for i in range(whn[2]):
    xya.append(list(map(int,input().split())))

threshold=[0,whn[0],0,whn[1]]
for i in range(whn[2]):
    if xya[i][2]==1:
        if xya[i][0]>threshold[0]:
            threshold[0]=xya[i][0]
    elif xya[i][2]==2:
        if xya[i][0]<threshold[1]:
            threshold[1]=xya[i][0]
    elif xya[i][2]==3:
        if xya[i][1]>threshold[2]:
            threshold[2]=xya[i][1]
    else:
        if xya[i][1]<threshold[3]:
            threshold[3]=xya[i][1]
w=max(threshold[1]-threshold[0],0)
h=max(threshold[3]-threshold[2],0)
print(w*h)

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
rect = [[1 for i in range(W+1)] for j in range(H+1)]

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        for j in range(H+1):
            for k in range(x):
                rect[j][k] = 0
    elif a == 2:
        for j in range(H+1):
            for k in range(x+1, W+1):
                rect[j][k] = 0
    elif a == 3:
        for j in range(y):
            for k in range(W+1):
                rect[j][k] = 0
    else:
        for j in range(y+1, H+1):
            for k in range(W+1):
                rect[j][k] = 0
                
ret = 0
for i in range(H):
    for j in range(W):
        if rect[i][j] and rect[i+1][j] and rect[i][j+1] and rect[i+1][j+1]:
            ret += 1
            
print(ret)

Submission status: Accepted

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

points = [list(map(int, input().split())) for _ in range(N)]
res = np.ones((W,H), dtype=np.int64)

for x, y, a in points:
    if a == 1:
        res[:x] = 0
    if a == 2:
        res[x:] = 0
    if a == 3:
        tmp = res[:, :y]
        res[:, :y] = 0
    if a == 4:
        tmp = res[:, y:]
        res[:, y:] = 0

print(res.sum())

Submission status: Accepted

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

points = [list(map(int, input().split())) for _ in range(N)]
res = 0

x1,y1 = [0,0]
x2,y2 = [W,H]

for x,y,a in points:
    if a == 1:
        x1 = max(x1, x)
    if a == 2:
        x2 = min(x2, x)
    if a == 3:
        y1 = max(y1, y)
    if a == 4:
        y2 = min(y2, y)

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

Submission status: Accepted

Solution code:
import numpy as np

W, H, N = map(int, input().split())
grid = np.ones((H, W), np.int64)

for _ in range(N):
  x, y, a = map(int, input().split())
  x -= 1
  y -= 1
  if a == 1:
    grid[:, :x+1] = 0
  if a == 2:
    grid[:, x+1:] = 0
  if a == 3:
    grid[-y-1:, :] = 0
  if a == 4:
    grid[:-y-1, :] = 0

print(np.sum(grid))

Submission status: Accepted

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

a1 = 0
a2 = w
a3 = 0
a4 = h
for _ in range(n):
   x,y,a = map(int,input().split())
   if a == 1:
      a1 = max(a1, x)
   if a == 2:
      a2 = min(a2, x)
   if a == 3:
      a3 = max(a3, y)
   if a == 4:
      a4 = min(a4, y)
a5 = max(a2 - a1, 0)
a6 = max(a4 -a3, 0)
print(a5*a6)

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
maxw=0
minw=w
maxh=0
minh=h
for i in range(n):
  if a[i][-1]==1:    
    maxw=max(a[i][0],maxw)
  elif a[i][-1]==2:
    minw=min(a[i][0],minw)
  elif a[i][-1]==3:    
    maxh=max(a[i][1],maxh)
  else:
    minh=min(a[i][1],minh)
    
haba=max(0,minw-maxw)
takasa=max(0,minh-maxh)

print(haba*takasa)

Submission status: Accepted

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

x1 = 0
x2 = w
y1 = 0
y2 = h

for i in range(n):
	if ls[i][2] == 1:
		if ls[i][0] >= x1:
			x1 = ls[i][0]
	elif ls[i][2] == 2:
		if ls[i][0] <= x2:
			x2 = ls[i][0]
	elif ls[i][2] == 3:
		if ls[i][1] >= y1:
			y1 = ls[i][1]
	elif ls[i][2] == 4:
		if ls[i][1] <= y2:
			y2 = ls[i][1]

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

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
s=0
W=[i for i in range(1,w+1)]
H=[i for i in range(1,h+1)]
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        W=[j for j in W if j>x]
    elif a==2:
        W = [j for j in W if j <= x]
    elif a==3:
        H=[j for j in H if j>y]
    elif a==4:
        H = [j for j in H if j <= y]
print(len(W)*len(H))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
w,h,n=map(int,input().split())
x_max=0
x_min=w
y_max=0
y_min=h
flg=[0]*4
for i in range(n):
    x_,y_,a=map(int,input().split())
    if a==1:
        x_max=max(x_,x_max)
        flg[0]=1
    elif a==2:
        x_min=min(x_,x_min)
        flg[1]=1
    elif a==3:
        y_max=max(y_,y_max)
        flg[2]=1
    else:
        y_min=min(y_,y_min)
        flg[3]=1
if x_max>=x_min or y_max>=y_min:
    print(0)
else:
    print((x_min-x_max)*(y_min-y_max))

Submission status: Accepted

Solution code:
W, H, N = map(int, raw_input().split())
x = []
y = []
a = []
for i in range(N):
    xi, yi, ai = map(int, raw_input().split())
    x.append(xi)
    y.append(yi)
    a.append(ai)

xs = set(range(W))
ys = set(range(H))
for i in range(N):
    xi, yi, ai = x[i], y[i], a[i]
    if ai == 1:
        xs -= set(range(xi))
    elif ai == 2:
        xs -= set(range(xi, W))
    elif ai == 3:
        ys -= set(range(yi))
    elif ai == 4:
        ys -= set(range(yi, H))
    else:
        continue
print len(xs) * len(ys)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
xmax, ymax, N = [int(x) for x in input().split()]
X = []
for _ in range(N):
    X.append([int(x) for x in input().split()])
xmin = 0
ymin = 0
for i in X:
    x, y, a = i
    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 xmax <= xmin or ymax <= ymin:
    print(0)
else:
    print((xmax - xmin) * (ymax - ymin))

Submission status: Accepted

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

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

x_l, x_r, y_d, y_u = 0, w, 0, h
for x in a:
  if x[2] == 1 and x[0] > x_l:
    x_l = x[0]
  elif x[2] == 2 and x[0] < x_r:
    x_r = x[0]
  elif x[2] == 3 and x[1] > y_d:
    y_d = x[1]
  elif x[2] == 4 and x[1] < y_u:
    y_u = x[1]
if (x_r - x_l) <= 0 or (y_u - y_d) <= 0:
  print(0)
else:
  print((x_r - x_l) * (y_u - y_d))

Submission status: Accepted

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

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

import numpy as np

Z = np.zeros((H, W))

for i in AA:
    if i[2] == 1:
        Z[:, :i[0]] = 1
    
    elif i[2] == 2:
        Z[:, i[0]:] = 1
    
    elif i[2] == 3:
        Z[:i[1], :]= 1
        
    else:
        Z[i[1]:, :] = 1

print(W*H - np.count_nonzero(Z))

Submission status: Accepted

Solution code:
import numpy as np
w,h,n = [int(i) for i in input().split()]

width = np.ones(w,dtype = np.int64)
height = np.ones(h,dtype = np.int64)

l = [[int(i) for i in input().split()] for _ in range(n)]

for i in l:
    if i[2] == 1:
        width[:i[0]] = 0
    elif i[2] == 2:
        width[i[0]:] = 0
    elif i[2] == 3:
        height[:i[1]] = 0
    else:
        height[i[1]:] = 0
        
width = np.count_nonzero(width)
height = np.count_nonzero(height)
print(width * height)

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
g=[list(map(int,input().split())) for i in range(n)]
t1,t2,t3,t4=0,w,0,h
for i in range(n):
  if g[i][2]==1:
    t1=max(t1,g[i][0])
  elif g[i][2]==2:
    t2=min(t2,g[i][0])
  elif g[i][2]==3:
    t3=max(t3,g[i][1])
  else:
    t4=min(t4,g[i][1])
if t2<=t1 or t4<=t3:
  print(0)
else:
  print((t2-t1)*(t4-t3))

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
xya = []
hx = W
lx = 0
hy = H
ly = 0
for i in range(N):
    x,y,a = map(int,input().split())
    if a == 1:
        lx = max(lx,x)
    if a == 2:
        hx = min(hx,x)
    if a == 3:
        ly = max(ly,y)
    if a == 4:
        hy = min(hy,y)
print(max(0,max(0,(hx-lx))*max(0,(hy-ly))))

Submission status: Accepted

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

b = [[0 for _ in range(w)] for _ in range(h)]
for x, y, a in xya:
    if a == 1:
        for i in range(h):
            for j in range(x):
                b[i][j] = 1
    elif a == 2:
        for i in range(h):
            for j in range(x, w):
                b[i][j] = 1
    elif a == 3:
        for i in range(y):
            for j in range(w):
                b[i][j] = 1
    elif a == 4:
        for i in range(y, h):
            for j in range(w):
                b[i][j] = 1
ans = 0
for i in range(h):
    for j in range(w):
        if b[i][j] == 0:
            ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ew,eh,n=[int(x) for x in input().rstrip().split()]
fw=0
fh=0
ansx=0
ansy=0
for i in range(n):
    x,y,a=[int(x) for x in input().rstrip().split()]
    if(a==1):
        fw=max(fw,x)
    elif(a==2):
        ew=min(ew,x)
    elif (a==3):
        fh=max(fh,y)
    elif (a==4):
        eh=min(eh,y)

if(ew-fw<0):
    ansx=0
elif(eh-fh<0):
    ansy=0
else:

    ansx=ew-fw
    ansy=eh-fh

print(ansx*ansy)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
w,h,n = map(int, sys.stdin.readline().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, x_min)
    elif a == 2:
        x_max = min(x, x_max)
    elif a == 3:
        y_min = max(y, y_min)
    else:
        y_max = min(y, y_max)

if x_min >= x_max or y_min >= y_max:
    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 j in range(N)]
x_0, y_0 = 0, 0
x_1, y_1 = W, H
for i in range(N):
    if xya[i][2] == 1:
        x_0 = max(x_0, xya[i][0])
    elif xya[i][2] == 2:
        x_1 = min(x_1, xya[i][0])
    elif xya[i][2] == 3:
        y_0 = max(y_0, xya[i][1])
    elif xya[i][2] == 4:
        y_1 = min(y_1, xya[i][1])
if x_0 < x_1 and y_0 < y_1:
    print((x_1 - x_0) * (y_1 - y_0))
else:
    print(0)

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
l=[0,w,0,h]
for i in range(n):
  a,c,d=map(int,input().split())
  x= c if (d)//3 else a
  f=min if (d-1)%2 else max
  l[d-1]=f(l[d-1],x)
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:
w,h,n=map(int,input().split())
info=[]
for i in range(n):
    x,y,a=map(int,input().split())
    info.append([x,y,a])
top,down,left,right=h,0,0,w
def calc(x,y,a):
    global top,down,left,right
    if a==1:
        if left<x:
            left=x
    elif a==2:
        if x<right:
            right=x
    elif a==3:
        if down<y:
            down=y
    else:
        if y<top:
            top=y
for i in range(n):
    calc(info[i][0],info[i][1],info[i][2])
    if top<=down:
        top,down=0,0
        break
    if right<=left:
        right,left=0,0
        break
    #print(right)
    #print(left)
print((top-down)*(right-left))

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
w_2 = 0
h_2 = 0
order = []

for i in range(n):
    array = list(map(int, input().split()))
    order.append(array)

for i, j, a in order:
    if a == 1:
        w_2 = max(w_2, i)
    elif a == 2:
        w = min(w, i)
    elif a == 3:
        h_2 = max(h_2, j)
    else:
        h = min(h, j)

tate = h - h_2
yoko = w - w_2
if tate < 0 or yoko < 0:
    print(0)
    exit()
print(max(tate*yoko, 0))

Submission status: Accepted

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

max_W = W
max_H = H
S = W * H
sx, sy = 0, 0

for i in range(N):
    if a[i] == 1:
        if (x[i] - sx) * (max_H - sy) >= 0:
            S -= (x[i] - sx) * (max_H - sy)
            sx = x[i]
    elif a[i] == 2:
        if (max_W - x[i]) * (max_H - sy) >= 0:
            S -= (max_W - x[i]) * (max_H - sy)
            max_W = x[i]
    elif a[i] == 3:
        if (max_W - sx) * (y[i] - sy) >= 0:
            S -= (max_W - sx) * (y[i] - sy)
            sy = y[i]
    else:
        if (max_W - sx) * (max_H - y[i]) >= 0:
            S -= (max_W - sx) * (max_H - y[i])
            max_H = y[i]

if S < 0:
    S = 0

print(S)

Submission status: Accepted

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

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


f = [[0] * w for _ in range(h)]

for i in range(n):
    for x in range(w):
        for y in range(h):
            if xya[i][2] == 1 and x < xya[i][0]:
                f[y][x] = 1
            elif xya[i][2] == 2 and x >= xya[i][0]:
                f[y][x] = 1
            elif xya[i][2] == 3 and y < xya[i][1]:
                f[y][x] = 1
            elif xya[i][2] == 4 and y >= xya[i][1]:
                f[y][x] = 1

ans = 0
for i in range(h):
    for j in range(w):
        if f[i][j]:
            ans += 1
print(w * h - ans)

Submission status: Accepted

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

mw = 0
mh = 0
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        mw = max(mw, x)
    elif a == 2:
        w = min(w, x)
    elif a == 3:
        mh = max(mh, y)
    elif a == 4:
        h = min(h, y)

print((w-mw)*(h-mh) if mw <= w and mh <= h else 0)

Submission status: Accepted

Solution code:

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

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

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

	if a == 2:
		maxx = min(maxx, x)
	elif a == 1:
		minx = max(minx, x)
	elif a == 4:
		maxy = min(maxy, y)
	else:
		miny = max(miny, y)

ans = (maxx - minx) * (maxy - miny)

if minx < maxx and miny < maxy:
	print(ans)
else:
	print(0)

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
pnt=[list(map(int,input().split())) for i in range(n)]
x1,x2,y1,y2=0,w,0,h
for i in range(n):
  if pnt[i][2]==1:
    x1=max(x1,pnt[i][0])
  if pnt[i][2]==2:
    x2=min(x2,pnt[i][0])
  if pnt[i][2]==3:
    y1=max(y1,pnt[i][1])
  if pnt[i][2]==4:
    y2=min(y2,pnt[i][1])
print(max(x2-x1,0)*max(y2-y1,0))

Submission status: Accepted

Solution code:
import sys
import numpy as np 

I = np.array(sys.stdin.read().split(), dtype=np.int64)
w, h, n = I[:3]
x, y, a = I[3:].reshape(n, 3).T 

def main():
    l = 0
    r = w
    d = 0
    u = h
    if np.any(a == 1):
        l = np.amax(x[a == 1])
    if np.any(a == 2):
        r = np.amin(x[a == 2])
    if np.any(a == 3):
        d = np.amax(y[a == 3])
    if np.any(a == 4):
        u = np.amin(y[a == 4])
        
    if l > r or d > u:
        return 0
    return (r - l) * (u - d)

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
W,H,N=map(int,input().split())

def paint(mth,lis,w,h):
    if mth==1:
        for i in range(H):
            for j in range(w):
                l[i][j]=1
    elif mth==2:
        for i in range(H):
            for j in range(w,W):
                l[i][j]=1
    elif mth==3:
        for i in range(h):
            for j in range(W):
                lis[i][j]=1
    else:
        for i in range(h,H):
            for j in range(W):
                lis[i][j]=1
                
l=[[0]*W for i in range(H)]

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

ans=0
for i in range(H):
    for j in range(W):
        ans+=l[i][j]

print(H*W-ans)

Submission status: Accepted

Solution code:
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect
import itertools


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(W, H, N, inputs):
    actions = list(map(string_to_int, inputs))
    white_x1 = 0
    white_x2 = W
    white_y1 = 0
    white_y2 = H

    for a in actions:
        if a[2] == 1:
            if white_x1 < a[0]:
                white_x1 = a[0]
        elif a[2] == 2:
            if white_x2 > a[0]:
                white_x2 = a[0]
        elif a[2] == 3:
            if white_y1 < a[1]:
                white_y1 = a[1]
        elif a[2] == 4:
            if white_y2 > a[1]:
                white_y2 = a[1]

    if white_x1 >= white_x2 or white_y1 >= white_y2:
        return 0
    return (white_x2 - white_x1) * (white_y2 - white_y1)


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    [W, H, N] = string_to_int(input())
    ret = solve(W, H, N, inputs(N))
    print(ret)

Submission status: Accepted

Solution code:
# 幅W, 高さH, 点の数N
W, H, N = map(int, input().split())

# ゼロ(白)で埋めた2次元配列
tmp = [[0] * W for i in range(H)]
tmp

# N回塗りつぶす
for n in range(N):
    # 塗る場所を入力する
    X,Y,A = map(int, input().split())
    
    if A == 1:
        # xより左を塗る
        for y in range(0,H):
            for x in range(0,X):
                tmp[y][x] = 1

    if A == 2:
        # xより右を塗る
        for y in range(0,H):
            for x in range(X,W):
                tmp[y][x] = 1
                
    if A == 3:
        # yより下を塗る
        for y in range(0,Y):
            for x in range(0,W):
                tmp[y][x] = 1
                
    if A==4:
        # yより下を塗る
        for y in range(Y,H):
            for x in range(0,W):
                tmp[y][x] = 1

#print(tmp)
# ゼロの数を数えると、塗りつぶされていないエリアの面積がわかる
result = 0
for y in range(0,H):
    for x in range(0,W):
        if tmp[y][x] == 0:
            result += 1
print(result)

Submission status: Accepted

Solution code:

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


d = []
for _ in range(n):
  a = [int(i) for i in input().split()]
  d.append(a)



x1 = [0]
x2 = [w]
y1 = [0]
y2 = [h]

for i in range(n):
  if d[i][2] == 1:
    x1.append(d[i][0])
  if d[i][2] == 2:
    x2.append(d[i][0])
  if d[i][2] == 3:
    y1.append(d[i][1])
  if d[i][2] == 4:
    y2.append(d[i][1])

x1 = sorted(x1, reverse = True)[0]
x2 = sorted(x2)[0]
y1 = sorted(y1, reverse = True)[0]
y2 = sorted(y2)[0]

sum = (x2 - x1)*(y2 - y1)
if x2 - x1 >= 0 and y2 - y1 >= 0:
  print(sum)
else:
  print(0)

Submission status: Accepted

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

x_min = 0
x_max = W
y_min = 0
y_max = H

for i in range(N):
  x, y, a = [int(j) for j in input().split()]
  
  if a == 1:
    x_min = max(x, x_min)
  elif a == 2:
    x_max = min(x, x_max)
  elif a == 3:
    y_min = max(y, y_min)
  else:
    y_max = min(y, y_max)

width = x_max - x_min
height = y_max - y_min

if width > 0 and height > 0:
  print(width * height)
else:
  print(0)

Submission status: Accepted

Solution code:
WHN = list(map(int,input().split()))
W=WHN[0]
H=WHN[1]
N=WHN[2]

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)

l_1 = [i for i , z in enumerate(a) if z==1]
l_1_max=[]

n1=0
n2=W
n4=H
n3=0

for i in l_1:
    l_1_max.append(x[i])
    n1=max(l_1_max)

l_2 = [i for i , z in enumerate(a) if z==2]
l_2_min=[]

for i in l_2:
    l_2_min.append(x[i])
    n2=min(l_2_min)

l_3 = [i for i , z in enumerate(a) if z==3]
l_3_max=[]

for i in l_3:
    l_3_max.append(y[i])
    n3=max(l_3_max)

l_4 = [i for i , z in enumerate(a) if z==4]
l_4_min=[]

for i in l_4:
    l_4_min.append(y[i])
    n4=min(l_4_min)

if n1<n2 and n3<n4:
    S=(n2-n1)*(n4-n3)
    print(S)
else:
    print(0)

Submission status: Accepted

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

def solve(W: int, H: int, N: int, x: "List[int]", y: "List[int]", a: "List[int]"):
    cnt = 0
    for y_ in range(H):
        for x_ in range(W):
            for i in range(N):
                if a[i] == 1 and x_ < x[i] or a[i] == 2 and x_ >= x[i] or a[i] == 3 and y_ < y[i] or a[i] == 4 and y_ >= y[i]:
                    break
            else:
                cnt += 1
    return cnt

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    W = int(next(tokens))  # type: int
    H = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]"
    y = [int()] * (N)  # type: "List[int]"
    a = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
        a[i] = int(next(tokens))
    print(solve(W, H, N, x, y, a))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
xy = [list(map(int, input().split())) for i in range(N)]
x_black = [0] * W 
y_black = [0] * H 
def get_area(x, y, a): 
        if a == 1:
                for i in range(x):
                        x_black[i] = 1 
        if a == 2:
                for i in range(x, W): 
                        x_black[i] = 1 
        if a == 3:
                for i in range(y):
                        y_black[i] = 1 
        if a == 4:
                for i in range(y, H): 
                        y_black[i] = 1 
for i in xy: 
        get_area(i[0], i[1], i[2])
print(x_black.count(0) * y_black.count(0))