QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#458487#8837. Increasing Incomeucup-team1525#WA 1ms7988kbC++202.5kb2024-06-29 17:37:282024-06-29 17:37:29

Judging History

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

  • [2024-06-29 17:37:29]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7988kb
  • [2024-06-29 17:37:28]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=2e5;
int n;
int p[N+5],rp[N+5];
int q[N+5];

// void solve(){
//     set<int> pos,val;
//     scanf("%d",&n);
//     for(int i=1;i<=n;i++){
//         scanf("%d",&p[i]);
//         rp[p[i]]=i;
//         pos.insert(i);
//         val.insert(i);
//     }
//     int tot=n;
//     while(pos.size()&&val.size()){
//         int p1=*pos.rbegin(),v1;
//         int p2,v2=*val.rbegin();
//         v1=p[p1]; p2=rp[v2];
//         if(p1==p2){
//             q[tot--]=p1;
//             pos.erase(p1);
//             val.erase(v1);
//         }
//         else{
//             pos.erase(p1); val.erase(v2);
//             if(v1==*val.rbegin()){
//                 q[tot--]=p2; q[tot--]=p1;
//             }
//             else{
//                 q[tot--]=p1; q[tot--]=p2;
//             }
//             pos.erase(p2); val.erase(v1);
//         }
//     }
//     for(int i=1;i<=n;i++)
//         printf("%d ",q[i]);
//     puts("");
// }
int a[N+5];
int pre[N+5],used[N+5];
void solve()
{
    scanf("%d",&n);
    for (int i=1;i<=n;++i)
    {
        scanf("%d",&a[i]);
        p[a[i]]=i;
    }
    set<int> s;
    for (int i=1;i<=n;++i)
    {
        auto it=s.lower_bound(a[i]);
        if(it!=s.begin())
            pre[i]=p[*prev(it)];
        if (it!=s.end())
            s.erase(it);
        s.insert(a[i]);
    }
    int r=*s.rbegin(),pr;
    pr=p[r];
    vector<int> v;
    while (pr!=0)
    {
        v.push_back(pr);
        pr=pre[pr];
    }
    for (int i=1;i<=n;++i)
        used[i]=0;
    int oldp=n,oldv=n;
    vector<int> ans;
    for (int x:v)
    {
        int newp=x,newv=a[x];
        for (int i=oldp;i>newp;--i)
            if (!used[i])
            {
                used[i]=1;
                ans.push_back(i);
            }
        for (int i=oldv;i>newv;--i)
            if (!used[p[i]])
            {
                used[p[i]]=1;
                ans.push_back(p[i]);
            }
        used[x]=1;
        ans.push_back(x);
        oldp=newp-1;
        oldv=newv-1;
    }
    for (int i=oldp;i;--i)
        if (!used[i])
            {
                used[i]=1;
                ans.push_back(i);
            }
    for (int i=oldv;i;--i)
        if (!used[p[i]])
        {
            used[p[i]]=1;
            ans.push_back(p[i]);
        }
    for (int i=ans.size()-1;i>=0;--i)
        printf("%d ",ans[i]);
    puts("");
}
int main(){
    int t; scanf("%d",&t);
    while(t--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7988kb

input:

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

output:

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

result:

ok Correct (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 7872kb

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 3 2 4 
1 3 4 2 
1 2 1 3 4 5 
1 2 3 4 5 
1 3 2 4 
1 3 5 4 2 
1 3 4 2 5 1 
1 2 3 5 1 4 
1 2 4 5 3 
1 2 4 1 3 5 
1 2 3 4 2 1 5 
1 2 1 5 4 3 
1 2 3 4 5 
1 3 2 4 5 
1 2 3 4 1 5 
1 2 3 2 4 1 5 
1 4 3 5 2 
1 3 2 4 5 
1 5 4 3 2 
1 2 3 4 5 
1 2 4 1 3 5 
1 4 2 5 3 
1 2 1 3 4 5 
1 2 1 3 
1 2 4 3 5 
1 2 3 5 4...

result:

wrong answer Participant didn't find permutation (test case 3)