QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#463965#8837. Increasing IncomeCryingWA 0ms13956kbC++141.7kb2024-07-05 16:52:492024-07-05 16:52:49

Judging History

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

  • [2024-07-05 16:52:49]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:13956kb
  • [2024-07-05 16:52:49]
  • 提交

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);
    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++){
        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: 100
Accepted
time: 0ms
memory: 13892kb

input:

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

output:

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

result:

ok Correct (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 13956kb

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

result:

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