QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#316883#8177. Sum is Integerucup-team2000#TL 9ms9580kbPython31.1kb2024-01-28 05:29:072024-01-28 05:29:07

Judging History

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

  • [2024-01-28 05:29:07]
  • 评测
  • 测评结果:TL
  • 用时:9ms
  • 内存:9580kb
  • [2024-01-28 05:29:07]
  • 提交

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

output:


result: