from turtle import *
pensize(1); speed(0)
def square(x, y, size, c):
pu(); goto(x, y); pd(); color(c)
begin_fill()
for _ in range(4): fd(size); rt(90)
end_fill()
color("red")
while size >= d:
for _ in range(4): fd(size); rt(90)
size -= d
n = int(input())
d = 40
for i in range(n, 0, -1):
if i ==1: square(0, 0, d, "yellow")
else:
L = (i-1) * d
x, y = -L//2, L//2
square(x, y, d * i, "yellow")
square(x, y, d, "blue"); square(x + L, y, d, "blue")
square(x, y - L, d, "blue"); square(x + L, y - L, d, "blue")
ht()
def build_wall(N, K, stages):
heights = [0] * N # Initialize all columns to height 0
for stage in stages:
Op, Left, Right, Height = stage
if Op == 1: # Adding bricks
for i in range(Left, Right + 1):
if heights[i] < Height:
heights[i] = Height
elif Op == 2: # Removing bricks
for i in range(Left, Right + 1):
if heights[i] > Height:
heights[i] = Height
return heights
Reading input
N, K = map(int, input().split())
stages = [list(map(int, input().split())) for _ in range(K)]
Bình luận
code b1
def build_wall(N, K, stages):
heights = [0] * N # Initialize all columns to height 0
Reading input
N, K = map(int, input().split())
stages = [list(map(int, input().split())) for _ in range(K)]
Processing and getting the final heights
final_heights = build_wall(N, K, stages)
Outputting the result
print(" ".join(map(str, final_heights)))
This comment is hidden due to too much negative feedback. Click here to view it.