Submission #866307

# Submission time Handle Problem Language Result Execution time Memory
866307 2023-10-25T20:35:47 Z epicci23 Volontiranje (COCI21_volontiranje) C++17
0 / 110
1 ms 344 KB
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define sz(x) ((int)(x).size())

constexpr int N = 1e6 + 5;

int fw[N];

void upd(int c,int x){
  for(;c<N;c+=c&-c) fw[c]=max(fw[c],x);
}

int query(int c,int res=0LL){
  for(;c;c-=c&-c) res=max(res,fw[c]);
  return res;
}

void solve(){
  int n;
  cin >> n;
  
  int ar[n+5];
  int dp[n+5];
  dp[0]=0;

  for(int i=1;i<=n;i++) cin >> ar[i];

  vector<array<int,2>> layer[n+5];

  for(int i=1;i<=n;i++){
    dp[i] = query(ar[i]) + 1;
    upd(ar[i],dp[i]);
    layer[dp[i]].pb({ar[i],i});
  }

  int lis = query(n);
  
  vector<vector<int>> ans;
  
  
  vector<int> poi(lis+5,0);
  int d = 1;

  vector<int> cur;
  cur.pb(layer[1][0][1]);
  bool ok = 1;

  while(!cur.empty() && ok){
    if(d==lis){
      ans.pb(cur);
      cur.clear();
      for(int i=1;i<=lis;i++){
        poi[i]++;
        if(poi[i]==sz(layer[i])) ok=0;
      }
      d=1;
      cur.pb(layer[d][poi[d]][1]);
      continue;
    }

    int ind = poi[d];
    while(poi[d+1] < sz(layer[d+1]) && layer[d+1][poi[d+1]][1] < layer[d][ind][1]) poi[d+1]++;
    if(poi[d+1]==sz(layer[d+1])) break;

    if(ar[cur.back()]<layer[d+1][poi[d+1]][0]){
     d++;  
     cur.pb(layer[d][poi[d]][1]);
    }
    else{
      cur.pop_back();
      poi[d]++;
      if(poi[d]==sz(layer[d])) break;
      d--;
    }
  }


  cout << sz(ans) << " " << lis << endl;

  for(auto u : ans){
    for(int x : u) cout << x << " ";
    cout << endl;
  }
}


int32_t main(){

  ios::sync_with_stdio(0);
  cin.tie(0);

  int t=1;//cin >> t;
  while(t--) solve();
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Integer parameter [name=number of subsequences] equals to 0, violates the range [1, 7]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Integer parameter [name=number of subsequences] equals to 0, violates the range [1, 7]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Integer parameter [name=number of subsequences] equals to 0, violates the range [1, 7]
2 Halted 0 ms 0 KB -