QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#316885#8177. Sum is Integerucup-team2000#TL 7ms10100kbPython31.2kb2024-01-28 05:30:252024-01-28 05:30:25

Judging History

你现在查看的是最新测评结果

  • [2024-01-28 05:30:25]
  • 评测
  • 测评结果:TL
  • 用时:7ms
  • 内存:10100kb
  • [2024-01-28 05:30:25]
  • 提交

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 = [A[i] - B[i] for i in range(n)] + [0]
# 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)


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 10100kb

input:

4
1 6
1 3
1 2
1 2

output:

2

result:

ok "2"

Test #2:

score: 0
Accepted
time: 6ms
memory: 10008kb

input:

5
1 1
2 2
3 3
4 4
5 5

output:

15

result:

ok "15"

Test #3:

score: 0
Accepted
time: 7ms
memory: 10004kb

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...

output:


result: