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
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    W, H, N = map(int, readline().split())
    xl = 0
    xr = W
    yl = 0
    yh = H
    for _ in range(N):
        x, y, a = map(int, readline().split())
        if a==1:
            xl = max(xl,x)
        elif a==2:
            xr = min(xr,x)
        elif a==3:
            yl = max(yl,y)
        else:
            yh = min(yh,y)
    print(max(xr-xl,0)*max(yh-yl,0))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Xleft = 0
Xright = W
Ylow = 0
Yhigh = H
for X,Y,A in rows:
    if A == 1:
        Xleft = max(X,Xleft)
    elif A == 2:
        Xright = min(X,Xright)
    elif A == 3:
        Ylow = max(Y,Ylow)
    else:
        Yhigh = min(Y,Yhigh)

ans = max(Yhigh-Ylow,0) * max(Xright-Xleft,0)
print(ans)

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    W, H, N = [int(item) for item in input().split()]
    query = [[int(item) for item in input().split()] for _ in range(N)]

    x_low = 0
    x_high = W
    y_low = 0
    y_high = H

    for x, y, a in query:
        if a == 1:
            x_low = max(x_low, x)
        elif a == 2:
            x_high = min(x_high, x)
        elif a == 3:
            y_low = max(y_low, y)
        else:
            y_high = min(y_high, y)

        # print(x,y,a)
        # print(x_low, x_high, y_low, y_high)
        # print('-----------')
    
    # print('##############')
    # print(x,y,a)
    # print(x_low, x_high, y_low, y_high)
    # print('-----------')

    x_delta = x_high - x_low
    y_delta = y_high - y_low

    if x_delta >= 0 and y_delta >= 0:
        print(x_delta*y_delta)
    else:
        print(0)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
# coding: utf-8
import re
import math
from collections import defaultdict
import itertools
from copy import deepcopy
import random
from heapq import heappop,heappush
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
#@lru_cache(maxsize=None)
readline=sys.stdin.readline
sys.setrecursionlimit(2000000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_power(a,b):#aはbの累乗数か
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def get_facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=""):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)
def hani(x,min_,max_):
    ret=x
    if x<min_:ret=min_
    if x>max_:ret=max_
    return ret
def seifu(x):
    return x//abs(x)
###################################################

def main():
    W,H,N=map(int,input().split())
    X=[1]*(W)
    Y=[1]*(H)
    for i in range(N):
        x,y,a=map(int,input().split())
        if a==1:
           for j in range(0,x):
               X[j]=0
        elif a==2:
           for j in range(x,W):
               X[j]=0
        elif a==3:
           for j in range(y):
               Y[j]=0
        else:
           for j in range(y,H):
               Y[j]=0
    print(Y.count(1)*X.count(1))
main()

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
WL = 0
HL = 0
X = []
Y = []
A = []
for _ in range(N):
    x,y,a = map(int, input().split())
    X.append(x)
    Y.append(y)
    A.append(a)

for i in range(N):
    if A[i] == 1 and WL <= X[i]:
        WL = X[i]
    elif A[i] == 2 and W >= X[i]:
        W = X[i]
    elif A[i] == 3 and HL <= Y[i]:
        HL = Y[i]
    elif A[i] == 4 and H >= Y[i]:
        H = Y[i]

if W - WL <= 0 or H - HL <= 0:
    print(0)
    exit()

print((W - WL) * (H - HL))

Submission status: Accepted

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

painting = []
for i in range(h):
    li = [1]*w
    painting.append(li)


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):
                painting[j][k] = 0
    elif a == 2:
        for j in range(h):
            for k in range(x,w):
                painting[j][k] = 0
    elif a == 3:
        for j in range(y):
            for k in range(w):
                painting[j][k] = 0
    elif a == 4:
        for j in range(y,h):
            for k in range(w):
                painting[j][k] = 0

ans = 0
for i in range(h):
    for j in range(w):
        if painting[i][j] == 1:
            ans += 1

print(ans)

Submission status: Accepted

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

F = [[1 for _ in range(W)] for _ in range(H)]

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

print(sum(sum(f) for f in F))

Submission status: Accepted

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

