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())
ws = hs = 0

li_point = list()
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        ws = x if x >= ws else ws
    elif a == 2:
        w = x if x <= w else w
    elif a == 3:
        hs = y if y >= hs else hs
    else: # a == r
        h = y if y <= h else h

yoko = w - ws if w - ws > 0 else 0
tate = h - hs if h - hs > 0 else 0

print(yoko * tate)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
l=[[int(j) for j in input().split()] for i in range(n)]
b=c=0
d=w
e=h
for i in range(n):
    a=l[i][2]
    if a==1:b=max(b,l[i][0])
    if a==2:d=min(d,l[i][0])
    if a==3:c=max(c,l[i][1])
    if a==4:e=min(e,l[i][1])
print([(d-b)*(e-c),0][(d<b)|(e<c)])

Submission status: Accepted

Solution code:
# _*_ coding:utf-8 _*_
#  Atcoder_Beginner_Contest047-B
#  TODO https://atcoder.jp/contests/abc047/tasks/abc047_b

def solveProblem(XLine,YLine,PointCounter):
	graphPaper = [[1 for _ in range(0,YLine,+1)] for _ in range(0,XLine,+1)]
	xplot = list()
	yplot = list()
	processSelect = list()
	for _ in range(0,PointCounter,+1):
		xplotEach,yplotEach,processSelectEach = map(int,input().strip().split(' '))
		xplot.append(xplotEach)
		yplot.append(yplotEach)
		processSelect.append(processSelectEach)

	for i in range(0,PointCounter,+1):
		if processSelect[i]==1:
			xrange = range(0,xplot[i],+1)
			yrange = range(0,YLine,+1)
		elif processSelect[i]==2:
			xrange = range(xplot[i],XLine,+1)
			yrange = range(0,YLine,+1)
		elif processSelect[i]==3:
			xrange = range(0,XLine,+1)
			yrange = range(0,yplot[i],+1)
		elif processSelect[i]==4:
			xrange = range(0,XLine,+1)
			yrange = range(yplot[i],YLine,+1)
		for x in xrange:
			for y in yrange:
				graphPaper[x][y]=0
	menseki=0
	for x in range(0,XLine,+1):
		for y in range(0,YLine,+1):
			if graphPaper[x][y]==1:
				menseki = menseki + 1
	answer = menseki
	return answer


if __name__ == '__main__':
	W,H,N = map(int,input().strip().split(' '))
	solution = solveProblem(W,H,N)
	print("{}".format(solution))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
X,Y,A = [],[],[]
for i in range(N):
    x,y,a = map(int,input().split())
    X.append(x)
    Y.append(y)
    A.append(a)
x0,x1,y0,y1 = 0,W,0,H
for i in range(N):
    if A[i]==1:
        x0 = max(x0,X[i])
    elif A[i]==2:
        x1 = min(x1,X[i])
    elif A[i]==3:
        y0 = max(y0,Y[i])
    else:
        y1 = min(y1,Y[i])

print(max(0,(x1-x0))*max(0,(y1-y0)))

Submission status: Accepted

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

Submission status: Accepted

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

LL = []

for j in range(H):
    L = []
    for i in range(W):
        L.append(0)
    LL.append(L)

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        # ans -= x * H
        for j in range(H):
            LL[j][:x] = [1 for k in range(x)]
    elif a == 2:
        # ans -= (W - x) * H
        for j in range(H):
            LL[j][x:] = [1 for k in range(x)]
    elif a == 3:
        # ans -= W * y
        cnt = 0
        for j in range(H):
            if cnt >= H - y:
                LL[j] = [1 for k in range(x)]
            cnt += 1
    else:
        # ans -= W * (H - y)
        for j in range(H - y):
            LL[j] = [1 for k in range(x)]

ans = 0
for i in LL:
    for j in i:
        if j == 0:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
max_x = W
min_x = 0
max_y = H
min_y = 0
for i in range(N):
    x,y,a = map(int,input().split())
    if a == 1 and x > min_x:
        min_x = x
    if a == 2 and x < max_x:
        max_x = x
    if a == 3 and y > min_y:
        min_y = y
    if a == 4 and y < max_y:
        max_y = y
if max_x - min_x < 0 or max_y - min_y < 0:
    ans = 0
