# 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)
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
2880 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
909 ms |
6396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
2904 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
41 ms |
2908 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
2880 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |