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 numpy as np

W,H,N = map(int,input().split())
l = np.zeros((H,W)) #	要素0のH×W配列

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

  if a==1:
    l[:,:x] = 1
    #print(l[:,x:])
  elif a==2:
    l[:,x:] = 1
  elif a==3:
    l[:y,:] = 1
  elif a==4:
    l[y:,:] = 1
#print(H*W-int(l.sum().sum()))
print(H*W-int(l.sum()))

Submission status: Accepted

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

count = 0
for i in field:
    count += i.count(1)
print(count)

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
l = [[0] * w for i in range(h)]
z = [list(map(int,input().split())) for i in range(n)]
x,y,a = [list(i) for i in zip(*z)]

for i in range(n):
    if a[i] == 1:
        for j in range(h):
            for k in range(x[i]):
                l[j][k] = 1
    if a[i] == 2:
        for j in range(h):
            for k in range(x[i],w):
                l[j][k] = 1
    if a[i] == 3:
        for j in range(y[i]):
            for k in range(w):
                l[j][k] = 1
    if a[i] == 4:
        for j in range(y[i],h):
            for k in range(w):
                l[j][k] = 1

t = 0
for i in range(h):
    t += l[i].count(0)

print(t)

Submission status: Accepted

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

o,p,q,r = 0,0,0,0
for _ in range(n):
  x,y,a = map(int, input().split())
  if a == 1: o = max(o,x)
  elif a == 2: p = max(p,w-x)
  elif a == 3: q = max(q, y)
  elif a == 4: r = max(r,h-y)

w -= o+p
h -= q+r
if w > 0 and h > 0: print(w*h)
else: print(0)

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
a=[]
b=[]
c=[]
d=[]
for _ in range(N):
  x=list(map(int,input().split()))
  if x[2]==1:
    a.append(x)
  elif x[2]==2:
    b.append(x)
  elif x[2]==3:
    c.append(x)
  else:
    d.append(x)
a.sort()
b.sort()
c.sort(key=lambda x:x[1])
d.sort(key=lambda x:x[1])
ans=W*H
e,f=W,H
if len(a)!=0:
  if len(b)!=0:
    if b[0][0]<a[-1][0]:
      print(0)
      exit()
    e=b[0][0]-a[-1][0]
  else:
    e-=a[-1][0]
else:
  if len(b)!=0:
    e=b[0][0]
if len(c)!=0:
  if len(d)!=0:
    if d[0][1]<c[-1][1]:
      print(0)
      exit()
    f=d[0][1]-c[-1][1]
  else:
    f-=c[-1][1]
else:
  if len(d)!=0:
    f=d[0][1]
print(e*f)

Submission status: Accepted

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

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

ans=(x_mx-x_mn)*(y_mx-y_mn)
if x_mx-x_mn<=0 or y_mx-y_mn<=0:
    ans=0
print(max(ans,0))

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
W, H, N = map(int,input().split())
x = 0
y = 0
a = 0
X = []
Y = []
A = []
for i in range(N):
    x, y, a = map(int,input().split())
    X.append(x)
    Y.append(y)
    A.append(a)
P = [[0 for i in range(W)] for j in range(H)]
for i in range(N):
    if A[i] == 1:
        for j in range(X[i]):
            for k in range(H):
                P[k][j] = 1
    elif A[i] == 2:
        for j in range(X[i],W):
            for k in range(H):
                P[k][j] = 1
    elif A[i] == 3:
        for j in range(Y[i]):
            for k in range(W):
                P[j][k] = 1
    elif A[i] == 4:
        for j in range(Y[i],H):
            for k in range(W):
                P[j][k] = 1
ans = 0
for i in range(W):
    for j in range(H):
        if P[j][i] == 0:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
w, h, n = map(int, input().split())
xya = [map(int, input().split()) for _ in range(n)]
x, y, a = [list(i) for i in zip(*xya)]

arr = [[0] * w for i in range(h)]

