QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#475431#8837. Increasing Incomeucup-team3646#WA 14ms10760kbPython31.9kb2024-07-13 14:45:062024-07-13 14:45:07

Judging History

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

  • [2024-07-13 14:45:07]
  • 评测
  • 测评结果:WA
  • 用时:14ms
  • 内存:10760kb
  • [2024-07-13 14:45:06]
  • 提交

answer

def f(a):
  cnt=0
  mx=-1
  for i in a:
    if mx<i:
      cnt+=1
      mx=i
  return cnt

from bisect import bisect
def LIS(a,n):
  INF=1<<30
  dp=[INF]*(n+1)
  dp[0]=-1
  c=[0]*n
  for i in range(n):
    idx=bisect(dp, a[i]-1)
    dp[idx]=min(a[i], dp[idx])
    c[i]=idx
  return c

import itertools
def naive(p):
  n=len(p)
  ans=0
  cand=[]
  dand=[]
  for q in itertools.permutations(list(range(n))):
    r=[0]*n
    for i in range(n):
      r[i]=p[q[i]]
    r=tuple(r)
    val=f(q)+f(r)
    if val>ans:
      ans=val
      cand=[q]
      dand=[r]
    elif ans==val:
      cand.append(q)
      dand.append(r)
  return cand[0]

def calc0(p):
  n=len(p)
  q=[0]*n
  for i in range(n):
    q[p[i]]=i
  cnt=0
  dnt=0
  for i in range(n-1):
    if q[i]>q[i+1]:
      cnt+=1
    if p[i]>p[i+1]:
      dnt+=1
  print(2*n-max(dnt,cnt))
  return 2*n-max(dnt,cnt)

def solve(p):
  n=len(p)
  L=LIS(p,n)
  R=LIS([n-1-i for i in p[::-1]],n)[::-1]
  mx=0
  for i in range(n):
    mx=max(mx,L[i]+R[i])
  idxs=[]
  tmp=0
  for i in range(n):
    if L[i]+R[i]==mx:
      if tmp<L[i]:
        tmp=L[i]
        idxs.append(i)
  
  mn=-1
  use=[0]*n
  for i in idxs:
    use[i]=1
  ans=[]
  for i in range(n):
    if use[i]:
      ans.append(i)
      mn=max(mn,p[i])
    elif p[i]<mn:
      ans.append(i)
      use[i]=1
  for i in range(n):
    if use[i]==0:
      ans.append(i)
  return ans

def calc(p,q):
  n=len(p)
  r=[0]*n
  for i in range(n):
    r[i]=p[q[i]]
  return f(p)+f(q)
"""
import random
for p in itertools.permutations(list(range(8))):
  print(p,solve(p))
  ans1=solve(p)
  ans2=naive(p)
  
  print(p,ans1,ans2,calc(p,ans1),calc(p,ans2))
  assert calc(p,ans1)==calc(p,ans2)
"""

from sys import stdin
input=lambda :stdin.readline()[:-1]

for _ in range(int(input())):
  n=int(input())
  p=list(map(lambda x:int(x)-1,input().split()))
  print(*[i+1 for i in solve(p)])

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 14ms
memory: 10656kb

input:

3
3
1 2 3
4
2 4 3 1
5
1 5 2 4 3

output:

1 2 3
1 2 3 4
1 3 4 5 2

result:

ok Correct (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 12ms
memory: 10760kb

input:

153
4
2 4 3 1
4
1 4 2 3
5
2 1 4 5 3
5
1 4 5 3 2
4
1 3 2 4
5
1 5 2 4 3
5
5 3 1 2 4
5
4 1 2 5 3
5
1 2 5 3 4
5
3 1 4 2 5
5
5 4 2 3 1
5
2 1 5 4 3
5
3 4 1 5 2
5
1 4 3 5 2
5
5 1 3 4 2
5
5 3 2 4 1
5
1 5 3 2 4
5
2 4 3 1 5
5
1 5 4 3 2
5
1 2 4 5 3
5
4 2 5 3 1
5
1 3 5 2 4
5
3 1 4 5 2
3
2 1 3
5
1 2 4 3 5
5
5 1 ...

output:

1 2 3 4
1 3 4 2
1 2 3 4 5
1 2 3 4 5
1 2 3 4
1 3 4 5 2
3 4 5 1 2
2 3 4 5 1
1 2 4 5 3
1 2 3 4 5
3 4 5 1 2
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
2 3 4 5 1
2 3 4 5 1
1 3 4 5 2
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3
1 2 3 4 5
2 3 4 5 1
3 4 5 1 2
3 4 5 1 2
1 2 3
1 2 3 4
1 2 3 4
1 2 3 4
...

result:

wrong answer Jury found better answer than participant (test case 7)