Problem:


Score : 200 points

Problem Statement

There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white.

Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i).

Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows:

If a_i = 1, he painted the region satisfying x < x_i within the rectangle.

If a_i = 2, he painted the region satisfying x > x_i within the rectangle.

If a_i = 3, he painted the region satisfying y < y_i within the rectangle.

If a_i = 4, he painted the region satisfying y > y_i within the rectangle.

Find the area of the white region within the rectangle after he finished painting.

Constraints

1 ≦ W, H ≦ 100

1 ≦ N ≦ 100

0 ≦ x_i ≦ W (1 ≦ i ≦ N)

0 ≦ y_i ≦ H (1 ≦ i ≦ N)

W, H (21:32, added), x_i and y_i are integers.

a_i (1 ≦ i ≦ N) is 1, 2, 3 or 4.

Input

The input is given from Standard Input in the following format:

W H N
x_1 y_1 a_1
x_2 y_2 a_2
:
x_N y_N a_N

Output

Print the area of the white region within the rectangle after Snuke finished painting.

Sample Input 1

5 4 2
2 1 1
3 3 4

Sample Output 1

9

The figure below shows the rectangle before Snuke starts painting.

First, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x < 2 within the rectangle:

Then, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y > 3 within the rectangle:

Now, the area of the white region within the rectangle is 9.

Sample Input 2

5 4 3
2 1 1
3 3 4
1 4 2

Sample Output 2

0

It is possible that the whole region within the rectangle is painted black.

Sample Input 3

10 10 5
1 6 1
4 1 3
6 9 4
9 4 2
3 1 3

Sample Output 3

64



Sample input:
5 4 2
2 1 1
3 3 4


Sample output:
9

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *

W, H, N = MAP()
 
dict = defaultdict(int)
dict[1] = 0
dict[2] = W
dict[3] = 0
dict[4] = H
 
for _ in range(N):
	x, y, a = MAP()
	if a == 1:
		dict[1] = max(x, dict[1])
	elif a == 2:
		dict[2] = min(x, dict[2])
	elif a == 3:
		dict[3] = max(y, dict[3])
	elif a == 4:
		dict[4] = min(y, dict[4])
 
if dict[2]-dict[1] < 0 or dict[4]-dict[3] < 0:
	print(0)
else:
	print(max(0, (dict[2]-dict[1])*(dict[4]-dict[3])))

Submission status: Accepted

Solution code:
import math
import fractions
#import sys
#input = sys.stdin.readline

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ZipArray(a):
    aa = [[a[i],i]for i in range(n)]

    aa.sort(key = lambda x : x[0])
    for i in range(n):
        aa[i][0]=i+1
    aa.sort(key = lambda x : x[1])
    b=[aa[i][0] for i in range(len(a))]
    return b

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

def Zeros(a,b):
    if(b<=-1):
        return [0 for i in range(a)]
    else:
        return [[0 for i in range(b)] for i in range(a)]

def AddV2(v,w):
    return [v[0]+w[0],v[1]+w[1]]

dir4 = [[1,0],[0,1],[-1,0],[0,-1]]


def clamp(x,y,z):
    return max(y,min(z,x))

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
            

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)


'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 2
N = 10 ** 6 + 2
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

