QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#886787 | #9329. Good Subsegments | kangkunma | TL | 1577ms | 22836kb | Python3 | 669b | 2025-02-07 11:31:47 | 2025-02-07 11:31:48 |
Judging History
answer
def s(n,l):
A=[[] for i in range(n+1)];k=1
for i in range(n-1):
if l[i]==l[i+1]:k+=1
else:A[l[i]]+=[k];k=1
A[l[-1]]+=[k]
N=[0]*(n+1)
for i in range(1,n+1):
if not A[i]:continue
p=[0]*(n+1);u=0;v=0
for j in A[i]:p[j]+=1;u+=j;v+=1
j=1
while u:
N[j]+=(v-1)*u-v*(v-1)//2-(v-1)*(j-1)*v
N[j//2]+=u-(j-1)*v
v-=p[j];u-=j*p[j];j+=1
F=[N[n//2]]
for i in range(n//2-1,0,-1):F=[N[i]+F[0]]+F
return F
from sys import stdin;z=stdin.readline
for _ in range(int(input())):
n=int(z());l=[*map(int,z().split())]
print(*s(n,l))
詳細信息
Test #1:
score: 100
Accepted
time: 7ms
memory: 8832kb
input:
4 10 1 2 2 2 2 2 3 2 2 2 6 1 1 1 2 1 1 9 2 2 1 1 1 2 2 1 1 10 3 2 3 2 4 2 10 10 10 10
output:
28 11 3 0 0 10 2 0 16 3 0 0 10 1 0 0 0
result:
ok 17 numbers
Test #2:
score: 0
Accepted
time: 11ms
memory: 8704kb
input:
4 3 3 3 3 8 3 3 3 3 2 2 2 2 3 3 3 3 5 3 3 3 3 3
output:
3 12 2 0 0 3 10 3
result:
ok 8 numbers
Test #3:
score: 0
Accepted
time: 88ms
memory: 9088kb
input:
15430 4 4 4 2 2 9 1 1 1 1 1 1 1 1 2 10 2 2 2 2 2 2 4 4 4 3 7 4 4 4 4 4 4 4 7 6 6 6 6 5 5 5 6 6 6 6 6 6 6 8 8 8 8 8 5 5 3 3 7 7 7 7 7 6 6 6 10 4 4 4 4 2 2 2 2 2 2 4 1 2 2 2 6 1 1 1 1 1 1 10 6 6 6 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 9 7 1 3 3 3 3 3 3 10 4 4 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 10 10 10 10 10 1...
output:
2 0 28 15 6 1 18 6 1 0 0 21 10 3 9 1 0 15 6 1 8 1 0 0 9 1 0 21 7 1 0 0 3 0 15 6 1 24 10 3 0 0 36 21 10 3 15 6 1 29 15 6 1 0 21 10 3 16 4 0 0 0 13 2 0 0 0 3 0 13 2 0 0 0 7 1 0 6 0 0 3 6 1 10 3 0 36 21 10 3 10 3 0 10 3 10 3 3 45 28 15 6 1 6 1 11 3 0 6 1 7 0 0 6 1 15 6 1 1 10 1 0 0 4 0 15 6 1 3 18 6 1 ...
result:
ok 46132 numbers
Test #4:
score: 0
Accepted
time: 70ms
memory: 9088kb
input:
1785 33 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 63 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 73 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 2...
output:
528 465 406 351 300 253 210 171 136 105 78 55 36 21 10 3 1953 1830 1711 1596 1485 1378 1275 1176 1081 990 903 820 741 666 595 528 465 406 351 300 253 210 171 136 105 78 55 36 21 10 3 2628 2485 2346 2211 2080 1953 1830 1711 1596 1485 1378 1275 1176 1081 990 903 820 741 666 595 528 465 406 351 300 253...
result:
ok 49554 numbers
Test #5:
score: 0
Accepted
time: 69ms
memory: 8960kb
input:
1822 96 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 21 9...
output:
4560 4371 4186 4005 3828 3655 3486 3321 3160 3003 2850 2701 2556 2415 2278 2145 2016 1891 1770 1653 1540 1431 1326 1225 1128 1035 946 861 780 703 630 561 496 435 378 325 276 231 190 153 120 91 66 45 28 15 6 1 210 171 136 105 78 55 36 21 10 3 2178 1996 1822 1656 1498 1348 1206 1072 946 828 718 616 52...
result:
ok 49546 numbers
Test #6:
score: 0
Accepted
time: 1577ms
memory: 22836kb
input:
2 89720 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 18749 1874...
output:
1848963231 1848783803 1848604391 1848424995 1848245615 1848066251 1847886903 1847707571 1847528255 1847348955 1847169671 1846990403 1846811151 1846631915 1846452695 1846273491 1846094303 1845915131 1845735975 1845556835 1845377711 1845198603 1845019511 1844840435 1844661375 1844482331 1844303303 184...
result:
ok 50000 numbers
Test #7:
score: 0
Accepted
time: 1105ms
memory: 19720kb
input:
2 73829 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 44095 4409...
output:
535244835 535097201 534949599 534802029 534654491 534506985 534359511 534212069 534064659 533917281 533769935 533622621 533475339 533328089 533180871 533033685 532886531 532739409 532592319 532445261 532298235 532151241 532004279 531857349 531710451 531563585 531416751 531269949 531123179 530976441 ...
result:
ok 49999 numbers
Test #8:
score: -100
Time Limit Exceeded
input:
1 200000 128472 128472 128472 128472 128472 128472 128472 128472 128472 128472 128472 128472 128472 128472 128472 128472 128472 128472 128472 128472 128472 128472 128472 128472 128472 128472 128472 128472 128472 128472 128472 128472 128472 128472 128472 128472 128472 128472 128472 128472 128472 1284...