for i in range(n):
    if a[i] == 1:
        for j in range(h):
            for k in range(x[i]):
                arr[j][k] = 1
    
    elif a[i] == 2:
        for j in range(h):
            for k in range(x[i], w):
                arr[j][k] = 1

    elif a[i] == 3:
        for j in range(y[i]):
            arr[j] = [1 for _ in arr[j]]

    elif a[i] == 4:
        for j in range(y[i], h):
            arr[j] = [1 for _ in arr[j]]

ans = 0
for s in arr:
    ans += s.count(0)

print(ans)

Submission status: Accepted

Solution code:
# Problem: https://atcoder.jp/contests/abc047/tasks/abc047_b
# Python 3rd Try

import sys
# import pprint
# from collections import defaultdict
# import heapq,copy
# from collections import deque
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solver(WIDTH, HEIGHT, OPERATION):
    result = 0
    all_ope = len(OPERATION)
    up_max = HEIGHT
    left_min = 0
    right_max = WIDTH
    down_min = 0
    for j in range(0, all_ope, +1):
        each_ope = OPERATION[j]
        ope = each_ope[2]
        if ope == 1:
            if left_min < each_ope[0]:
                left_min = each_ope[0]
        if ope == 2:
            if each_ope[0] < right_max:
                right_max = each_ope[0]
        if ope == 3:
            if down_min < each_ope[1]:
                down_min = each_ope[1]
        if ope == 4:
            if each_ope[1] < up_max:
                up_max = each_ope[1]
    if ((left_min < right_max) and (down_min < up_max)):
        result = (right_max-left_min) * (up_max - down_min)
    return result


if __name__ == "__main__":

    W, H, N = MI()
    OPE = list()
    for _ in range(0, N, +1):
        OPE.append(LI())
    print("{}".format(solver(W, H, OPE)))

Submission status: Accepted

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

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

  x1=x if a==1 else -1
  x2=x if a==2 else w+1
  y1=y if a==3 else -1
  y2=y if a==4 else h+1
  for k in range(w):
    for j in range(h):
     
      if k<x1:
        l[j][k]=0
      if k>=x2:
        l[j][k]=0
      if j<y1:
        l[j][k]=0
      if j>=y2:
        l[j][k]=0
print(sum([sum(v) for v in l]))

Submission status: Accepted

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

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


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    W, H, N = il()
    w, h = 0, 0
    for _ in range(N):
        x, y, a = il()
        if a == 1 and w <= x:
            w = x
        if a == 2 and W >= x:
            W = x
        if a == 3 and h <= y:
            h = y
        if a == 4 and H >= y:
            H = y

    if h >= H or w >= W:
        print(0)
    else:
        print((H - h) * (W - w))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

for _ in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        x1 = max(x1, x)
    elif a == 2:
        x2 = min(x2, x)
    elif a == 3:
        y1 = max(y1, y)
    else:
        y2 = min(y2, y)

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

Submission status: Accepted

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

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

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

    if a == 1:
        x0 = max(x,x0)
    elif a == 2:
        x1 = min(x,x1)
    elif a == 3:
        y0 = max(y,y0)
    elif a == 4:
        y1 = min(y,y1)
X = [x0,x1,y0,y1]

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

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
x=[]
y=[]
a=[]
for i in range(n):
    xya=list(map(int,input().split()))
    x.append(xya[0])
    y.append(xya[1])
    a.append(xya[2])

top,bottom,left,right=h,0,0,w

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

if (top-bottom)<=0 or (right-left)<=0:
    ans=0
else:
    ans=(right-left)*(top-bottom)
print(ans)

Submission status: Accepted

Solution code:
(w, h, n) = map(int, input().split())
(x, y, a) = zip(*[map(int, input().split()) for _ in range(n)])

x_min = 0
x_max = w
y_min = 0
y_max = h

for i in range(n):
    if a[i] == 1:
        x_min = max(x_min, x[i])
    elif a[i] == 2:
        x_max = min(x_max, x[i])
    elif a[i] == 3:
        y_min = max(y_min, y[i])
    else:
        y_max = min(y_max, y[i])