for i in range(N):
    x,y,a = map(int,input().split())
    if a == 1:
        for j in range(W+1):
            if X[j] < x:
                X[j] = x
    elif a == 2:
        for j in range(W+1):
            if X[j] > x:
                X[j] = x
    elif a == 3:
        for j in range(H+1):
            if Y[j] < y:
                Y[j] = y
    else:
        for j in range(H+1):
            if Y[j] > y:
                Y[j] = y
print((max(X)-min(X))*(max(Y)-min(Y)))

Submission status: Accepted

Solution code:
def nurie(x, y, a):
    if a == 1:
        for i in range(x):
            for j in range(H):
                A[i][j] = 1
    if a == 2:
        for i in range(x, W):
            for j in range(H):
                A[i][j] = 1
    if a == 3:
        for i in range(W):
            for j in range(y):
                A[i][j] = 1
    if a == 4:
        for i in range(W):
            for j in range(y, H):
                A[i][j] = 1

def cal_area(A):
    count = 0
    for i in range(W):
        for j in range(H):
            if A[i][j] == 0:
                count += 1
    return count

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

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

print(cal_area(A))

Submission status: Accepted

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

# 左下の座標
X=Y=0

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(H,y)

# 出力
print(max(W-X,0)*max(H-Y,0))

Submission status: Accepted

Solution code:

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

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

for i in range(n):
    if xya[i][2] == 1:
        for j in range(xya[i][0]):
            for k in range(h):
                ans[j][k] = 0
    elif xya[i][2] == 2:
        for j in range(xya[i][0],w):
            for k in range(h):
                ans[j][k] = 0
    elif xya[i][2] == 3:
        for j in range(xya[i][1]):
            for k in range(w):
                ans[k][j] = 0
    else:
        for j in range(xya[i][1],h):
            for k in range(w):
                ans[k][j] = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

box = [[True for i in range(w)]for j in range(h)]
for i in range(n):
    if xya[i][2] == 1:
        for j in range(xya[i][0]):
            for k in range(h):
                box[k][j] = False
    elif xya[i][2] == 2:
        for j in range(xya[i][0], w):
            for k in range(h):
                box[k][j] = False
    elif xya[i][2] == 3:
        for j in range(w):
            for k in range(xya[i][1]):
                box[k][j] = False
    else:
        for j in range(w):
            for k in range(xya[i][1], h):
                box[k][j] = False

ans = 0
for i in range(h):
    for j in range(w):
        if box[i][j]:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin


def ind_cnv(x,y,xlim):
    return x+y*xlim


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    W, H, N = list(map(int,_in[0].split(' ')))  # type:list(int)
    x_y_a_arr = []
    for i in range(N):
        _ = list(map(int,_in[i+1].split(' ')))  # type:list(int)
        x_y_a_arr.append(_)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    colored = [0]*(H*W)
    for x,y,a in x_y_a_arr:
        x -= 1
        y -= 1
        if a==1:
            for _x in range(x+1):
                for _y in range(H):
                    colored[ind_cnv(_x,_y,W)] = 1
        elif a==2:
            for _x in range(x+1,W):
                for _y in range(H):
                    colored[ind_cnv(_x,_y,W)] = 1
        elif a==3:
            for _x in range(W):
                for _y in range(y+1):
                    colored[ind_cnv(_x,_y,W)] = 1
        elif a==4:
            for _x in range(W):
                for _y in range(y+1,H):
                    colored[ind_cnv(_x,_y,W)] = 1
    cnt = colored.count(0)
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
x = []
y = []
a = []
for i in range(n):
    xx,yy,aa = map(int,input().split())
    x.append(xx)
    y.append(yy)
    a.append(aa)

l = 0
r = w
t = h
b = 0


for i, aa in enumerate(a):
    if aa == 1:
        l = max(l,x[i])
    elif aa == 2:
        r = min(r,x[i])

    elif aa == 3:
        b = max(b,y[i])
    elif aa == 4:
        t = min(t,y[i])

ans = max(0,(r-l) * (t-b))
if r-l <= 0 or t-b <= 0:
    ans = 0
print(ans)

Submission status: Accepted

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

