QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#316883 | #8177. Sum is Integer | ucup-team2000# | TL | 9ms | 9580kb | Python3 | 1.1kb | 2024-01-28 05:29:07 | 2024-01-28 05:29:07 |
Judging History
answer
# import io,os,sys
# input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
import sys
input = sys.stdin.readline
p1 = 23513892331597
p2 = 999998727899999
p3 = 19489355557003
pn = []
qn = []
n = int(input())
for i in range(n):
x, y = list(map(int, input().split()))
pn.append(x)
qn.append(y)
def get_array(p):
arr = [(pn[i] * pow(qn[i], p-2,p)) % p for i in range(n)]
for i in range(1,n):
arr[i] = (arr[i] + arr[i-1]) % p
return arr
A = get_array(p1)
B = get_array(p2)
C = get_array(p3)
all = [A,B,C]
k = 2
res = []
for i in range(n):
vals = []
for ii in range(k):
for jj in range(ii+1,k):
vals.append(all[ii][i] - all[jj][i])
# print(vals)
res.append(vals)
res.append([0 for i in range(k) for j in range(i+1,k)])
res = list(sorted(res))
# print(res)
ans = 0
for i in range(n+1):
if i > 0 and res[i] == res[i-1]:
continue
j = i
while j + 1 < n+1 and res[j+1] == res[i]:
j += 1
# print(f"i: {i}, j: {j}")
len = j - i + 1
ans += (len) * (len - 1) // 2
print(ans)
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 9564kb
input:
4 1 6 1 3 1 2 1 2
output:
2
result:
ok "2"
Test #2:
score: 0
Accepted
time: 9ms
memory: 9580kb
input:
5 1 1 2 2 3 3 4 4 5 5
output:
15
result:
ok "15"
Test #3:
score: 0
Accepted
time: 8ms
memory: 9572kb
input:
2 1 99999 99999 100000
output:
0
result:
ok "0"
Test #4:
score: -100
Time Limit Exceeded
input:
200000 82781 82781 86223 86223 16528 16528 84056 84056 94249 94249 54553 54553 25943 25943 10415 10415 52417 52417 46641 46641 70298 70298 84228 84228 55441 55441 49326 49326 11753 11753 89499 89499 58220 58220 71482 71482 32373 32373 7251 7251 78573 78573 74268 74268 46682 46682 20314 20314 85519 8...