if x_max > x_min:
    x_delta = x_max - x_min
else:
    x_delta = 0
if y_max > y_min:
    y_delta = y_max - y_min
else:
    y_delta = 0
print(x_delta * y_delta)

Submission status: Accepted

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

#print(W,H,N)
#print(lst)
#lst = sorted(lst, key=lambda x: x[2])
#print(lst)
Wst = [1]*W
Hst = [1]*H
for i in range(N):
    if lst[i][2] == 1:
        for j in range(lst[i][0]):
            Wst[j] = 0
    if lst[i][2] == 2:
        #print(lst[i][0],W)
        for j in range(lst[i][0],W):
            Wst[j] = 0
    if lst[i][2] == 3:
        for j in range(lst[i][1]):
            Hst[j] = 0
    if lst[i][2] == 4:
        #print(lst[i][0],W)
        for j in range(lst[i][1],H):
            Hst[j] = 0
    
#print(Wst,Hst)
print(sum(Wst)*sum(Hst))

Submission status: Accepted

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

ans = 0
for i in range(H):
    for j in range(W):
        ans += grid[i][j]
print(H * W - ans)

Submission status: Accepted

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

area = []
area_w = []
for h in range(H):
    for w in range(W):
        area_w.append(0)
    area.append(area_w)
    area_w = []

for n in range(N):
    X,Y,a = map(int, input().split(' '))
    if a == 1:
        for h in range(H):
            for x in range(X):
                area[h][x] = 1
    elif a == 2:
        for h in range(H):
            for x in range(X,W):
                area[h][x] = 1 
    elif a == 3:
        for y in range(Y):
            for w in range(W):
                area[y][w] = 1
    else:
        for y in range(Y,H):
            for w in range(W):
                area[y][w] = 1
sum_area = 0
for h in range(H):
    sum_area += sum(area[h])

ans = H*W - sum_area
print(ans)

Submission status: Accepted

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

ans = [[1] * H for i in range(W)]

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

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
W,H,N = readInts()
field = [[False] * W for _ in range(H)]

def fill(sy,sx,gy,gx):
    cnt = 0
    for y in range(sy,gy):
        for x in range(sx,gx):
            if field[y][x]:
                continue
            else:
                field[y][x] = True
                #print(y,x)
                cnt += 1
    return cnt
ans = 0
for i in range(N):
    x,y,a = readInts()
    if a == 1:
        ans += fill(0,0,H,x)
    elif a == 2:
        ans += fill(0,x,H,W)
    elif a == 3:
        ans += fill(0,0,y,W)
    else:
        ans += fill(y,0,H,W)
    #print(ans)
print(H*W - ans)

Submission status: Accepted

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

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

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)
if minx > maxx or miny > maxy:
    print(0)
else:
    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

w,h,n=MI()
xmx=w
ymx=h
xmn=0
ymn=0
for i in range(n):
    x,y,a=MI()
    if a==2:
        xmx=min(x,xmx)
    if a==1:
        xmn=max(x,xmn)
    if a==4:
        ymx=min(y,ymx)
    if a==3:
        ymn=max(y,ymn)
    #print(xmn,xmx,ymn,ymx)
print(max(xmx-xmn,0)*max(ymx-ymn,0))

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
xl = 0
xh = W
yl = 0
yh = H
for _ in range(N):
    x,y,a = map(int,input().split())
    if a==1:
        xl = max(xl,x)
    elif a==2:
        xh = min(xh,x)
    elif a==3:
        yl = max(yl,y)
    elif a==4:
        yh = min(yh,y)
dx = max(0,xh-xl)
dy = max(0,yh-yl)
print(dx*dy)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

W, H, N = inm()


def solve():
    xl = 0
    xr = W
    yb = 0
    yt = H
    for _ in range(N):
        x, y, a = inm()
        if a == 1:
            xl = min(max(xl, x), xr)
        elif a == 2:
            xr = max(min(xr, x), xl)
        elif a == 3:
            yb = min(max(yb, y), yt)
        else:
            assert a == 4
            yt = max(min(yt, y), yb)
    return (yt - yb) * (xr - xl)


