QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#458329#8837. Increasing Incomeucup-team1338#WA 0ms11720kbC++201.3kb2024-06-29 16:41:142024-06-29 16:41:23

Judging History

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

  • [2024-06-29 16:41:23]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:11720kb
  • [2024-06-29 16:41:14]
  • 提交

answer

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int N=1000013;
const int mod=998244353;
int p[N],ip[N];
int g[N],pre[N];
vector<int>v[200012];
void solve(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>p[i],ip[p[i]]=i,g[i]=0,v[i].clear();
    vector<int>o,x;
    for(int i=1;i<=n;i++){
        if(o.empty()||o.back()<p[i]){
            o.push_back(p[i]);
            if(o.size()>1)pre[p[i]]=o[o.size()-2];
        }
        auto id=std::lower_bound(o.begin(), o.end(), p[i])-o.begin();
        o[id]=p[i];
    }
    int s=(int)o.size();
    for(int i=s-2;~i;i--)o[i]=pre[o[i+1]];
    for(int i=0;i<s;i++)x.push_back(ip[o[i]]),g[x.back()]=1;
    cout<<n+s<<'\n';
    for(int i=1;i<=n;i++)if(!g[i]){
        auto id=std::lower_bound(o.begin(), o.end(),p[i])-o.begin();
        auto id2=std::lower_bound(x.begin(),x.end(),i)-x.begin();
        v[max(id,id2)].push_back(i);
    }

    for(int i=0;i<s;i++){
        cout<<x[i]<<' ';
        std::sort(v[i+1].begin(), v[i+1].end(),[&](int f,int g){
            if((f>x[i])!=(g>x[i]))return ((f>x[i])<(g>x[i]));
            if(f>x[i])return f<g;
            return p[f]<p[g];
        });
        for(auto y:v[i+1])cout<<y<<' ';
    }
    cout<<'\n';
}

int main(){
    ios::sync_with_stdio(false);
    int T=1;
    cin>>T;
    while(T--)solve();
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 11720kb

input:

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

output:

6
1 2 3 
6
1 3 2 4 
8
1 3 5 4 2 

result:

wrong answer Integer element q[1] equals to 6, violates the range [1, 3] (test case 1)