Created
April 4, 2012 21:02
-
-
Save soopercorp/2305630 to your computer and use it in GitHub Desktop.
unique elts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Question: | |
# You are given an array A[1..N] and a number of queries of the form (L,H). | |
# For each query, compute the number of unique elements in the array A between indices L and H inclusive. | |
# That is, you need to count the number of elements which occur exactly once in the index range [L..H]. | |
from collections import Counter | |
arr_size = raw_input() | |
arr = [] | |
for a in range(0,int(arr_size)): | |
n = raw_input() | |
arr.append(int(n)) | |
quer = raw_input() | |
qarr = [] | |
for a in range(0,int(quer)): | |
n = raw_input() | |
qarr.append(n) | |
for i,el in enumerate(qarr): | |
qarr[i] = el.split(' ') | |
qarr[i][0] = int(qarr[i][0])-1 | |
qarr[i][1] = int(qarr[i][1])-1 | |
start = qarr[i][0] | |
end = qarr[i][1] | |
y=Counter(arr[start:end+1]) | |
for k,v in y.items(): | |
if(y[k]>1): | |
del y[k] | |
out = len(y) | |
print out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment