Crayons

Five friends A, B, C, D and E has come to a shop to buy crayons for their art project. They need cra…

Click here to read the complete problem statement.


If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.

I am getting irritated. Plzz increase the runtime for python.
Here is my code:

n1, n2, n3, n4, n5 = map(int, input().split())
m, q = map(int, input().split())
m_crayons = list(map(int, input().split()))
for i in range(q):
    x, l, r = input().split()
    if x == 'A':
        if n1 <= len(set(m_crayons[int(l) - 1:int(r)])):
            print("Yes")
        else:
            print("No")
    if x == 'B':
        if n2 <= len(set(m_crayons[int(l) - 1:int(r)])):
            print("Yes")
        else:
            print("No")
    if x == 'C':
        if n3 <= len(set(m_crayons[int(l) - 1:int(r)])):
            print("Yes")
        else:
            print("No")
    if x == 'D':
        if n4 <= len(set(m_crayons[int(l) - 1:int(r)])):
            print("Yes")
        else:
            print("No")
    if x == 'E':
        if n5 <= len(set(m_crayons[int(l) - 1:int(r)])):
            print("Yes")
        else:
            print("No")

I can’t find a way to shorten the runtime anymore.
plzz hlp @touhidur @hjr265

@Abdullah_​1234 You should learn MO’s Algorithm

(https://www.geeksforgeeks.org/mos-algorithm-query-square-root-decomposition-set-1-introduction/)

1 Like