else:
    ans = (max_x - min_x) * (max_y - min_y)

print(ans)

Submission status: Accepted

Solution code:
import sys


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


x_max, y_max, N = il()
x_min, y_min = 0, 0
s = 0
for i in range(N):
    x, y, a = il()
    if a == 1:
        x_min = max(x_min, x)
    elif a == 2:
        x_max = min(x_max, x)
    elif a == 3:
        y_min = max(y_min, y)
    else:
        y_max = min(y_max, y)
if x_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:
x2, y2, n = [int(i) for i in input().split()]
x1, y1 = (0, 0)

for i in range(n):
    x, y, a = [int(x) for x in input().split()]
    if a == 1:
        x1 = max(x1, x)
    elif a == 2:
        x2 = min(x2, x)
    elif a == 3:
        y1 = max(y1, y)
    elif a == 4:
        y2 = min(y2, y)

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

Submission status: Accepted

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

if x_max > x_min or y_max > y_min:
    print(0)
else:
    if y_min == 100:
        y_min = H
    if x_min == 100:
        x_min = W
    print((y_min-y_max)*(x_min-x_max))

Submission status: Accepted

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

W, H, N = inpl()
l, r, d, u = 0, W, 0, H

for _ in range(N):
    x, y, a = inpl()
    if a == 1:
        l = max(l, x)
    elif a == 2:
        r = min(r, x)
    elif a == 3:
        d = max(d, y)
    else:
        assert a == 4
        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())
lx, mx = 0, w
ly, my = 0, h

for _ in range(n):
  x, y, a = map(int, input().split())
  if a == 1:
    lx = max(lx, x)
  elif a == 2:
    mx = min(mx, x)
  elif a == 3:
    ly = max(ly, y)
  elif a == 4:
    my = min(my, y)
print((mx-lx)*(my-ly) if mx > lx and my > ly else 0)

Submission status: Accepted

Solution code:
x,y,n = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(n)]
a,b,c,d = [0,0],[x,0],[x,y],[0,y]

for i in range(n):
    if A[i][2] == 1:
        if A[i][0] >= b[0]:
            print(0)
            break
        else:
            a[0] = max(A[i][0],a[0])
            d[0] = a[0]
    if A[i][2] == 2:
        if A[i][0] <= a[0]:
            print(0)
            break
        else:
            b[0] = min(A[i][0],b[0])
            c[0] = b[0]
    if A[i][2] == 3:
        if A[i][1] >= d[1]:
            print(0)
            break
        else:
            a[1] = max(A[i][1],a[1])
            b[1] = a[1]
    if A[i][2] == 4:
        if A[i][1] <= a[1]:
            print(0)
            break
        else:
            c[1] = min(A[i][1],c[1])
            d[1] = c[1]
else:
    print((b[0]-a[0])*(d[1]-a[1]))

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
wl = 0
wr = W
hu = 0
hl = W

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

    if a == 1:
        if x > wl:
            wl = x
    elif a == 2:
        if x < wr:
            wr = x
    elif a == 3:
        if y > hu:
            hu = y
    else:
        if y < hl:
            hl = y

if wl >= wr or hu >= hl:
    print(0)
else:
    ans = (wr - wl) * (hl - hu)
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
x,y = 0,0
X,Y = w,h
for i in range(n):
    a,b,c = map(int,input().split())
    if c == 1 and x < a:
        x = a
    elif c == 2 and a < X:
        X = a
    elif c == 3 and y < b:
        y = b
    elif c == 4 and b < Y:
        Y = b