print(solve())

Submission status: Accepted

Solution code:
def coloring():
    line = input()
    words = line.split()
    W = int(words[0])
    H = int(words[1])
    N = int(words[2])

    x = 0
    y = 0
    w = W
    h = H

    grid = []

    for i in range(h):
        for j in range(w):
            grid.append(0)

    for i in range(N):
        s = input()
        ws = s.split()
        x = int(ws[0])
        y = int(ws[1])
        a = int(ws[2])
        if a == 1:
            #rect = x * whole
            for i in range(h):
                for j in range(x):
                    grid[j + w * i] = 1

        if a == 2:
            #rect = (w - x) * whole
            for i in range(h):
                for j in range(x,w):
                    grid[j + w*i] = 1

        if a==3:
            #rect = whole * y
            for i in range(y):
                for j in range(w):
                    grid[j + w * i] = 1
        
        if a == 4:
            #rect = whole * (h - y)
            for i in range(y,h):
                for j in range(w):
                    grid[j + w*i] = 1

        
    print(grid.count(0))


coloring()

Submission status: Accepted

Solution code:
import bisect,copy,heapq,string
from collections import *
from math import *
from itertools import *
import sys
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

w, h, n = MAP()
a = [LIST() for i in range(n)]
x0 = 0
x1 = w
y0 = 0
y1 = h