for i in range(n):
    x,y,a = map(int,input().split())
    
    if a == 1:
        for j in range(h):
            pic[j][:x] = [1]*len(pic[j][:x])
            
    if a == 2:
        for j in range(h):
            pic[j][x:] = [1]*len(pic[j][x:])
            
    if a == 3:
         for j in range(1,h+1):
            if j < y+1:
                pic[-j] = [1] * w
                
    if a == 4:
        for j in range(1,h+1):
            if j > y:
                pic[-j] = [1] * w
                
ans = 0

for i in pic:
    ans += i.count(0)
    
print(ans)

Submission status: Accepted

Solution code:
def resolve():
    # 整数 1 つ
    # n = int(input())
    # 整数複数個
    w, h, n = list(map(int, input().split()))
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    # N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
#    P = [list(map(int, input().split())) for i in range(n)]

    Area = [[True] * w] * h
    for _ in range(n):
        x, y, a = list(map(int, input().split()))
        if a == 1:
            for i in range(h):
                for j in range(x):
                    Area[i][j] = False
        if a == 2:
            for i in range(h):
                for j in range(w - x):
                    Area[i][j + x] = False
        if a == 3:
            for i in range(y):
                Area[i] = [False] * w
        if a == 4:
            for i in range(h - y):
                Area[i + y] = [False] * w

    cnt = 0
    for i in Area:
        cnt += i.count(True)
    print(cnt)
resolve()

Submission status: Accepted

Solution code:
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
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 printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

w,h,n=MI()
rect=[0,w,0,h]
for i in range(n):
    a,b,c=MI()
    if c==1:
        rect[0]=max(a,rect[0])
    elif c==2:
        rect[1]=min(a,rect[1])
    elif c==3:
        rect[2]=max(b,rect[2])
    else:
        rect[3]=min(b,rect[3])
print(max(0,rect[3]-rect[2])*max(0,rect[1]-rect[0]))

Submission status: Accepted

Solution code:
if __name__ == '__main__':

    w, h, n = map(int, input().split())
    x = y = 0
    xx = w
    yy = h
    for i in range(n):
        xi, yi, a = map(int, input().split())
        if a == 1:
            x = max(x, xi)
        elif a == 2:
            xx = min(xx, xi)
        elif a == 3:
            y = max(y, yi)
        elif a == 4:
            yy = min(yy, yi)
    print(0 if x >= xx or y >= yy else (xx - x) * (yy - y))

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(n)]
a,b,c,d=0,w,0,h
for x,y,A in l:
    if A==1:
        a=max(a,x)
    elif A==2:
        b=min(b,x)
    elif A==3:
        c=max(c,y)
    else:
        d=min(d,y)
# print(f"b-a:{b-a},d-c:{d-c}")
print((b-a)*(d-c) if b-a>=0 and d-c>=0 else 0)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
lis=[]
for i in range(n):
  lis.append(list(map(int,input().split())))
count=0
for i in range(0,w):
  for j in range(0,h):
    keep=0
    for k in range(0,n):
      x=lis[k][0]
      y=lis[k][1]
      a=lis[k][2]
      if a==1:
        if i<x:
          keep=1
      elif a==2:
        if i>=x:
          keep=1
      elif a==3:
        if j<y:
          keep=1
      elif a==4:
        if j>=y:
          keep=1
    if keep==0:
      count+=1
print(count)

Submission status: Accepted

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

x=[0]*W
y=[0]*H


for _ in range(N):
    xi,yi,ai=map(int,input().split())

    if ai==1:
        for i in range(xi):
            x[i]=1
    elif ai==2:
        for i in range(xi,W):
            x[i]=1
    elif ai==3:
        for i in range(yi):
            y[i]=1
    elif ai==4:
        for i in range(yi,H):
            y[i]=1

