Skip to content

Instantly share code, notes, and snippets.

@saraswatmks
Created September 28, 2017 18:46
Show Gist options
  • Save saraswatmks/dac250cbc66462fe1995d9f8df795fdd to your computer and use it in GitHub Desktop.
Save saraswatmks/dac250cbc66462fe1995d9f8df795fdd to your computer and use it in GitHub Desktop.
Sell Statistics
# Enter your code here. Read input from STDIN. Print output to STDOUT
T = int(raw_input())
sell = [[] for i in range(100)]
product_sell = [[[] for j in range(10)] for i in range(100)]
state_sell = [[[] for j in range(7)] for i in range(100)]
p_s_sell = [[[[] for j in range(7)] for j in range(10)] for i in range(100)]
for t in range(T):
query = 0
data = raw_input().split()
if data[0] == 'S':
data.pop(0)
product = map(int, data[1].split('.'))
if len(product) == 1:
product.append(0)
state = map(int, data[2].split('.'))
if len(state) == 1:
state.append(0)
new_data = product + state
sell[int(data[0])-1].append(new_data)
product_sell[int(data[0])-1][new_data[0]-1].append(new_data)
state_sell[int(data[0])-1][new_data[2]-1].append(new_data)
p_s_sell[int(data[0])-1][new_data[0]-1][new_data[2]-1].append(new_data)
elif data[0] == 'Q':
data.pop(0)
product = map(int, data[1].split('.'))
if len(product) == 1:
product.append(0)
state = map(int, data[2].split('.'))
if len(state) == 1:
state.append(0)
q_data = product + state
total_sell = 0
for day in range(int(data[0].split('.')[0]), int(data[0].split('.')[-1])+1):
if q_data[0] == -1 and q_data[2] == -1:
total_sell += len(sell[day-1])
elif q_data[0] != -1 and q_data[2] == -1:
for s in product_sell[day-1][q_data[0]-1]:
#print q_data, s
if ((q_data[1] == s[1] and q_data[1] != 0) or (q_data[1] == 0)) and ((q_data[2] == s[2] and q_data[3] == s[3] and q_data[3] != 0) or (q_data[2] == s[2] and q_data[3] == 0) or q_data[2] == -1):
total_sell += 1
elif q_data[0] == -1 and q_data != -1:
for s in state_sell[day-1][q_data[2]-1]:
if ((q_data[0] == s[0] and q_data[1] == s[1] and q_data[1] != 0) or (q_data[0] == s[0] and q_data[1] == 0) or q_data[0] == -1) and ((q_data[3] == s[3] and q_data[3] != 0) or (q_data[3] == 0)):
total_sell += 1
else:
for s in p_s_sell[day-1][q_data[0]-1][q_data[2]-1]:
if ((q_data[0] == s[0] and q_data[1] == s[1] and q_data[1] != 0) or (q_data[0] == s[0] and q_data[1] == 0)) and ((q_data[2] == s[2] and q_data[3] == s[3] and q_data[3] != 0) or (q_data[2] == s[2] and q_data[3] == 0)):
total_sell += 1
print total_sell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment