Submission #63856307


Source Code Expand

Copy
from atcoder.lazysegtree import LazySegTree
inf=1<<63
n=int(input())
a=list(map(int,input().split()))
def mapping(a,b):return a+b
def comp(a,b):return a+b
prefix=[]
dp=LazySegTree(max,-inf,mapping,comp,0,[0]*n)
pre=set()
for i in range(n):
pre.add(a[i])
prefix.append(len(pre))
idx=[-1]*(n+1)
X=[0]*(n+1)
for i in range(n):
if idx[a[i]]==-1:
dp.apply(0,i,1)
else:
dp.apply(idx[a[i]],i,1)
X[i]=dp.prod(0,i)
dp.set(i,prefix[i])
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
from atcoder.lazysegtree import LazySegTree
inf=1<<63
n=int(input())
a=list(map(int,input().split()))
def mapping(a,b):return a+b
def comp(a,b):return a+b
prefix=[]
dp=LazySegTree(max,-inf,mapping,comp,0,[0]*n)
pre=set()
for i in range(n):
    pre.add(a[i])
    prefix.append(len(pre))
idx=[-1]*(n+1)
X=[0]*(n+1)
for i in range(n):
    if idx[a[i]]==-1:
        dp.apply(0,i,1)
    else:
        dp.apply(idx[a[i]],i,1)
    X[i]=dp.prod(0,i)
    dp.set(i,prefix[i])
    idx[a[i]]=i
suf=set()
ans=0
suf.add(a[-1])
for i in range(n-2,0,-1):
    ans=max(ans,X[i]+len(suf))
    suf.add(a[i])
print(ans)

Submission Info

Submission Time
Task F - Variety Split Hard
User juten
Language Python (PyPy 3.10-v7.3.12)
Score 550
Code Size 626 Byte
Status AC
Exec Time 812 ms
Memory 217684 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 550 / 550
Status
AC × 2
AC × 44
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_test_00.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt, 01_test_26.txt, 01_test_27.txt, 01_test_28.txt, 01_test_29.txt, 01_test_30.txt, 01_test_31.txt, 01_test_32.txt, 01_test_33.txt, 01_test_34.txt, 01_test_35.txt, 01_test_36.txt, 01_test_37.txt, 01_test_38.txt, 01_test_39.txt, 01_test_40.txt, 01_test_41.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 118 ms 84460 KB
00_sample_01.txt AC 119 ms 84216 KB
01_test_00.txt AC 173 ms 87848 KB
01_test_01.txt AC 153 ms 86492 KB
01_test_02.txt AC 181 ms 88080 KB
01_test_03.txt AC 174 ms 87668 KB
01_test_04.txt AC 159 ms 87564 KB
01_test_05.txt AC 335 ms 112808 KB
01_test_06.txt AC 781 ms 200288 KB
01_test_07.txt AC 555 ms 129524 KB
01_test_08.txt AC 753 ms 200116 KB
01_test_09.txt AC 563 ms 130044 KB
01_test_10.txt AC 755 ms 200112 KB
01_test_11.txt AC 371 ms 119668 KB
01_test_12.txt AC 755 ms 200088 KB
01_test_13.txt AC 638 ms 167024 KB
01_test_14.txt AC 755 ms 200132 KB
01_test_15.txt AC 804 ms 176228 KB
01_test_16.txt AC 634 ms 176328 KB
01_test_17.txt AC 812 ms 183804 KB
01_test_18.txt AC 641 ms 183212 KB
01_test_19.txt AC 772 ms 187912 KB
01_test_20.txt AC 639 ms 187816 KB
01_test_21.txt AC 764 ms 192636 KB
01_test_22.txt AC 650 ms 192272 KB
01_test_23.txt AC 757 ms 197076 KB
01_test_24.txt AC 658 ms 196772 KB
01_test_25.txt AC 572 ms 147068 KB
01_test_26.txt AC 585 ms 169704 KB
01_test_27.txt AC 590 ms 169464 KB
01_test_28.txt AC 589 ms 169468 KB
01_test_29.txt AC 573 ms 166812 KB
01_test_30.txt AC 587 ms 166808 KB
01_test_31.txt AC 592 ms 217632 KB
01_test_32.txt AC 637 ms 217556 KB
01_test_33.txt AC 119 ms 84280 KB
01_test_34.txt AC 119 ms 84540 KB
01_test_35.txt AC 630 ms 200084 KB
01_test_36.txt AC 617 ms 170612 KB
01_test_37.txt AC 615 ms 163996 KB
01_test_38.txt AC 591 ms 217560 KB
01_test_39.txt AC 611 ms 217580 KB
01_test_40.txt AC 623 ms 217684 KB
01_test_41.txt AC 616 ms 217548 KB


2025-05-05 (Mon)
15:15:27 +09:00