QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#463988#8837. Increasing IncomeCryingWA 0ms14464kbC++141.8kb2024-07-05 17:06:462024-07-05 17:06:47

Judging History

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

  • [2024-07-05 17:06:47]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:14464kb
  • [2024-07-05 17:06:46]
  • 提交

answer

#include<bits/stdc++.h>
#define lowbit(x) (x&(-x))
using namespace std;
typedef long long ll;
const int MAXN = 2e5+10,INF = 1e9;
template<typename T>void tomin(T& x,T y){x = min(x,y);}
template<typename T>void tomax(T& x,T y){x = max(x,y);}
//
int T,n,p[MAXN],q[MAXN];

int dp[MAXN],pre[MAXN];

struct BIT{
    int t[MAXN],p[MAXN];
    void reset(){fill(t+1,t+1+n,0);fill(p+1,p+1+n,0);}
    void mdf(int x,int v){
        int tmp = x;
        for(;x<=n;x+=lowbit(x))if(t[x] < v){
            t[x] = v; p[x] = tmp;
        }
    }
    int qry(int x){
        int S=0,pos=0;
        for(;x;x-=lowbit(x))if(S<t[x]){
            S = t[x]; pos = p[x];
        }
        return pos;
    }
}bit;

int arr[MAXN],vis[MAXN],tot;
vector<int> o[MAXN];

void solve(){
    cin>>n;
    for(int i=1;i<=n;i++)cin>>p[i],q[p[i]] = i,vis[i] = 0,o[i].clear();
    bit.reset();
    for(int i=1;i<=n;i++){
        pre[i] = bit.qry(q[i]);
        dp[i] = dp[p[pre[i]]]+1;
        bit.mdf(q[i],dp[i]);
    }
    int pos = 0; for(int i=1;i<=n;i++)if(dp[i] > dp[pos])pos = i;

    tot = 0;
    for(int u=pos;u;u=p[pre[u]])arr[++tot] = q[u],vis[u] = 1;
    reverse(arr+1,arr+1+tot);
    //for(int i=1;i<=tot;i++)cout<<arr[i]<<" "; cout<<endl;
    int mx = 0,cnt = 0;
    for(int i=1;i<=n;i++)if(vis[i])mx = q[i],cnt++;else{
        if(q[i] < mx)o[cnt].push_back(q[i]);
        else{
            int pos = lower_bound(arr+1,arr+1+tot,q[i])-arr-1;
            o[pos].push_back(q[i]);
        }
    }
    for(int i=1;i<=tot;i++){
        sort(o[i].begin(),o[i].end());
        cout<<arr[i]<<" "; for(auto u : o[i])cout<<u<<" ";
    }
    cout<<"\n";
}
int main(){
    ios::sync_with_stdio(false); cin.tie(0);

    cin>>T;
    while(T--)solve();

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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 2 4 

result:

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