1935B - Informatics in MAC - CodeForces Solution


constructive algorithms

Please click on ads to support us..

Python Code:

for _ in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    d={}
    for ele in l:
        if(ele not in d):
            d[ele]=1
        else:
            d[ele]+=1
    mex=0
    for i in range(n+1):
        if(i not in d):
            mex=i
            break
    if(mex==0):
        print(2)
        print(1,1)
        print(2,n)
        continue
    d={}
    ans=[]
    left=0
    for i in range(n):
        if(l[i]<mex):
            d[l[i]]=1
        if(len(d)==mex):
            ans.append([left+1,i+1])
            left=i+1
            d={}
    ans[len(ans)-1][1]=n
    if(len(ans)<2):
        print(-1)
    else:
        print(len(ans))
        for val in ans:
            print(val[0],val[1])
        


Comments

Submit
0 Comments
More Questions

99A - Help Far Away Kingdom
622B - The Time
1688C - Manipulating History
1169D - Good Triple
1675B - Make It Increasing
588A - Duff and Meat
1541B - Pleasant Pairs
1626B - Minor Reduction
1680A - Minimums and Maximums
1713A - Traveling Salesman Problem
1713B - Optimal Reduction
1710A - Color the Picture
1686B - Odd Subarrays
251A - Points on Line
427C - Checkposts
1159A - A pile of stones
508A - Pasha and Pixels
912A - Tricky Alchemy
1249A - Yet Another Dividing into Teams
1713C - Build Permutation
1699A - The Third Three Number Problem
1617B - GCD Problem
841A - Generous Kefa
1690B - Array Decrements
1692C - Where's the Bishop
104A - Blackjack
1438A - Specific Tastes of Andre
1711C - Color the Picture
1194C - From S To T
110B - Lucky String