print(y.count(0)*x.count(0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
ll=[list(map(int,input().split()))for i in range(N)]
wmax=W
hmax=H
wmin=0
hmin=0
for i in range(N):
    if ll[i][2]==1 and ll[i][0]>=wmin:
        wmin=ll[i][0]
    elif ll[i][2]==2 and ll[i][0]<=wmax:
        wmax=ll[i][0]
    elif ll[i][2]==3 and ll[i][1]>=hmin:
        hmin=ll[i][1]
    elif ll[i][2]==4 and ll[i][1]<=hmax:
        hmax=ll[i][1]
ans = (wmax-wmin)*(hmax-hmin)
if wmax-wmin>0 and hmax-hmin>0:
    print((wmax-wmin)*(hmax-hmin))
else:
    print(0)

Submission status: Accepted

Solution code:
def resolve():
    W, H, N = list(map(int, input().split()))
    XYA = [list(map(int, input().split())) for i in range(N)]
    xmin, xmax, ymin, ymax = 0, W, 0, H
    for xya in XYA:
        if xya[2] == 1:
            xmin = max(xmin, xya[0])
        elif xya[2] == 2:
            xmax = min(xmax, xya[0])
        elif xya[2] == 3:
            ymin = max(ymin, xya[1])
        elif xya[2] == 4:
            ymax = min(ymax, xya[1])
    print(max(max(0,(xmax-xmin))*max((ymax-ymin), 0), 0))

if '__main__' == __name__:
    resolve()

Submission status: Accepted

Solution code:
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)]
p=[]
q=[]
t=[]
s=[]
for i in range(n):
    if a[i]==1:
        p.append(x[i])
    elif a[i]==2:
        q.append(x[i])
    elif a[i]==3:
        t.append(y[i])
    else:
        s.append(y[i])

l=max(p) if p else 0
r=min(q) if q else w
d=max(t) if t else 0
u=min(s) if s else h

if l>r or d>u:
    print(0)
else:
    print((r-l)*(u-d))

Submission status: Accepted

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

for i in range(n):
    x,y,a = map(int, input().split())
    if a==1:
        l=max(l,x)
    elif a==2:
        r=min(r,x)
    elif a==3:
        u=max(u,y)
    elif a==4:
        t=min(t,y)

if l>=r or u>=t:
    print(0)
else:
    print((r-l)*(t-u))

Submission status: Accepted

Solution code:
import numpy as np

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

c = np.zeros((W, H), int)

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

ans = W * H - np.sum(c)
print(ans)

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
p = 0
q = W
l = 0
m = H

for i in range(N):
  x,y,a = map(int, input().split())
  if a == 1:
    p = max(p,x)
  if a == 2:
    q = min(q,x)
  if a == 3:
    l = max(l,y)
  if a == 4:
    m = min(m,y)
if (q-p)<0 or (m-l)<0:
  print(0)
  exit()
else:
  S = (q-p)*(m-l)
  print(S)

Submission status: Accepted

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

    xl, xh = 0, W
    yl, yh = 0, 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)
        else:
            yh = min(yh, y)

    s = max(0, xh - xl) * max(0, yh - yl)

    print(s)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
W, H, N = map(int,input().split())
p = 0
q = W
r = 0
s = H
for i in range(N):
    x, y, a = map(int,input().split())
    if a == 1:
        if x > p:
            p = x
    if a == 2:
        if x < q:
            q = x
    if a == 3:
        if y > r:
            r = y
    if a == 4:
        if y < s:
            s = y
ans = (q-p)*(s-r)
if q < p or s < r:
    ans = 0
print(ans)

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
xmin, xmax, ymin, ymax = 0, w, 0, h
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        if x > xmin:
            xmin = x
    elif a == 2:
        if x < xmax:
            xmax = x
    elif a == 3:
        if y > ymin:
            ymin = y
    else:
        if y < ymax:
            ymax = y

if xmax-xmin < 0 or ymax-ymin < 0:
    print(0)
    exit()
ans = (xmax-xmin) * (ymax-ymin)
print(ans)

Submission status: Accepted

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

left = 0
right = w
down = 0
up = h

for _ 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:
        down = max(down, y)
    elif a == 4:
        up = min(up, y)

if left >= right or down >= up:
    ans = 0
else:
    ans = (right - left) * (up - down)
print(ans)

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
left = 0
right = w
under = 0
hight= 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:
        under = max(under,y)
    else:
        hight = min(hight,y)

if left>=right or under>=hight:
    print(0)
else:
    print((right-left)*(hight-under))

Submission status: Accepted