print(max(X-x,0)*max(Y-y,0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
xmax=w
ymax=h
xmin=0
ymin=0

for i in range(n):
  x,y,a=map(int,input().split())
  if a==1 and xmin<x:
    xmin=x
  if a==2 and xmax>x:
    xmax=x
  if a==3 and ymin<y:
    ymin=y
  if a==4 and ymax>y:
    ymax=y

if (xmax-xmin)>0 and (ymax-ymin)>0:
  print((xmax-xmin)*(ymax-ymin))
else:
  print(0)

Submission status: Accepted

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

Submission status: Accepted

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

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

print('0'if ax>=w or ay>=h else(w-ax)*(h-ay))
#コピペです。

Submission status: Accepted

Solution code:
xmax, ymax, N = map(int, input().split())
xmin = 0
ymin = 0
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        if x > xmin: xmin = x
    if a == 2:
        if x < xmax: xmax = x
    if a == 3:
        if y > ymin: ymin = y
    if a == 4:
        if y < ymax: ymax = y
print(max(xmax - xmin, 0) * max(ymax - ymin, 0))

Submission status: Accepted

Solution code:
W,H,N=map(int, input().split())
gss=[[1] * (H) for _ in range(W)]
for _ in range(N):
    x,y,a=map(int, input().split())
    xFr,xTo,yFr,yTo=0,W-1,0,H-1
    if a==1: xTo=x-1
    elif a==2: xFr=x
    elif a==3: yTo=y-1
    elif a==4: yFr=y
    for x in range(xFr,xTo+1):
        for y in range(yFr,yTo+1):
            gss[x][y]=0
print(sum(map(sum, gss)))

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
x1,y1,x2,y2 = 0,0,w,h
for i in range(n):
    b,c,d = map(int,input().split())
    if d == 1:
        x1 = max(x1,b)
    elif d == 2:
        x2 = min(x2,b)
    elif d == 3:
        y1 = max(y1,c)
    else:
        y2 = min(y2,c)
if x2-x1 <= 0 or y2 <= 0:
    print(0)
else:
    print((x2-x1)*(y2-y1))

Submission status: Accepted

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

for i in range(N):
  x, y, a = map(int,input().split())
  if(a == 1):
    dx = max(dx, x)
  elif(a == 2):
    W = min(W, x)
  elif(a == 3):
    dy = max(dy, y)
  else:
    H = min(H, y)
if(W <= dx or H <= dy):
  print(0)
else:
  print((dx-W) * (dy-H))

Submission status: Accepted

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

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

print('0'if ax>=w or ay>=h else(w-ax)*(h-ay))

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
ax=0
ix=w
ay=0
iy=h

for i in range(n):
    x,y,a=map(int,input().split())
    if(a==1):
        ax=max(ax,x)
    elif(a==2):
        ix=min(ix,x)
    elif(a==3):
        ay=max(ay,y)
    else:
        iy=min(iy,y)

if(ax>=ix or ay>=iy):
    print('0')
    exit()

else:
    print((ix-ax)*(iy-ay))

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
x=[]
y=[]
a=[]
ax=0
ix=w
ay=0
iy=h

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

for j in range(n):
    if(a[j]==1):
        ax=max(ax,x[j])
    elif(a[j]==2):
        ix=min(ix,x[j])
    elif(a[j]==3):
        ay=max(ay,y[j])
    else:
        iy=min(iy,y[j])

if(ax>=ix or ay>=iy):
    print('0')
    exit()

else:
    print((ix-ax)*(iy-ay))

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
x=[]
y=[]
a=[]
maxx=0
minx=w
maxy=0
miny=h

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

for j in range(n):
    if(a[j]==1):
        maxx=max(maxx,x[j])
    elif(a[j]==2):
        minx=min(minx,x[j])
    elif(a[j]==3):
        maxy=max(maxy,y[j])
    else:
        miny=min(miny,y[j])

if(maxx>=minx):
    print('0')
    exit()

elif(maxy>=miny):
    print('0')
    exit()

if(maxx<minx or maxy<miny):
    print((minx-maxx) * (miny-maxy))

Submission status: Accepted

Solution code:
def main():
    w, h, n = map(int, input().split())
    coord = [[1] * w for _ in range(h)]

    for _ in range(n):
        xi, yi, a = map(int, input().split())
        if a == 1:
            for y in range(h):
                for x in range(0, xi):
                    coord[y][x] = 0
        elif a == 2:
            for y in range(h):
                for x in range(xi, w):
                    coord[y][x] = 0
        elif a == 3:
            for y in range(0, yi):
                coord[y] = [0] * w
        else:
            for y in range(yi, h):
                coord[y] = [0] * w

    print(sum(map(sum, coord)))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
c = []
for i in range(n):#h:高さ
    c.append([int(m) for m in input().split()])

sx = [0, w]
sy = [0, h]
for i in range(n):
    if c[i][2] == 1:
        if sx[0] < c[i][0]:
            sx[0] = c[i][0]
    elif c[i][2] == 2:
        if sx[1] > c[i][0]:
            sx[1] = c[i][0]
    elif c[i][2] == 3:
        if sy[0] < c[i][1]:
            sy[0] = c[i][1]
    elif c[i][2] == 4:
        if sy[1] > c[i][1]:
            sy[1] = c[i][1]
if sx[1] <= sx[0] or sy[1] <= sy[0]:
    print(0)
else:
    print((sx[1] - sx[0]) * (sy[1] - sy[0]))

Submission status: Accepted

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

MINX=0
MAXX=W
MINY=0
MAXY=H

for x,y,a in XYA:
    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)

print(max(MAXY-MINY,0)*max(MAXX-MINX,0))

Submission status: Accepted

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

for _ in range(n):
    x, y, a = [int(i) for i in input().split()]
    if a == 1:
        table[0][0] += 1
        if x < w:
            table[0][x] -= 1
    elif a == 2:
        if x < w:
            table[0][x] += 1
    elif a == 3:
        table[0][0] += 1
        if y < h:
            table[y][0] -= 1
    elif a == 4:
        if y < h:
            table[y][0] += 1

for i in range(len(table)):
    for j in range(1, len(table[i])):
        table[i][j] += table[i][j-1]
for i in range(1, len(table)):
    for j in range(len(table[i])):
        table[i][j] += table[i-1][j]
count = 0
for i in range(len(table)):
    for j in range(len(table[i])):
        if table[i][j] == 0:
            count += 1
print(count)

Submission status: Accepted

Solution code:
import numpy as np
W, H, N = map(int, input().split())
P = [tuple(map(int, input().split())) for _ in range(N)]
rect = np.ones([W, H])
for p in P:
    if p[2] == 1:
        rect[:p[0]] = 0
    elif p[2] == 2:
        rect[p[0]:] = 0
    elif p[2] == 3:
        rect[:, :p[1]] = 0
    elif p[2] == 4:
        rect[:, p[1]:] = 0
print(int(np.sum(rect)))

Submission status: Accepted

Solution code:
line = input().split(" ")
w = int(line[0])
h = int(line[1])
n = int(line[2])
area = [[0 for wx in range(w)] for hy in range(h)]
c = 0

for i in range(n):
    line = input().split(" ")
    x = int(line[0])
    y = int(line[1])
    a = int(line[2])
    if a == 1:
        for xi in range(h):
            for yi in range(x):
                area[xi][yi] = 1
    elif a == 2:
        for xi in range(h):
            for yi in range(w-x):
                area[xi][yi+x] = 1
    elif a == 3:
        for yi in range(w):
            for xi in range(y):
                area[xi][yi] = 1
    elif a == 4:
        for yi in range(w):
            for xi in range(h-y):
                area[xi+y][yi] = 1

for i in range(h):
    c = area[i].count(0) + c
print(c)

Submission status: Accepted

Solution code:
import collections as cl

W,H,N = [int(i) for i in input().split()]
action_list = []
ACTION_INDEX = {
	"X" : 0,
	"Y" : 1,
	"TYPE" : 2
}
ACTION_TYPE = {
	"LESS_THAN_X" : 1,
	"MORE_THAN_X" : 2,
	"LESS_THAN_Y" : 3,
	"MORE_THAN_Y" : 4,
}

for i in range(N) :
	action_list.append([int(i) for i in input().split()])

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

for actions in action_list :
	if(actions[ACTION_INDEX["TYPE"]] == ACTION_TYPE["LESS_THAN_X"]) :
		for i in range(actions[ACTION_INDEX["X"]]) :
			for j in range(H) :
				arr[i][j] = 1

	elif (actions[ACTION_INDEX["TYPE"]] == ACTION_TYPE["MORE_THAN_X"]) :
		for i in range(actions[ACTION_INDEX["X"]], W) :
			for j in range(H) :
				arr[i][j] = 1
	elif (actions[ACTION_INDEX["TYPE"]] == ACTION_TYPE["LESS_THAN_Y"]) :
		for i in range(W) :
			for j in range(actions[ACTION_INDEX["Y"]]) :
				arr[i][j] = 1
	elif (actions[ACTION_INDEX["TYPE"]] == ACTION_TYPE["MORE_THAN_Y"]) :
		for i in range(W) :
			for j in range(actions[ACTION_INDEX["Y"]], H) :
				arr[i][j] = 1

arr2 = []
for i in range(W) :
	for j in range(H) :
		arr2.append(arr[i][j])
c = cl.Counter(arr2)
print(c[0])

Submission status: Accepted

Solution code:
W,H,N = map(int, input().split())
x_min, y_min = 0,0
x_max, y_max = W,H
for _ in range(N):
    x,y,a = map(int, input().split())
    if a==1:
        x_min = max(x_min, x)
    elif a==2:
        x_max = min(x_max, x)
    elif a==3:
        y_min = max(y_min, y)
    else:
        y_max = min(y_max, y)
width = max(0, x_max-x_min)
height = max(0, y_max-y_min)
print(width*height)

Submission status: Accepted

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

for _ in range(N):
    x,y,a = map(int, input().split())
    if a==1:
        for h in range(H):
            for w in range(W):
                if w<x:
                    rec[h][w]="B"
    elif a==2:
        for h in range(H):
            for w in range(W):
                if w>=x:
                    rec[h][w]="B"
    elif a==3:
        for h in range(H):
            for w in range(W):
                if h<y:
                    rec[h][w]="B"
    else:
        for h in range(H):
            for w in range(W):
                if h>=y:
                    rec[h][w]="B"
                    
ans = 0
for h in range(H):
    for w in range(W):
        if rec[h][w]=="W":
            ans += 1
print(ans)
# print(rec)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
wt,ht,n=map(int,input().split())
# XYA=[list(map(int,input().split())) for i in range(n)]

w=[1]*wt
h=[1]*ht
for i in range(n):
  W,Y,A=map(int,input().split())
  if A==1:
    w=[0]*(W)+w[W:]
  elif A==2:
    w=w[:W]+[0]*(wt-W)
  elif A==3:
    h=h[:ht-(Y+1)+1]+[0]*(Y)
  elif A==4:
    h=[0]*(ht-Y)+h[ht-Y:]

print(sum(w)*sum(h))

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
rec = []
for h in range(H):
    rec.append([])
    for w in range(W):
        rec[h].append(1)
        
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        for h in range(H):
            for _x in range(x):
                rec[h][_x] = 0
    elif a == 2:   
        for h in range(H):
            for _x in range(x, W):
                rec[h][_x] = 0
    elif a == 3:
        for w in range(W):
            for _y in range(y):
                rec[_y][w] = 0
    else:   
        for w in range(W):
            for _y in range(y, H):
                rec[_y][w] = 0
    # print(rec)
for h in range(H):
    rec[h] = sum(rec[h])
print(sum(rec))

Submission status: Accepted

Solution code:
W, H, N = [int(_) for _ in input().split()]
maxX = W
minX = 0
maxY = H
minY = 0
for _ in range(N):
    X, Y, A = [int(_) for _ in input().split()]
    if A == 1:
        minX = max(minX, X)
    elif A == 2:
        maxX = min(maxX, X)
    elif A == 3:
        minY = max(minY, Y)
    else:
        maxY = min(maxY, Y)
if maxX > minX and maxY > minY:
    print((maxX - minX) * (maxY - minY))
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
W,H,N=map(int,input().strip().split(" "))
Sum=0
r=0
xx=0
yy=0
for i in range(N):
    x,y,a=map(int,input().strip().split(" "))
    
    if(a==1):
        if(xx<x):
            xx=x
    elif(a==2):
        if(W>x):
            W=x
    elif(a==3):
        if(yy<y):
            yy=y
    elif(a==4):
        if(H>y):
            H=y
Sum=(W-xx)*(H-yy)

if((W-xx)<=0 or (H-yy)<=0):
    print("0")
else:
    print(Sum)

Submission status: Accepted

Solution code:
w, h, n = list(map(int, input().split()))
x_max = 0
x_min = w
y_max = 0
y_min = h

for i in range(n):
    x, y, a = list(map(int, input().split()))
    if a == 1:
        x_max = max(x_max, x)
    elif a == 2:
        x_min = min(x_min, x)
    elif a == 3:
        y_max = max(y_max, y)
    else:
        y_min = min(y_min, y)
        
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:
# input
W, H, N = map(int, input().split())
a1 = 0
a2 = W
a3 = 0
a4 = H
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        if x >= a1:
            a1 = x
    if a == 2:
        if x <= a2:
            a2 = x
    if a == 3:
        if y >= a3:
            a3 = y
    if a == 4:
        if y <= a4:
            a4 = y

ans = max(0, (a2 - a1)) * max(0, (a4 - a3))
print(ans)

Submission status: Accepted

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

for i in range(N):
    x_i, y_i, a_i = [int(x) for x in input().split()]
    for y in range(H):
        for x in range(W):
            if a_i == 1:
                if x <  x_i: A[y][x] = 1
            elif a_i == 2:
                if x >= x_i: A[y][x] = 1
            elif a_i == 3:
                if y <  y_i: A[y][x] = 1
            else:
                if y >= y_i: A[y][x] = 1
cnt = 0
for y in range(H):
    for x in range(W):
        if A[y][x] == 0: cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
W,H,N = map(int, input().split())
s = set([])
for h in range(H):
    for w in range(W):
        s.add((w+0.5, h+0.5))
# print(s)

for _  in range(N):
    x,y,a = map(int, input().split())
    rm = set([])
    if a==1:
        for si in s:
            if si[0]<x: rm.add(si)
    if a==2:
        for si in s:
            if si[0]>x: rm.add(si)
    if a==3:
        for si in s:
            if si[1]<y: rm.add(si)
    if a==4:
        for si in s:
            if si[1]>y: rm.add(si)
    s = s - rm
                
print(len(s))

Submission status: Accepted

Solution code:
# coding: utf-8
W, H, N = map(int, input().split())
min_x, max_x = 0, W
min_y, max_y = 0, H

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

Submission status: Accepted

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

xl, yl, n = map(int, input().split())
xr = 0
yr = 0

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

    if a == 1:
        if xl < x:
            xl = x

        if xr < x:
            xr = x

    elif a == 2:
        if xl > x:
            xl = x

        if xr > x:
            xr = x

    elif a == 3:
        if yl < y:
            yl = y

        if yr < y:
            yr = y

    elif a == 4:
        if yl > y:
            yl = y

        if yr > y:
            yr = y

if (xl - xr) <= 0 or (yl - yr) <= 0:
    print('0')
else:
    print((xl - xr) * (yl - yr))

Submission status: Accepted

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

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):
    L = [int(i) for i in input().split()]
    if L[2] == 1:
        l = max(l, L[0])
    elif L[2] == 2:
        r = min(r, L[0])
    elif L[2] == 3:
        b = max(b, L[1])
    else:
        t = min(t, L[1])