'''

#a = list(map(int, input().split()))
#list(map(int, input().split()))

#################################################
#################################################
#################################################
#################################################


#4400



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

data = Zeros(h,w)

for i in range(n):
    q = list(map(int, input().split()))
    a,b,c,d = 0,w,0,h
    if(q[2]==1):
        b = q[0]
    elif(q[2]==2):
        a = q[0]
    elif(q[2]==3):
        d = q[1]
    elif(q[2]==4):
        c = q[1]
    for j in range(a,b):
        for k in range(c,d):
            data[k][j]=1
    #print(data)

print(w*h-sum([sum(data[j]) for j in range(h)]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
"""
N = list(map(int,input().split()))
S = [str(input()) for _ in range(N)]
S = [list(map(int,list(input()))) for _ in range(h)] 
print(*S,sep="")
"""

import sys
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()
inf = float("inf") # 無限

w,h,n = map(int,input().split())
field = [[True for i in range(w)] for j in range(h)]

def paint(start,end,rotate=False):
    if rotate:
        for i in range(start,end):
            field[i] = [False for i in range(w)]

    else:
        for line in field[:]:
            for i in range(start,end):
                line[i] = False
for _ in range(n):
    x,y,a = map(int,input().split())
    if a == 1:  #1
        paint(0,x)
    elif a == 2:#2
        paint(x,w)
    elif a == 3:#3
        paint(0,y,rotate=True)
    else:       #4
        paint(y,h,rotate=True)

count = 0
for li in field[:]:
    count += li.count(True)
print(count)

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
zahyo = [list(map(int, input().split())) for _ in range(N)]
grid = [["w" for __ in range(W)] for ___ in range(H)]


def paint(h=range(H), w=range(W)):
    for i in h:
        for j in w:
            grid[i][j] = "b"


for xya in zahyo:
    if xya[2] == 1:
        paint(w=range(xya[0]))
    elif xya[2] == 2:
        paint(w=range(xya[0], W))
    elif xya[2] == 3:
        paint(h=range(xya[1]))
    elif xya[2] == 4:
        paint(h=range(xya[1], H))
print(sum(grid, []).count("w"))

Submission status: Accepted

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

left = 0
right = w
upper = h
lower = 0

for i in range(n):
	x, y, a = [int(k) for k in input().split()]
	if a == 1 and left < x:
		left = x
	elif a == 2 and right > x:
		right = x
	elif a == 3 and lower < y:
		lower = y
	elif a == 4 and upper > y:
		upper = y

S = (right-left)*(upper-lower)
if right-left < 0 or upper-lower < 0:
	print(0)
else:
	print(S)

Submission status: Accepted

Solution code:
from sys import stdin
input = stdin.readline
import copy as cp
from collections import deque

def VI(N, init=0):
  return [init for _ in range(N)]
def VVI(N, M, init=0):
  return [[init for _ in range(M)] for _ in range(N)]

def VD(N, init=0.0):
  return [init for _ in range(N)]
def VVD(N, M, init=0.0):
  return [[init for _ in range(M)] for _ in range(N)]

def Decimal(x):
  print("{0:.10f}".format(x))

class Pair:
  def __init__(self, x=0, y=0):
    self.first = x
    self.second = y

  def __repr__(self):
    return '{0} {1}'.format(self.first, self.second)

  def __lt__(self, pi):
    return self.first < pi.second

def POW(x, n):
  ret = 1
  while n:
    if n&1:
      ret *= x
    x *= x
    n >>= 1
  return ret

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

grid = VVI(H, W)
for _ in range(N):
  x, y, a = map(int, input().rstrip().split())
  if a == 1:
    for xx in range(x):
      for yy in range(H):
        grid[yy][xx] = 1
  elif a == 2:
    for xx in range(x, W):
      for yy in range(H):
        grid[yy][xx] = 1
  elif a == 3:
    for xx in range(W):
      for yy in range(y):
        grid[yy][xx] = 1
  elif a == 4:
    for xx in range(W):
      for yy in range(y, H):
        grid[yy][xx] = 1

ans = 0
for xx in range(W):
  for yy in range(H):
    ans += grid[yy][xx]

ans = H*W-ans

print(ans)

Submission status: Accepted

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

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

print(max(h - b, 0)*max(w - l, 0))

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
import numpy as np

W, H, N = MAP()

w, h = np.zeros(W), np.zeros(H)

for _ in range(N):
	x, y, a = MAP()
	if a == 1:
		w[:x] = 1
	elif a == 2:
		w[x:] = 1
	elif a == 3:
		h[:y] = 1
	elif a == 4:
		h[y:] = 1

print(list(w).count(0) * list(h).count(0))

Submission status: Accepted

Solution code:
import numpy as np

W,H,N=map(int,input().split())
T=[list(map(int,input().split())) for i in range(1,N+1)]

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

for i in range(0,N):
    x,y,a=T[i]

    if a==1:
        result[:,:x]=1

    elif a==2:
        result[:,x:]=1

    elif a==3:
        result[:y,:]=1

    elif a==4:
        result[y:,:]=1
    
print(np.count_nonzero(result==0))

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
high = h
low = 0
left = 0
right = w


for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        left = max(left, x)
    elif a == 2:
        right = min(right, x)
    elif a == 3:
        low = max(low, y)
    else:
        high = min(high, y)

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

Submission status: Accepted

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

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

for i in range(N):
    if xya[i][2] == 1:
        x_max.append(xya[i][0])
    if xya[i][2] == 2:
        x_min.append(xya[i][0])
    if xya[i][2] == 3:
        y_max.append(xya[i][1])
    if xya[i][2] == 4:
        y_min.append(xya[i][1])

x_1 = max(x_max)
x_2 = min(x_min)
y_3 = max(y_max)
y_4 = min(y_min)

if x_2 - x_1 > 0 and y_4 - y_3 > 0:
    print((x_2 - x_1) * (y_4 - y_3))
else :
    print(0)

Submission status: Accepted

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

Submission status: Accepted

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

left = 0
right = W
bottom = 0
top = H

for i in range(N):
  x, y, a = map(int, input().split())
  if a == 1:
    left = max(left, x)
  elif a == 2:
    right = min(right, x)
  elif a == 3:
    bottom = max(bottom, y)
  else:
    top = min(top, y)
    
print(max(0, (right-left)) * max(0, (top-bottom)))

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):
    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)
print(max(x2-x1,0)*max(y2-y1,0))

Submission status: Accepted

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

d = l = 0
u = h
r = w

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)

print(max(0, u - d) * max(0, r - l))

Submission status: Accepted

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

w0 = 0
h0 = 0

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

for i in c:
    if i[2] == 2:
        if i[0] < w:
            w = i[0]
    elif i[2] == 1:
        if i[0] > w0:
            w0 = i[0]
    elif i[2] == 4:
        if i[1] < h:
            h = i[1]
    elif i[2] == 3:
        if i[1] > h0:
            h0 = i[1]

w = w - w0 
if w < 0:
    w = 0
h = h - h0
if h < 0:
    h = 0
print(w*h)

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
x_r = W
x_l = 0
y_r = H
y_l = 0

for _ in range(N):
    x,y,a = map(int,input().split())
    if a == 1:
        x_l = max(x,x_l)
    elif a == 2:
        x_r = min(x,x_r)
    elif a == 3:
        y_l = max(y,y_l)
    else:
        y_r = min(y,y_r)


print(max(0,(x_r-x_l))*max(0,(y_r-y_l)))

Submission status: Accepted

Solution code:
def ABC_47_B():
    W,H,N = map(int, input().split())
    al=[]
    bl=[]
    cl=[]
    dl=[]

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

        if a == 1:
            al.append(x)
        elif a == 2:
            bl.append(x)
        elif a ==3:
            cl.append(y)
        else:
            dl.append(y)
    
    if len(al) != 0:
        at= max(al)
    else:
        at=0
    if len(bl) != 0:
        bt= min(bl)
    else:
        bt=W
    if len(cl) != 0:
        ct= max(cl)
    else:
        ct=0
    if len(dl) != 0:
        dt= min(dl)
    else:
        dt=H
    

    if (bt-at) >= 0 and (dt-ct) >=0:
        s = (bt-at)*(dt-ct)
    else:
        s = 0


    print(s)

if __name__ == '__main__':

    ABC_47_B()

Submission status: Accepted

Solution code:
W,H,N = map(int, input().split())
bottom = [0, 0]
top = [W,H]

for _ in range(N):
    x,y,a = map(int, input().split())
    if a==1:
        bottom[0] = max(bottom[0], x)
    elif a==2:
        top[0] = min(top[0], x)
    elif a==3:
        bottom[1] = max(bottom[1], y)
    elif a==4:
        top[1] = min(top[1], y)

print(max(0, top[0]-bottom[0])*max(0,top[1]-bottom[1]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
w, h, n = map(int, input().split())

field = np.ones([h, w], dtype=int)

for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        field[:, :x] = 0
    elif a == 2:
        field[:, x:] = 0
    elif a == 3:
        field[:y, :] = 0
    else:
        field[y:, :] = 0

print(field.sum())

Submission status: Accepted

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

mat=[[True]*H for _ in range(W)]
#print(mat)

for _ in range(N):
  x,y,a=map(int,input().split())
  if a==1:
    for i in range(x):
      for j in range(H):
        mat[i][j]=False
  elif a==2:
    for i in range(x,W):
      for j in range(H):
        mat[i][j]=False
  elif a==3:
    for i in range(W):
      for j in range(y):
        mat[i][j]=False
  elif a==4:
    for i in range(W):
      for j in range(y,H):
        mat[i][j]=False
#print(mat)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
grid = [[0] * W for _ in range(H)]
for _ in range(N):
    xi, yi, a = map(int, input().split())
    X = range(W)
    Y = range(H)
    if a in (1, 2):
        X = range(xi) if a == 1 else range(xi, W)
    elif a in (3, 4):
        Y = range(yi) if a == 3 else range(yi, H)
    for x in X:
        for y in Y:
            grid[y][x] |= 1
print(sum(map(lambda x: x.count(0), grid)))

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
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 SI(): return sys.stdin.readline()[:-1]

def main():
    w, h, n = MI()
    tt = [[1] * w for _ in range(h)]
    for _ in range(n):
        x, y, a = MI()
        if a == 1: i0, i1, j0, j1 = 0, h, 0, x
        if a == 2: i0, i1, j0, j1 = 0, h, x, w
        if a == 3: i0, i1, j0, j1 = 0, y, 0, w
        if a == 4: i0, i1, j0, j1 = y, h, 0, w
        for i in range(i0, i1):
            for j in range(j0, j1):
                tt[i][j] = 0
    ans=sum(sum(row) for row in tt)
    print(ans)

main()

Submission status: Accepted

Solution code:
from pprint import pprint
width, height, n = map(int, input().split())
rect = [[True for i in range(width)] for j in range(height)]
for i in range(n):
    x,y,a = map(int, input().split())
    if a == 1:
        for y_counter in range(height):
            x_counter = 0
            while x_counter < x:
                rect[y_counter][x_counter] = False
                x_counter += 1
    elif a == 2:
        for y_counter in range(height):
            x_counter = x
            while x_counter < width:
                rect[y_counter][x_counter] = False
                x_counter += 1
    elif a == 3:
        y_counter = 0
        while y_counter < y:
            for x_counter in range(width):
                rect[y_counter][x_counter] = False
            y_counter += 1
            
    elif a == 4:
        y_counter = y
        while y_counter < height:
            for x_counter in range(width):
                rect[y_counter][x_counter] = False
            y_counter += 1
count = 0
for i in rect:
    for j in i:
        if j == True:
            count += 1
print(count)

Submission status: Accepted

Solution code:
def main():
  n = list(map(int,input().split()))
  x_ans=[0,n[0]]
  y_ans=[0,n[1]] 
  x = [0] * n[2]
  y = [0] * n[2]
  t = [0] * n[2]
  for i in range(n[2]):
    x[i], y[i],t[i] = map(int, input().split())
  for i in range(0,n[2]):
    if t[i]==1 and x_ans[0]<x[i]:
      x_ans[0]=x[i]
    elif t[i]==2 and x[i]<x_ans[1]:
      x_ans[1]=x[i]
    elif t[i]==3 and y_ans[0]<y[i]:
      y_ans[0]=y[i]
    elif t[i]==4 and y[i]<y_ans[1]:
      y_ans[1]=y[i]
  if x_ans[0]>x_ans[1] or y_ans[0]>y_ans[1]:
    print(0)
  else:
    print((x_ans[1]-x_ans[0])*(y_ans[1]-y_ans[0]))
     
main()

Submission status: Accepted

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

for x,y,a in xya:
    if a==1:
        for i in range(x):
            for j in range(H):
                b[j][i]=1
    elif a==2:
        for i in range(x,W):
            for j in range(H):
                b[j][i]=1
    elif a==3:
        for i in range(y):
            for j in range(W):
                b[i][j]=1
    else:
        for i in range(y,H):
            for j in range(W):
                b[i][j]=1
res = H*W
for row in b:
    res -= sum(row)
print(res)

Submission status: Accepted

Solution code:
w, h, n = list(map(int, input().split()))
x_min, x_max, y_min, y_max = 0, w, 0, h
for _ in range(n):
    x, y, a = list(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)
if x_min >= x_max or y_min >= y_max:
    print(0)
else:
    print((x_max - x_min) * (y_max - y_min))

Submission status: Accepted

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

w1 = 0
w2 = w
h1 = 0
h2 = h
for x, y, a in xya:
    if a == 1:
        w1= max(w1, x)
    if a == 2:
        w2 = min(w2, x)
    if a == 3:
        h1 = max(h1, y)
    if a == 4:
        h2 = min(h2, y)
        
print(max(0, (w2-w1))*max(0, (h2-h1)))

Submission status: Accepted

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

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

for x, y, a in xya:
        for i in range(h):
             for j in range(w):
                    if a == 1 and j < x:
                        field[i][j] = 0
                    if a == 2 and j >= x:
                        field[i][j] = 0
                    if a == 3 and i < y:
                        field[i][j] = 0
                    if a == 4 and i >= y:
                        field[i][j] = 0

ans = 0
for i in field:
    ans += sum(i)
print(ans)

Submission status: Accepted

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

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

for x, y, a in xya:
        for i in range(h):
             for j in range(w):
                    if a == 1 and j < x:
                        field[i][j] = 0
                    if a == 2 and j >= x:
                        field[i][j] = 0
                    if a == 3 and i < y:
                        field[i][j] = 0
                    if a == 4 and i >= y:
                        field[i][j] = 0

print(sum(sum(np.array(field))))

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

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

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

W,H,N = IL()

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

for _ in range(N):
  x,y,t = IL()
  
  if t==1:
    for i in range(H):
      for j in range(x):
        l[i][j] = 0
  if t==2:
    for i in range(H):
      for j in range(W-x):
        l[i][W-1-j] = 0
  if t==4:
    for i in range(y,H):
      l[i] = [0]*W
  if t==3:
    for i in range(y):
      l[i] = [0]*W

P(sum(sum(l[i]) for i in range(H)))

Submission status: Accepted

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

d = [[0], [W], [0], [H]]

for x, y, a in xya:
    if a == 1 or a == 2:
        d[a-1] += [x]
    else:
        d[a-1] += [y]

if min(d[1]) - max(d[0]) > 0 and min(d[3]) - max(d[2]) > 0:
    ret = (min(d[1]) - max(d[0])) * ( min(d[3]) - max(d[2]))
    print(max(ret, 0))
else:
    print(0)

Submission status: Accepted

Solution code:
W,H,N = map(int, input().split())
l = 0
r = W
row = 0
up = H
for i in range(N):
    x,y,a = map(int, input().split())
    if a == 1:
        if x > l:
            l = x
    elif a == 2:
        if x < r:
            r = x
    elif a == 3:
        if y > row:
            row = y
    elif a == 4:
        if y < up:
            up = y
print(max(max((r-l),0)*max((up-row),0),0))

Submission status: Accepted

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

r = w
u = h
l = 0
b = 0

for z in xy:
    if z[2] == 1:
        l = max(l, z[0])
    elif z[2] == 2:
        r = min(r, z[0])
    elif z[2] == 3:
        b = max(b, z[1])
    elif z[2] == 4:
        u = min(u, z[1])

if (r-l) < 0 and (u-b) < 0:
    print(0)
else:
    print(max((r-l)*(u-b), 0))

Submission status: Accepted

Solution code:
w,h,n=map(int, input().split())
xl=0
xr=w
yd=0
yu=h
for _ in range(n):
    x,y,a=map(int, input().split( ))
    if a==1:
        xl=max(xl,x)
    elif a==2:
        xr=min(xr,x)
    elif a==3:
        yd=max(yd,y)
    else:
        yu=min(yu,y)
ans=max(xr-xl,0)*max(yu-yd,0)
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    W,H,N=map(int,input().split())
    c=[[1]*W for _ in range(H)]
    for _ in range(N):
        x,y,a=map(int,input().split())
        if a==1:
            for i in range(x):
                for j in range(H):
                    c[j][i]=0
        if a==2:
            for i in range(x,W):
                for j in range(H):
                    c[j][i]=0
        if a==3:
            for i in range(W):
                for j in range(y):
                    c[j][i]=0
        if a==4:
            for i in range(W):
                for j in range(y,H):
                    c[j][i]=0
    print(sum(sum(c,[])))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
S = [0,w,0,h] #[X1, X2, Y1, Y2]
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1 and S[0] < x:
        S[0] = x
    elif a == 2 and S[1] > x:
        S[1] = x
    elif a == 3 and S[2] < y:
        S[2] = y
    elif a == 4 and S[3] > y:
        S[3] = y
    else:
        continue
if S[1] > S[0] and S[3] > S[2]:
    print((S[1]-S[0]) * (S[3] - S[2]))
else:
    print(0)