Solution code:
import numpy as np
def solve():
    def do(x,y,a):
        if a == 1:
            square[0:x:, :] *= 0
        if a == 2:
            square[x::, :] *= 0
        if a == 3:
            square[:, 0:y:] *= 0
        if a == 4:
            square[:, y::] *= 0

    W, H, N = map(int, input().split())
    #w-1, h-1の格子点上
    square = np.array([[1 for _ in range(H)] for _2 in range(W)], dtype=np.int32)

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

    print(np.sum(square))




if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
w,h,n = map(int, input().split())
xya = [list(map(int,input().split())) for _ in range(n)]
X = [0,w]
Y = [0,h]
for x,y,a in xya:
    if a == 1 and X[0] < x: X[0] = x
    elif a == 2 and X[1] > x: X[1] = x
    elif a == 3 and Y[0] < y: Y[0] = y
    elif a == 4 and Y[1] > y: Y[1] = y
h, w = Y[1]-Y[0], X[1]-X[0]
print(0 if h<0 or w<0 else h*w)

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
X1 = W
X2 = 0
Y1 = H
Y2 = 0
for _ in range(N):
    x,y,a = map(int,input().split())
    if a==1:
        X2 = max(X2,x)
    elif a==2:
        X1 = min(X1,x)
    elif a==3:
        Y2 = max(Y2,y)
    elif a==4:
        Y1 = min(Y1,y)
if X2>=X1 and Y2>=Y1:
    ans = 0
elif X2>=X1 and Y2<Y1:
    ans = 0
elif X2<X1 and Y2>=Y1:
    ans = 0
elif X2<X1 and Y2<Y1:
    ans = (X1-X2)*(Y1-Y2)
print(ans)

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
y_max,x_max=h,w
y_min,x_min=0,0
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    x_min=max(x_min,x)
  elif a==2:
    x_max=min(x_max,x)
  elif a==3:
    y_min=max(y_min,y)
  elif a==4:
    y_max=min(y_max,y)

width=max(x_max-x_min,0)
height=max(y_max-y_min,0)
print(int(width*height))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
W,H,N=map(int, input().split())
R=np.zeros((H,W))
for i in range(N):
    x,y,a=map(int, input().split())
    if a==1:
        R[:,:x]=1
    elif a==2:
        R[:,x:]=1
    elif a==3:
        R[:y,:]=1
    else:
        R[y:,:]=1

print(int(W*H- R.sum()))

Submission status: Accepted

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

xy=[['.' for i in range(w)] for i in range(h)]

for x,y,a in l:
  x-=1
  y-=1

  if a==1:
    for i in range(h):
      for j in range(w):
        if j<=x:
          xy[i][j]='#'
  if a==2:
    for i in range(h):
      for j in range(w):
        if x<j:
          xy[i][j]='#'
  if a==3:
    for i in range(h):
      for j in range(w):
        if i<=y:
          xy[i][j]='#'
  if a==4:
    for i in range(h):
      for j in range(w):
        if y<i:
          xy[i][j]='#'

cnt=0
for i in xy:
  cnt+=i.count('.')
print(cnt)

Submission status: Accepted

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

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

#print(x_l,x_r,y_h,y_l)

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
    W,H,N=pin()
    ans=[0,W,0,H]#ans[[xの範囲][yの範囲]]
    for n in range(N):
        x,y,a=pin()
        if a==1:
            ans[0]=max(ans[0],x)
        elif a==2:
            ans[1]=min(ans[1],x)
        elif a==3:
            ans[2]=max(ans[2],y)
        else:
            ans[3]=min(ans[3],y)
    t=((ans[1]-ans[0])*(ans[3]-ans[2]))
    if ans[1]-ans[0]<0 or ans[3]-ans[2]<0:t=0
    print(t)    
#%%submit!
resolve()

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

print((r-l)*(t-b) if l<=r and b<=t else 0)

Submission status: Accepted

Solution code:
w,h,n = map(int, input().split())
xmin = 0
xmax = w
ymin = 0
ymax = h
for _ in range(n):
    x,y,a = map(int, input().split())
    if a == 1:
        xmin = max(xmin,x)
    elif a == 2:
        xmax = min(xmax,x)
    elif a == 3:
        ymin = max(ymin,y)
    elif a == 4:
        ymax = min(ymax,y)
print(max(0,xmax-xmin)*max(0,ymax-ymin))