for i in range(n):
        if a[i][2] == 1:
                x0 = max(x0, a[i][0])
        elif a[i][2] == 2:
                x1 = min(x1, a[i][0])
        elif a[i][2] == 3:
                y0 = max(y0, a[i][1])
        elif a[i][2] == 4:
                y1 = min(y1, a[i][1])

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

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
sq=[[1 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 X in range(0,x):
            for Y in range(H):
                sq[Y][X]=0
    if a==2:
        for X in range(x,W):
            for Y in range(H):
                sq[Y][X]=0
    if a==3:
        for X in range(W):
            for Y in range(0,y):
                sq[Y][X]=0
    if a==4:
        for X in range(W):
            for Y in range(y,H):
                sq[Y][X]=0

ans=0
for k in range(H):
    ans+=sum(sq[k])
print(ans)

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
ans_list = [0,0,w,h]
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1 and ans_list[0]<x:
        ans_list[0] = x
    elif a == 2 and ans_list[2]>x:
        ans_list[2] = x
    elif a == 3 and ans_list[1]<y:
        ans_list[1] = y
    elif a == 4 and ans_list[3]>y:
        ans_list[3] = y
    ans = (ans_list[2]-ans_list[0])*(ans_list[3]-ans_list[1])
    if ans <= 0:
        print(0)
        exit()
print(ans)

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
a,b,c,d=0,W,0,H

for i in range(N):
  x,y,A=map(int,input().split())
  if A==1:
    a=max(a,x)
  if A==2:
    b=min(b,x)
  if A==3:
    c=max(c,y)
  if A==4:
    d=min(d,y)
  
print(max(0,b-a)*max(0,d-c))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    W, H, N = mi()
    p = [[0]*W for _ in range(H)]
    for i in range(N):
        xi, yi, ai = mi()
        if ai == 1:
            for x in range(xi):
                for y in range(H):
                    p[y][x] = 1
        if ai == 2:
            for x in range(xi, W):
                for y in range(H):
                    p[y][x] = 1
        if ai == 3:
            for x in range(W):
                for y in range(yi):
                    p[y][x] = 1
        if ai == 4:
            for x in range(W):
                for y in range(yi, H):
                    p[y][x] = 1
    print(W*H-sum(sum(p[i]) for i in range(H)))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(n):
  x, y, a = map(int, input().split())
  if a == 1:
    if num_w < x:
      num_w = x
  elif a == 2:
    if w > x:
      w = x
  elif a == 3:
    if num_h < y:
      num_h = y
  else:
    if h > y:
      h = y
      
cnt_w = w-num_w
cnt_h = h-num_h

if cnt_w < 0 or cnt_h < 0:
  print(0)
else:
  print(cnt_w*cnt_h)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
w,h,n=map(int, input().split())
x=[]
y=[]
a=[]
for i in range(n):
  s=input().split()
  x.append(int(s[0]))
  y.append(int(s[1]))
  a.append(int(s[2]))
x_l=0
x_h=w
y_l=0
y_h=h
for i in range(n):
  if a[i]==1:
    if x_l<x[i]:
      x_l=x[i]
  elif a[i]==2:
    if x_h>x[i]:
      x_h=x[i]
  elif a[i]==3:
    if y_l<y[i]:
      y_l=y[i]
  else:
    if y_h>y[i]:
      y_h=y[i]
if x_h>x_l and y_h>y_l:
  print((x_h-x_l)*(y_h-y_l))
else:
  print("0")

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
w = W*[1]
h = H*[1]

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

print(w.count(1)*h.count(1))

Submission status: Accepted

Solution code:
# Problem: https://atcoder.jp/contests/abc047/tasks/abc047_b
# Python 2nd Try

import sys
# from collections import defaultdict
# import heapq,copy
# from collections import deque
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solver(Width, Height, op_count, x_list, y_list, op_list):
    result = 0
    x_label_max = Width
    x_label_min = 0
    y_label_max = Height
    y_label_min = 0
    for j in range(0, op_count):
        real_ope = op_list[j]
        if real_ope == 1:
            x_label_min = max(x_list[j], x_label_min)
        if real_ope == 2:
            x_label_max = min(x_list[j], x_label_max)
        if real_ope == 3:
            y_label_min = max(y_list[j], y_label_min)
        if real_ope == 4:
            y_label_max = min(y_list[j], y_label_max)
    resultWidth = x_label_max - x_label_min
    resultHeight = y_label_max - y_label_min
    if resultWidth < 0:
        resultWidth = 0
    if resultHeight < 0:
        resultHeight = 0
    result = resultWidth * resultHeight
    return result


if __name__ == "__main__":
    W, H, N = MI()
    x_list = list()
    y_list = list()
    op_list = list()
    for _ in range(0, N, +1):
        tmp_x, tmp_y, tmp_op = MI()
        x_list.append(tmp_x)
        y_list.append(tmp_y)
        op_list.append(tmp_op)
    print("{}".format(solver(W, H, N, x_list, y_list, op_list)))

Submission status: Accepted

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

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

wn = 0
hn = 0

for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1 and wn < x:
        wn = x
    elif a == 2 and w > x:
        w = x        
    elif a == 3 and hn < y:
        hn = y
    elif a == 4 and h > y:
        h = y

if (w - wn) > 0 and (h - hn) > 0:
    print((w - wn) * (h - hn))
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    W,H,N = map(int,input().split())
    lx,rx,ly,ry = 0,W,0,H
    for _ in range(N):
        x,y,a = map(int,input().split())
        if a == 1:
            lx = max(lx,x)
        elif a == 2:
            rx = min(rx,x)
        elif a == 3:
            ly = max(ly,y)
        else:
            ry = min(ry,y)
    ans = max(0,rx - lx) * max(0,ry - ly)
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
lists = [list(map(int,input().split())) for i in range(n)]
plx = 0
ply = 0
prx = w
pry = h
for x,y,a in lists:
    if a == 1:
        if plx < x:
            plx = x
    elif a == 2:
        if prx > x:
            prx = x
    elif a == 3:
        if ply < y:
            ply = y
    elif a == 4:
        if pry > y:
            pry = y
px = (prx - plx)
if px < 0:
    px = 0
py = (pry - ply)
if py < 0:
    py = 0
ans = px * py
if ans < 0:
    ans = 0
print(ans)

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
lists = [list(map(int,input().split())) for i in range(n)]
x1 = 0
x2 = w
y1 = 0
y2 = h
for x,y,a in lists:
    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)
x = max(0,(x2 - x1))
y = max(0,(y2 - y1))
ans = max(0,x*y)
print(ans)

Submission status: Accepted

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