if l < r and b < t:
    print((r-l)*(t-b))
else:
    print(0)

Submission status: Accepted

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

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

print(max(x1 - x0, 0) * max(y1 - y0, 0))

Submission status: Accepted

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

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

if x1 - x0 <= 0 or y1 - y0 <= 0:
    print(0)
else:
    print((x1 - x0) * (y1 - y0))

Submission status: Accepted

Solution code:
W, H, N = list(map(int, input().split()))
x0 = 0
x1 = W
y0 = 0
y1 = H

for i in range(N):
	x, y, a = list(map(int, input().split()))
	if a == 1:
		if x0 <= x:
			x0 = x
	elif a == 2:
		if x <= x1:
			x1 = x
	elif a == 3:
		if y0 <= y:
			y0 = y
	else:
		if y <= y1:
			y1 = y

if x1 - x0 <= 0 or y1 - y0 <= 0:
	print(0)
else:
	print((x1 - x0) * (y1 - y0))

Submission status: Accepted

Solution code:
w,h,n = map(int, input().split())
xya = []
xl, xr, yu, yt = 0, w, 0, h
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
       if xl < x:
           xl = x 
    elif a == 2:
        if xr > x:
            xr = x
    elif a == 3:
        if yu < y:
            yu = y
    else:
        if yt > y:
            yt = y
print([(xr - xl) * (yt - yu), 0][(xr - xl) <= 0 or (xr - xl) <= 0])