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())
l = [0, w, 0, h]
for i in range(n):
  x, y, a = map(int, input().split())
  if (a == 1):
    l[0] = max(l[0], x)
  elif (a == 2):
    l[1] = min(l[1], x)
  elif (a == 3):
    l[2] = max(l[2], y)
  else:
    l[3] = min(l[3], y)
print(max(0, (l[1] - l[0])) * max(0, (l[3] - l[2])))

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
area = [[0]*W for _ in range(H)]
x, y, a = [], [], []
for _ in range(N):
    xi, yi, ai = map(int, input().split())
    x.append(xi)
    y.append(yi)
    a.append(ai)


def show(area):
    for line in area:
        print(line)
    print("-----")


for i in range(N):
    # print("({}, {}, {})".format(x[i], y[i], a[i]))
    if a[i] == 1:
        for j in range(H):
            for k in range(x[i]):
                area[j][k] = 1
    if a[i] == 2:
        for j in range(H):
            for k in range(x[i], W):
                area[j][k] = 1
    if a[i] == 3:
        for j in range(H-y[i], H):
            for k in range(W):
                area[j][k] = 1
    if a[i] == 4:
        for j in range(0, H-y[i]):
            for k in range(W):
                area[j][k] = 1
    # show(area)
ans = 0
for i in range(H):
    for j in range(W):
        if area[i][j] == 0:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
L = []
for i in range(N):
  L.append(list(map(int,input().split())))
A = [0]
B = [W]
C = [0]
D = [H]
for i in range(N):
  if L[i][2] == 1:
    A.append(L[i][0])
  elif L[i][2] == 2:
    B.append(L[i][0])
  elif L[i][2] == 3:
    C.append(L[i][1])
  else:
    D.append(L[i][1])
A.sort()
A.reverse()
B.sort()
C.sort()
C.reverse()
D.sort()
w = 0
h = 0
if A[0] <= B[0]:
  w = B[0]-A[0]
else:
  w = 0
if C[0] <= D[0]:
  h = D[0]-C[0]
else:
  h = 0
print(w*h)

Submission status: Accepted

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

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

