Submission #659586

#TimeUsernameProblemLanguageResultExecution timeMemory
659586beaconmcFancy Fence (CEOI20_fancyfence)Pypy 3
100 / 100
170 ms44284 KiB
n = int(input()) h = list(map(int, input().split())) w = list(map(int, input().split())) sussies = [list(i) for i in zip(h,w)] stack = [] def rect(a,b): return a*(a+1)*b*(b+1)//4 def comb(): if len(stack)>1 and stack[-1][0] == stack[-2][0]: a = stack.pop()[1] stack[-1][1] += a ans = 0 for i in sussies: if not stack: stack.append(i) else: while stack[-1][0] > i[0]: if len(stack)==1: ans += rect(stack[-1][0],stack[-1][1])-rect(i[0],stack[-1][1]) stack[-1][0] = i[0] else: sus = max(stack[-2][0], i[0]) ans += rect(stack[-1][0],stack[-1][1])-rect(sus,stack[-1][1]) stack[-1][0] = sus comb() stack.append(i) comb() while len(stack) != 1: sus = stack[-2][0] ans += rect(stack[-1][0],stack[-1][1])-rect(sus,stack[-1][1]) stack[-1][0] = sus comb() ans += rect(stack[0][0], stack[0][1]) print(ans%1000000007)
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...