Crayons

Limits 1s, 32 MB

Five friends A, B, C, D and E has come to a shop to buy crayons for their art project. They need crayons of Na, Nb, Nc, Nd and Ne distinct colors respectively. The shop has a strange rule. There are M crayons in the shop arranged in a row numbered from 1 to M. If you want to buy crayons, you have to choose two numbers L and R where 1 ≤ L ≤ R ≤M and then you have to buy all the crayons numbered from L to R.


This is a companion discussion topic for the original entry at https://toph.co/p/crayons

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/)