for i in range(N):
    x_tmp, y_tmp, a_tmp = map(int,input().split())
    if a_tmp == 1:
        x_min = max(x_tmp, x_min)
    elif a_tmp == 2:
        x_max = min(x_tmp, x_max)
    elif a_tmp == 3:
        y_min = max(y_tmp, y_min)
    else:
        y_max = min(y_tmp, 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:
right, top, n = map(int, input().split())
list = [list(map(int, input().split())) for i in range(n)]
bottom, left = 0, 0

for i in range(n):
    if list[i][2] == 1:
        left = max(list[i][0], left)
    elif list[i][2] == 2:
        right = min(list[i][0], right)
    elif list[i][2] == 3:
        bottom = max(list[i][1], bottom)
    else:
        top = min(list[i][1], top)

area = (top - bottom) * (right - left)

print(area if top - bottom > 0 and right - left > 0 else 0)

Submission status: Accepted

Solution code:
import sys
W,H,N = [int(n) for n in input().split()]
# N = int(input())
# a = [int(input()) for _ in range(N)]
field = [[1 for _ in range(H)] for _ in range(W)]
x = [0]*N
y = [0]*N
a = [0]*N# 1 == 左の面、2 == 右, 3 == 下 4 == 下
for i in range(N):
    x[i], y[i], a[i] = [int(n) for n in input().split()]
    if(a[i] == 1):
        for k in range(x[i]):
            field[k] = [0 for _ in range(H)]
    elif(a[i] == 2):
        for k in range(x[i],W):
            field[k] = [0 for _ in range(H)]
    elif(a[i] == 3):
        for k in range(W):
            for j in range(y[i]):
                field[k][j] = 0
    elif(a[i] == 4):
        for k in range(W):
            for j in range(y[i],H):
                field[k][j] = 0
    # for k in range(W):
        # print(field[k])
ans = 0
for i in range(W):
    ans+=sum(field[i])
    # print(field[i])
print(ans)

Submission status: Accepted

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

if f[0]-s[0] <= 0 or f[1] - s[1] <= 0:
    print(0)
else:
    print((f[0]-s[0])*(f[1]-s[1]))

Submission status: Accepted

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

yoko = [0,w]
tate = [0,h]

for i in range(n):
  if info [i][2]==1 and yoko[0]<info[i][0]:
    yoko[0]=info[i][0]
  elif info [i][2]==2 and yoko[1]>info[i][0]:
    yoko[1]=info[i][0]
  elif info [i][2]==3 and tate[0]<info[i][1]:
    tate[0]=info[i][1]
  elif info [i][2]==4 and tate[1]>info[i][1]:
    tate[1]=info[i][1]

len_yoko = yoko[1]-yoko[0]
len_tate = tate[1]-tate[0]
if len_yoko<=0 or len_tate<=0:
  print(0)
else:
  print(len_tate*len_yoko)

Submission status: Accepted

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

x1 = 0
x2 = W
y1 = 0
y2 = H
rectangle_S = W*H
black_S = 0
judge = 1 #1:黒部分全部でない,0:黒部分全部

for i in range(N):
  x,y,a = map(int,input().split())
  if(a == 1):
    if(x < x1):
     black_S += 0
     x1 = x1
    elif(x1 <= x <= x2):
     black_S += (x-x1)*(y2-y1)
     x1 = x
    elif(x2 < x):
     black_S = W*H
     break      
  elif(a == 2):
    if(x < x1):
     black_S = W*H
     judge = 0 #黒全部
    elif(x1 <= x <= x2):
     black_S += (x2-x)*(y2-y1)
     x2 = x
    elif(x2 < x):
     black_S += 0
     #x2 = x2   
  elif(a == 3):
    if(y < y1):
     black_S += 0
     y1 = y1
    elif(y1 <= y <= y2):
     black_S += (y-y1)*(x2-x1)
     y1 = y
    elif(y2 < y):
     black_S = W*H
     judge = 0   
  elif(a == 4):
    if(y < y1):
     black_S = W*H
     judge = 0 #黒全部
    elif(y1 <= y <= y2):
     black_S += (y2-y)*(x2-x1)
     y2 = y
    elif(y2 < y):
     black_S += 0
     #y2 = y2

if(judge == 0):
  print(0)
else:
  print(rectangle_S - black_S)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
W, H, N = map(int, input().split())
grid = [[0, W], [0, H]]
for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        if grid[0][0] < x:
            grid[0][0] = x
    elif a == 2:
        if grid[0][1] > x:
            grid[0][1] = x
    elif a == 3:
        if grid[1][0] < y:
            grid[1][0] = y
    else:
        if grid[1][1] > y:
            grid[1][1] = y
ans = (grid[0][1] - grid[0][0]) * (grid[1][1] - grid[1][0])
if grid[0][0] > grid[0][1] or grid[1][0] > grid[1][1]:
    ans = 0
print(ans)

Submission status: Accepted

Solution code:
import sys
W,H,N=map(int,input().split())
wide=[0,W]
height=[0,H]
# white sphere calculate
for i in range(N):
    x,y,a=map(int,input().split())
    if a==1:
        wide[0]=max(wide[0],x)
    elif a==2:
        wide[1]=min(wide[1],x)
    elif a==3:
        height[0]=max(height[0],y)
    elif a==4:
        height[1]=min(height[1],y)
w_len=wide[1]-wide[0]
h_len=height[1]-height[0]
s=w_len*h_len
if h_len<0 or w_len<0:
    print(0)
else:
    print(s)

Submission status: Accepted

Solution code:
w,h,n = (int(i) for i in input().split())
sq = [0,0,w,h]
answer = 0
#x1,y1 x2,y2
for j in range(n):
  x,y,a = (int(k) for k in input().split())
  if a == 1 and sq[0] < x:
    sq[0] = x
  elif a == 2 and sq[2] > x:
    sq[2] = x
  elif a == 3 and sq[1] < y:
    sq[1] = y
  elif a == 4 and sq[3] > y:
    sq[3] = y
if sq[2]-sq[0] > 0 and sq[3]-sq[1] > 0:
  answer = (sq[2]-sq[0])*(sq[3]-sq[1])
print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
p = [0, 0]
q = [W, H]
for _ in [0]*N:
    x, y, a = map(int, input().split())
    if a == 1:
        p[0] = max(p[0], x)
    elif a == 2:
        q[0] = min(q[0], x)
    elif a == 3:
        p[1] = max(p[1], y)
    elif a == 4:
        q[1] = min(q[1], y)

if q[0] - p[0] < 0 or q[1] - p[1] < 0:
    print(0)
else:
    print((q[0] - p[0])*(q[1] - p[1]))

Submission status: Accepted

Solution code:
W, H, N = map(int,input().split())
dx, dy = 0, 0
for _ 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:
#import pprint
w,h,n=map(int,input().split())
x=[]
y=[]
a=[]
for i in range(n):
    xi,yi,ai=map(int,input().split())
    x.append(xi)
    y.append(yi)
    a.append(ai)

dot = [[0] * w for i in range(h)]
#pprint.pprint(dot,width=60)

for i in range(n):
    if a[i] == 1:
        for j in range(x[i]):
            for k in range(h):
                dot[k][j]=1
    if a[i] == 2:
        for j in range(x[i],w):
            for k in range(h):
                dot[k][j]=1
    if a[i] == 3:
        for j in range(y[i]):
            for k in range(w):
                dot[j][k]=1
    if a[i] == 4:
        for j in range(y[i],h):
            for k in range(w):
                dot[j][k]=1
    #pprint.pprint(dot,width=60)

print(sum(dot,[]).count(0))

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
A=[[0 for i in range(w)] for j in range(h)]
for i in range(n):
  a,b,c=map(int,input().split())
  if c==1:
    for i in range(h):
      for j in range(a):
        A[i][j]=1
  elif c==2:
    for i in range(h):
      for j in range(w-a):
        A[i][j+a]=1
  elif c==3:
    for i in range(b):
      A[i]=[1 for i in range(w)]
  else:
    for i in range(h-b):
      A[h-i-1]=[1 for i in range(w)]
ans=0
for i in range(h):
  ans+=A[i].count(0)
print(ans)

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
xl = yd = 0
xr = W
yu = H
for _ in range(N):
    X,Y,A = map(int,input().split())
    if A == 1:xl = max(X,xl)
    elif A == 2:xr = min(X,xr)
    elif A == 3:yd = max(Y,yd)
    elif A == 4:yu = min(Y,yu)
s = max(0,(xr-xl)) * max(0,(yu-yd))
print(s)

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
dots = [list(map(int,input().split())) for i in range(n)]
xl = [dots[i] for i in range(n) if dots[i][2] == 1]
xr = [dots[i] for i in range(n) if dots[i][2] == 2]
yd = [dots[i] for i in range(n) if dots[i][2] == 3]
yu = [dots[i] for i in range(n) if dots[i][2] == 4]

kfunc1 = lambda x : x[0]
kfunc2 = lambda y : y[1]

xxl = max(xl,key = kfunc1,default = [0,0,0])
xxr = min(xr,key = kfunc1,default = [w,0,0])
yyd = max(yd,key = kfunc2,default = [0,0,0])
yyu = min(yu,key = kfunc2,default = [0,h,0])

if xxl[0] >= xxr[0] or yyd[1] >= yyu[1]: print(0)
else : print((xxr[0]-xxl[0])*(yyu[1]-yyd[1]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
a = [[int(i) for i in input().split()] for j in range(n)]
s = [0,w]
t = [0,h]
for i in range(n):
    if a[i][2] == 1:
        s[0] = max(s[0],a[i][0])
    elif a[i][2] == 2:
        s[1] = min(s[1],a[i][0])
    elif a[i][2] == 3:
        t[0] = max(t[0],a[i][1])
    else:
        t[1] = min(t[1],a[i][1])
print(max(0,(s[1]-s[0]))*max(0,(t[1]-t[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 == 1:
        minx = max(minx, x)
    elif a == 2:
        maxx = min(maxx, x)
    elif a == 3:
        miny = max(miny, y)
    else:
        maxy = min(maxy, y)

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

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

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
flag=0
lst=[]
most_up=H
most_down=0
most_right=W
most_left=0
now_location=[most_up, most_down, most_right, most_left]
for i in range(N):
    lst.append(list(map(int,input().split())))
for i in lst:
    if i[2]==1:
        if now_location[3] <= i[0]:
            now_location[3]=i[0]
    elif i[2]==2:
        if now_location[2] >= i[0]:
            now_location[2]=i[0]
    elif i[2]==3:
        if now_location[1] <= i[1]:
            now_location[1]=i[1]
    else:
        if now_location[0] >= i[1]:
            now_location[0]=i[1]
height=now_location[0]-now_location[1]
width=now_location[2]-now_location[3]
print(0) if (height<0 or width<0) else print(height*width)

Submission status: Accepted

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

l,r,t,b = 0,W,0,H
for _ in range(N):
  x,y,a = map(int, raw_input().split())
  if a==1:
    l = max(l, x)
  if a==2:
    r = min(r, x)
  if a==3:
    t = max(t, y)
  if a==4:
    b = min(b, y)
print max(r-l, 0)*max(b-t, 0)

Submission status: Accepted

Solution code:
whn = list (map(int, input().split()))
x = 0
y = 0
flag = 0

for i in range(whn[2]):
    xya = list(map(int,input().split()))
    if xya[2] == 1:
        x = max(x, xya[0])
    elif xya[2] == 2:
        whn[0] = min(whn[0], xya[0])
    elif xya[2] == 3:
        y = max(y, xya[1])
    else:
        whn[1] = min(whn[1], xya[1])
    if x >= whn[0] or y >= whn[1]:
        print(0)
        flag += 1
        break
        
if flag == 0:
    print((whn[0]-x)*(whn[1]-y))

Submission status: Accepted

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

print(sum(W)*sum(H))

Submission status: Accepted

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

space=[[0 for _ in range(H)] for __ in range(W)]
for point in points:
    if point[2]==1:
        for i in range(W):
            for j in range(H):
                if i<point[0]:
                    space[i][j]=1
    elif point[2]==2:
        for i in range(W):
            for j in range(H):
                if i>=point[0]:
                    space[i][j]=1
    elif point[2]==3:
        for i in range(W):
            for j in range(H):
                if j<point[1]:
                    space[i][j]=1
    elif point[2]==4:
        for i in range(W):
            for j in range(H):
                if j>=point[1]:
                    space[i][j]=1

count=0

for i in range(W):
    for j in range(H):
        if space[i][j]==0:
            count+=1
print(count)

Submission status: Accepted

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

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

dp = [[0] * W for i in range(H)]

for i in range(N):
    if L[i][2] == 1:
        for y in range(H):
            for x in range(L[i][0]):
                dp[y][x] = 1
                
    elif L[i][2] == 2:
        for y in range(H):
            for x in range(L[i][0], W):
                dp[y][x] = 1
                
    elif L[i][2] == 3:
        for y in range(L[i][1]):
            for x in range(W):
                dp[y][x] = 1
                
    else:
        for y in range(L[i][1], H):
            for x in range(W):
                dp[y][x] = 1
                

res = 0

for x in range(W):
    for y in range(H):
        if dp[y][x] == 0:
            res += 1
        
print(res)

Submission status: Accepted

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

if cx[0] >= cx[1] or cy[0] >= cy[1]:
    print(0)
else:
    print((cx[1]-cx[0])*(cy[1]-cy[0]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
l=[]
x=W
y=H
max1=0
max2=0
max3=W
max4=H
for i in range(N):
     x1,y1,z=map(int,input().split())
     ls=[]
     ls.append(x1)
     ls.append(y1)
     ls.append(z)
     l.append(ls)
for i in l:
     if i[2]==1:
          c=i[0]
          if c>max1:
               x-=c-max1
               max1=c
     elif i[2]==2:
          a=i[0]
          if a<max3:
               x-=max3-a
               max3=a
     elif i[2]==3:
          b=i[1]
          if b>max2:
               y-=b-max2
               max2=b
     elif i[2]==4:
          d=i[1]
          if d<max4:
               y-=max4-d
               max4=d
if y<=0 or x<=0:
     print('0')
else:
     print(x*y)

Submission status: Accepted

Solution code:
W, H, N = [int(i) for i in input().split()]
Map = [ [1 for _ in range(H)] for _ in range(W) ]
for _ in range(N):
    x, y, a = [int(i) for i in input().split()]
    if a == 1:
        for i in range(x):
            for j in range(H):
                Map[i][j] = 0
    elif a == 2:
        for i in range(x, W):
            for j in range(H):
                Map[i][j] = 0
    elif a == 3:
        for i in range(W):
            for j in range(y):
                Map[i][j] = 0
    elif a == 4:
        for i in range(W):
            for j in range(y, H):
                Map[i][j] = 0
#for y in range(H, 0, -1):
#   for x in range(W):
#       print(Map[x][y-1], end="")
#   print()
print(sum([sum(i) for i in Map]))

Submission status: Accepted

Solution code:
import numpy
I=lambda:map(int,input().split())
W,H,N=I()
m=numpy.zeros((H,W),int)
while N:x,y,a=I();m[y*(a>3):H*(a^3)or y,x*(a==2):W*~-a or x]=1;N-=1
print(W*H-m.sum())

Submission status: Accepted

Solution code:
from numpy import*;I=lambda:map(int,input().split());W,H,N=I();m=zeros((H,W),int)
while N:x,y,a=I();m[y*(a>3):H*(a^3)or y,x*(a==2):W*~-a or x]=1;N-=1
print(W*H-m.sum())

Submission status: Accepted

Solution code:
import numpy;I=lambda:map(int,input().split());W,H,N=I();m=numpy.zeros((H,W),int)
while N:x,y,a=I();m[y*(a>3):H*(a^3)or y,x*(a==2):W*~-a or x]=1;N-=1
print(W*H-m.sum())

Submission status: Accepted

Solution code:
from numpy import*;I=lambda:map(int,input().split());W,H,N=I();m=zeros((H,W),int)
for _ in[0]*N:x,y,a=I();m[y*(a>3):H*(a^3)or y,x*(a==2):W*~-a or x]=1
print(W*H-m.sum())

Submission status: Accepted

Solution code:
from numpy import*;I=lambda:map(int,input().split());W,H,N=I();m=zeros((H,W))
for _ in[0]*N:x,y,a=I();m[y*(a>3):H*(a^3)or y,x*(a==2):W*~-a or x]=1
print(W*H-int(sum(m)))

Submission status: Accepted

Solution code:
from numpy import*;I=lambda:map(int,input().split());W,H,N=I();m=zeros((H,W))
for i in range(N):x,y,a=I();m[y*(a>3):H*(a^3)or y,x*(a==2):W*~-a or x]=1
print(W*H-int(sum(m)))

Submission status: Accepted

Solution code:
from numpy import*;I=lambda:map(int,input().split());W,H,N=I();m=zeros((H,W))
for i in range(N):x,y,a=I();m[y*(a>3):H*(a!=3)or y,x*(a==2):W*~-a or x]=1
print(W*H-int(sum(m)))

Submission status: Accepted

Solution code:
from numpy import*;I=lambda:map(int,input().split());W,H,N=I();m=zeros((H,W))
for i in range(N):x,y,a=I();m[y*(a>3):y*(a==3or H),x*(a==2):x*(a<2or W)]=1
print(W*H-int(sum(m)))

Submission status: Accepted

Solution code:
# シミュレーション問題

def paint_gt_x(area, threhsold):
    for y in range(len(area)):
        for x in range(len(area[y])):
            if x < threhsold:
                area[y][x] = 1

def paint_lt_x(area, threhsold):
    for y in range(len(area)):
        for x in range(len(area[y])):
            if x > threhsold:
                area[y][x] = 1

def paint_gt_y(area, threhsold):
    for y in range(len(area)):
        for x in range(len(area[y])):
            if y < threhsold:
                area[y][x] = 1

def paint_lt_y(area, threhsold):
    for y in range(len(area)):
        for x in range(len(area[y])):
            if y > threhsold:
                area[y][x] = 1


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

area = []
for _ in range(h):
    area.append([0 for _ in range(w)])

for _ in range(n):
    (x, y, a) = map(int, input().split())
    if 1 == a:
        paint_gt_x(area, x)
    elif 2 == a:
        paint_lt_x(area, x - 1)
    elif 3 == a:
        paint_gt_y(area, y)
    else:
        paint_lt_y(area, y - 1)

count = 0
for row in area:
    for cell in row:
        count += 1 if 0 == cell else 0
print(count)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


w, h, n = LI()
A = [0] * 4
A[1] = w
A[3] = h
for _ in range(n):
    x, y, a = LI()
    a -= 1
    if a == 0:
        A[a] = max(A[a], x)
    elif a == 1:
        A[a] = min(A[a], x)
    elif a == 2:
        A[a] = max(A[a], y)
    else:
        A[a] = min(A[a], y)

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

Submission status: Accepted

Solution code:
w, h, n = map(int,  input().split())
W = [0, w]
H = [0, h]

for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1 and x > W[0]:
        W[0] = x
    if a == 2 and x < W[1]:
        W[1] = x
    if a == 3 and y > H[0]:
        H[0] = y
    if a == 4 and y < H[1]:
        H[1] = y
        
if W[0] > W[1] or H[0] > H[1]:
    print(0)
else:
    print((W[1] - W[0]) * (H[1] - H[0]))

Submission status: Accepted

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

for _ in range(n):
    *a, = map(int, input().split())
    s = int((a[2] % 2 - 0.5)*2)
    b[a[2]-1] = s*max(s*a[a[2]//3], s*b[a[2]-1])
print(max((b[1]-b[0]), 0)*max((b[3]-b[2]), 0))

Submission status: Accepted

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

Submission status: Accepted

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

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

    if a==1:
        s,t=range(h),range(x)
    elif a==2:
        s,t=range(h),range(x,w)
    elif a==3:
        s,t=range(y),range(w)
    elif a==4:
        s,t=range(y,h),range(w)

    for i in s:
        for j in t:
            l[i][j]=True

print(h*w-sum(map(sum,l)))

Submission status: Accepted

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

print(max(0, w - x0) * max(0, h - y0))

Submission status: Accepted

Solution code:
import numpy as np

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

for _ in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        wh[:,:x]=0
    if a==2:
        wh[:,x:]=0
    if a==3:
        wh[:y,:]=0
    if a==4:
        wh[y:,:]=0
print(int(np.sum(wh)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
x = [0]*N
y = [0]*N
a = [0]*N
Xmin = -1
Xmax = W+1
Ymin = -1
Ymax = H+1
for i in range(0,N):
	x[i],y[i],a[i] = map(int,input().split())
	if a[i] == 1 and Xmin < x[i]:
		Xmin = x[i]
	if a[i] == 2 and Xmax > x[i]:
		Xmax = x[i]
	if a[i] == 3 and Ymin < y[i]:
		Ymin = y[i]
	if a[i] == 4 and Ymax > y[i]:
		Ymax = y[i]

ans = 0

if Xmin == -1:
	Xmin = 0
if Xmax == W+1:
	Xmax = W
if Ymin == -1:
	Ymin = 0
if Ymax == H+1:
	Ymax = H
ans = (Xmax-Xmin)*(Ymax-Ymin)
if Xmin > Xmax or Ymin > Ymax:
	ans = 0
print(ans)

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
x = [0] * N
y = [0] * N
a = [0] * N
lx = 0
ly = 0
rx = W
ry = H

for i in range(N):
    x[i], y[i], a[i] = map(int, input().split())
    if a[i] == 1:
        if lx < x[i]:
            lx = x[i]
    elif a[i] == 2:
        if x[i] < rx:
            rx = x[i]
    elif a[i] == 3:
        if ly < y[i]:
            ly = y[i]
    else:
        if y[i] < ry:
            ry = y[i]

if lx >= rx or ly >= ry:
    print(0)
else:
    print((rx - lx) * (ry - ly))

Submission status: Accepted

Solution code:
def execute(w, h, n, xya):
    s = [[1 for _ in range(w)] for _ in range(h)]
    for x, y, a in xya:
        for xi in range(w):
            for yi in range(h):
                if a == 1:
                    if xi < x:
                        s[yi][xi] = 0
                if a == 2:
                    if xi >= x:
                        s[yi][xi] = 0
                if a == 3:
                    if yi < y:
                        s[yi][xi] = 0
                if a == 4:
                    if yi >= y:
                        s[yi][xi] = 0
    return sum(map(sum, s))


if __name__ == '__main__':
    w, h, n = map(int, input().split())
    xya = []
    for _ in range(n):
        xya.append(list(map(int, input().split())))
    print(execute(w, h, n, xya))

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
s=[0,w,0,h]
for i in range(n):
    p=list(map(int,input().split()))
    if p[2]==1 or p[2]==3:
        s[p[2]-1]=max(p[p[2]//2],s[p[2]-1])
    else:
        s[p[2]-1]=min(p[p[2]//2-1],s[p[2]-1])
print(max(s[1]-s[0],0)*max(s[3]-s[2],0))

Submission status: Accepted

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

x1 = []
x2 = []
y3 = []
y4 = []

for _ in range(N):
  x, y, a = map(int, input().split())
  if a == 1:
    x1.append(x)
  elif a == 2:
    x2.append(x)
  elif a == 3:
    y3.append(y)
  else:
    y4.append(y)

if not x1:
  if not x2:
    W = W
  else:
    W = min(x2)
elif not x2:
  W -= max(x1)
elif max(x1) >= min(x2):
  W = 0
else:
  W = min(x2) - max(x1)

if not y3:
  if not y4:
    H = H
  else:
    H = min(y4)
elif not y4:
  H -= max(y3)
elif max(y3) >= min(y4):
  H = 0
else:
  H = min(y4) - max(y3)
  
print(W*H)

Submission status: Accepted

Solution code:
# B
def zeros(n): return [0 for i in range(n)]
W, H, N = [int(x) for x in input().split()]
white = [[0,0],[W,H]]
#x, y, a = zeros(N), zeros(N), zeros(N)
for i in range(N):
    #x[i], y[i], a[i] = [int(x) for x in input().split()]
    x, y, a = [int(x) for x in input().split()]
    #print(x,y,a)#
    if a==1: white[0][0] = max(white[0][0], x)
    elif a==2: white[1][0] = min(white[1][0], x)
    elif a==3: white[0][1] = max(white[0][1], y)
    elif a==4: white[1][1] = min(white[1][1], y)
    else: print('error')
    #print(white)#
    
print(max(white[1][0]-white[0][0], 0)*max(white[1][1]-white[0][1], 0))