Submission #65875497


Source Code Expand

Copy
n=int(input())
a=list(map(int,input().split()))
cnt=[0]*(n-1)
for i in range(n-1):
if a[i]<a[i+1]:
cnt[i]=1
elif a[i]>a[i+1]:
cnt[i]-=1
p=[0]*n
v=[0]*n
for i in range(1,n-1):
if cnt[i-1]==1 and cnt[i]==-1:
p[i]=1
elif cnt[i-1]==-1 and cnt[i]==1:
v[i]=1
inf=10**9
np=[inf]*(n+1)
nv=[inf]*(n+1)
for i in range(n-1,-1,-1):
np[i]=i if (i<n and v[i])else np[i+1]
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
n=int(input())
a=list(map(int,input().split()))

cnt=[0]*(n-1)
for i in range(n-1):
    if a[i]<a[i+1]:
        cnt[i]=1
    elif a[i]>a[i+1]:
        cnt[i]-=1
p=[0]*n
v=[0]*n
for i in range(1,n-1):
    if cnt[i-1]==1 and cnt[i]==-1:
        p[i]=1
    elif cnt[i-1]==-1 and cnt[i]==1:
        v[i]=1
inf=10**9
np=[inf]*(n+1)
nv=[inf]*(n+1)
for i in range(n-1,-1,-1):
    np[i]=i if (i<n and v[i])else np[i+1]
    nv[i]=i if (i<n and v[i])else nv[i+1]
l=0
r=0
pc=0
vc=0
ans=0
for l in range(n):
    if r<=l:r=l+1
    while r<n and pc+p[r-1]<=1 and vc+v[r-1]<=1:
        pc+=p[r-1]
        vc+=v[r-1]
        r+=1
    if l+1<n and cnt[l]==1:
        pp=np[l+1]
        vv=nv[l+1]
        if pp<inf and vv<inf:
            rr=max(pp,vv)+1
            if rr<=r:
                ans+=r-rr
    if l+1<r:
        pc-=p[l+1]
        vc-=v[l+1]
print(ans)

Submission Info

Submission Time
Task C - ~
User juten
Language Python (PyPy 3.10-v7.3.12)
Score 350
Code Size 891 Byte
Status AC
Exec Time 131 ms
Memory 144292 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 350 / 350
Status
AC × 3
AC × 38
Set Name Test Cases
Sample sample00.txt, sample01.txt, sample02.txt
All sample00.txt, sample01.txt, sample02.txt, testcase00.txt, testcase01.txt, testcase02.txt, testcase03.txt, testcase04.txt, testcase05.txt, testcase06.txt, testcase07.txt, testcase08.txt, testcase09.txt, testcase10.txt, testcase11.txt, testcase12.txt, testcase13.txt, testcase14.txt, testcase15.txt, testcase16.txt, testcase17.txt, testcase18.txt, testcase19.txt, testcase20.txt, testcase21.txt, testcase22.txt, testcase23.txt, testcase24.txt, testcase25.txt, testcase26.txt, testcase27.txt, testcase28.txt, testcase29.txt, testcase30.txt, testcase31.txt, testcase32.txt, testcase33.txt, testcase34.txt
Case Name Status Exec Time Memory
sample00.txt AC 56 ms 76696 KB
sample01.txt AC 57 ms 76760 KB
sample02.txt AC 56 ms 76332 KB
testcase00.txt AC 87 ms 92524 KB
testcase01.txt AC 131 ms 139420 KB
testcase02.txt AC 79 ms 87512 KB
testcase03.txt AC 129 ms 139312 KB
testcase04.txt AC 120 ms 131504 KB
testcase05.txt AC 127 ms 139428 KB
testcase06.txt AC 114 ms 125432 KB
testcase07.txt AC 128 ms 139480 KB
testcase08.txt AC 56 ms 76324 KB
testcase09.txt AC 56 ms 76272 KB
testcase10.txt AC 82 ms 99360 KB
testcase11.txt AC 117 ms 144064 KB
testcase12.txt AC 98 ms 120448 KB
testcase13.txt AC 117 ms 144012 KB
testcase14.txt AC 110 ms 144292 KB
testcase15.txt AC 83 ms 111512 KB
testcase16.txt AC 105 ms 143952 KB
testcase17.txt AC 79 ms 104716 KB
testcase18.txt AC 105 ms 144040 KB
testcase19.txt AC 79 ms 95736 KB
testcase20.txt AC 110 ms 139432 KB
testcase21.txt AC 85 ms 104652 KB
testcase22.txt AC 110 ms 139412 KB
testcase23.txt AC 98 ms 116756 KB
testcase24.txt AC 113 ms 139712 KB
testcase25.txt AC 95 ms 112376 KB
testcase26.txt AC 113 ms 139508 KB
testcase27.txt AC 86 ms 95800 KB
testcase28.txt AC 118 ms 139364 KB
testcase29.txt AC 95 ms 105452 KB
testcase30.txt AC 119 ms 139708 KB
testcase31.txt AC 88 ms 91548 KB
testcase32.txt AC 123 ms 139432 KB
testcase33.txt AC 99 ms 108360 KB
testcase34.txt AC 119 ms 139600 KB


2025-05-17 (Sat)
22:42:02 +09:00