You are viewing a single comment's thread. Return to all comments →
Solution in Python 3
p = int(1e9+7) def intsc(l1,l2): if l1==[] or l2==[]: return([]) else: a = max(l1[0],l2[0]) b = min(l1[1],l2[1]) if b<a: return([]) else: return([a,b]) def cd(l): if l==[]: return(0) else: return(l[1]-l[0]+1) t = int(input()) for tst in range(t): s = input().strip().split() w = [] for i in s: w.append(int(i)) z= {} z[0]=[w[0],w[1]] z[1]=[w[2],w[3]] z[2]=[w[4],w[5]] z[3]=[w[6],w[7]] comp = 0 for i in range(4): tmp = 1 L = intsc(z[i],z[(i+1)%4]) j = (i+2)%4 k = (i+3)%4 tmp = (tmp*cd(L))%p tmp = (tmp*cd(z[j]))%p tmp = (tmp*cd(z[k]))%p comp = (comp+tmp)%p for i in range(4): tmp = 1 L = intsc(z[i],z[(i+1)%4]) L = intsc(L,z[(i+2)%4]) tmp = cd(L)%p tmp = (tmp*cd(z[(i+3)%4]))%p comp = (comp-tmp)%p a1 = intsc(z[0],z[1]) a2 = intsc(z[2],z[3]) a3 = intsc(z[1],z[2]) a4 = intsc(z[3],z[0]) comp = (comp - (cd(a1)*cd(a2))%p)%p comp = (comp - (cd(a3)*cd(a4))%p)%p b = intsc(a1,a2) comp = (comp+3*cd(b))%p tot = 1 for i in range(4): tot*=cd(z[i]) tot%=p tot-=comp tot%=p print(tot)
Seems like cookies are disabled on this browser, please enable them to open this website
Cyclic Quadruples
You are viewing a single comment's thread. Return to all comments →
Solution in Python 3