Can anybody help me with this, I’m getting time limit exceeded error always when I try to solve. I’m an amateur btw XD.
here’s my code in python 3.6
try:
t = int(input())
except:
t = 0
MOD = 1000000007
for i in range(t):
n = int(input())
s = input()
s_list = list(s)
q = int(input())
queries = []
for j in range(q):
queries.append(list(input().rstrip().split()))
for j in queries:
start = int(j[1]) - 1
end = int(j[2]) - 1
k = start
if j[0] == '1':
while k <= end:
s_list[k] = j[3]
k+=1
else:
while k <= end:
temp_p = int(j[3])
temp_q = int(j[4])
if s_list[k] == 'A':
# temp_p = int(j[3])
# temp_q = int(j[4])
j[3] = (temp_p%MOD - temp_q%MOD)%MOD
j[4] = (temp_p%MOD + temp_q%MOD)%MOD
else:
# temp_p = int(j[3])
# temp_q = int(j[4])
j[3] = (temp_p%MOD + temp_q%MOD)%MOD
j[4] = (temp_q%MOD - temp_p%MOD)%MOD
k+=1
print(j[3], j[4])