QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#457816#8837. Increasing Incomeucup-team133#WA 0ms3512kbC++174.5kb2024-06-29 14:13:272024-06-29 14:13:28

Judging History

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

  • [2024-06-29 14:13:28]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3512kb
  • [2024-06-29 14:13:27]
  • 提交

answer

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <random>
#include <stdio.h>
#include <fstream>
#include <functional>
#include <cassert>
#include <unordered_map>
#include <bitset>
#include <chrono>




using namespace std;







#define rep(i,n) for (int i=0;i<n;i+=1)
#define rrep(i,n) for (int i=n-1;i>-1;i--)
#define pb push_back
#define all(x) (x).begin(), (x).end()

#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << " )\n";

template<class T>
using vec = vector<T>;
template<class T>
using vvec = vec<vec<T>>;
template<class T>
using vvvec = vec<vvec<T>>;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;


template<class T>
bool chmin(T &a, T b){
  if (a>b){
    a = b;
    return true;
  }
  return false;
}

template<class T>
bool chmax(T &a, T b){
  if (a<b){
    a = b;
    return true;
  }
  return false;
}

template<class T>
T sum(vec<T> x){
  T res=0;
  for (auto e:x){
    res += e;
  }
  return res;
}

template<class T>
void printv(vec<T> x){
  for (auto e:x){
    cout<<e<<" ";
  }
  cout<<endl;
}



template<class T,class U>
ostream& operator<<(ostream& os, const pair<T,U>& A){
  os << "(" << A.first <<", " << A.second << ")";
  return os;
}

template<class T>
ostream& operator<<(ostream& os, const set<T>& S){
  os << "set{";
  for (auto a:S){
    os << a;
    auto it = S.find(a);
    it++;
    if (it!=S.end()){
      os << ", ";
    }
  }
  os << "}";
  return os;
}

template<class T>
ostream& operator<<(ostream& os, const tuple<T,T,T>& a){
  auto [x,y,z] = a;
  os << "(" << x << ", " << y << ", " << z << ")";
  return os;
}

template<class T>
ostream& operator<<(ostream& os, const map<ll,T>& A){
  os << "map{";
  for (auto e:A){
    os << e.first;
    os << ":";
    os << e.second;
    os << ", ";
  }
  os << "}";
  return os;
}

template<class T>
ostream& operator<<(ostream& os, const vec<T>& A){
  os << "[";
  rep(i,A.size()){
    os << A[i];
    if (i!=A.size()-1){
      os << ", ";
    }
  }
  os << "]" ;
  return os;
}

template <typename T>
std::vector<int> longest_increasing_subsequence_restore(const std::vector<T>& a, bool strict = true) {
    int n = a.size();
    std::vector<T> lis;
    std::vector<int> pre(n, -1);
    lis.reserve(n);
    for (int i = 0; i < n; i++) {
        auto it = (strict ? lower_bound(lis.begin(), lis.end(), i, [&](int x, int y) { return a[x] < a[y]; })
                          : upper_bound(lis.begin(), lis.end(), i, [&](int x, int y) { return a[x] < a[y]; }));
        if (it == lis.end())
            lis.emplace_back(i);
        else
            *it = i;
        if (it != lis.begin()) pre[i] = *std::prev(it);
    }
    std::vector<int> res;
    for (int cur = lis.back(); cur != -1; cur = pre[cur]) res.emplace_back(cur);
    res.push_back(-1);
    std::reverse(res.begin(), res.end());
    return res;
}


void solve(){
  int N;
  cin>>N;
  vec<int> P(N),pos(N);
  rep(i,N){
    cin>>P[i];
    P[i]--;
    pos[P[i]] = i;
  }

  vec<int> LIS_Q = longest_increasing_subsequence_restore(P);
  LIS_Q.push_back(N);

  vec<int> LIS_P = {-1};
  for (int i=1;i<int(LIS_Q.size())-1;i++){
    LIS_P.push_back(P[LIS_Q[i]]);
  }
  LIS_P.push_back(N);

  //debug(LIS_P);
  //debug(LIS_Q);
  

  int K = int(LIS_P.size()) - 2;

  vec<vec<int>> P_mid(K+1),Q_mid(K+1);
  for (int i=0;i<K+1;i++){
    int L = LIS_Q[i] + 1, R = LIS_Q[i+1] - 1;
    int check = LIS_P[i];
    for (int idx = L; idx <= R; idx++){
      if (P[idx] > check){
        int insert_pidx = lower_bound(all(LIS_P),P[idx]) - LIS_P.begin();
        P_mid[insert_pidx-1].push_back(idx);
      }
      else{
        Q_mid[i].push_back(idx);
      }
    }
  }

  //debug(P_mid);
  //debug(Q_mid);

  vec<int> res;
  for (int i=0;i<K+1;i++){
    if (i!=0){
      res.push_back(LIS_Q[i]);
    }
    sort(all(Q_mid[i]));
    sort(all(P_mid[i]));
    for (auto x:Q_mid[i]){
      res.push_back(x);
    }
    for (auto x:P_mid[i]){
      res.push_back(x);
    }
  }

  rep(i,N){
    cout << res[i]+1;
    if (i == N-1){
      cout << "\n";
    }
    else{
      cout << " ";
    }
  }




  


}



int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  cout << fixed << setprecision(15);


  int T;
  cin>>T;
  while (T--){
    solve();
  }
    
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

result:

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