This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
# Function to calculate the total time the taxi was able to drive from stop a to stop b
def calculate_time(lamps, a, b):
total_time = 0
for i in range(a - 1, b - 1):
total_time += lamps[i]
return total_time
# Read input values
n, q = map(int, input().split())
lamp_states = list(map(int, input().strip()))
# Initialize a list to store lamp states (0 for off, 1 for on)
lamps = [0] * n
# Initialize total time to 0
total_time = 0
# Process events
for _ in range(q):
event = input().split()
if event[0] == "toggle":
i = int(event[1]) - 1
lamp_states[i] = 1 - lamp_states[i] # Toggle lamp state
if lamp_states[i] == 1:
total_time += 1 # Increment total time if lamp is turned on
else:
total_time -= 1 # Decrement total time if lamp is turned off
else: # Event is a query
a, b = map(int, event[1:])
time = calculate_time(lamp_states, a, b)
print(time)
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |