답안 #780932

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
780932 2023-07-12T14:46:19 Z cig32 Volontiranje (COCI21_volontiranje) C++17
0 / 110
1 ms 212 KB
#include "bits/stdc++.h"
using namespace std;
#define int long long
const int MAXN = 1e6 + 10;
const int MOD = 998244353;
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
  int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
int bm(int b, int p) {
  if(p==0) return 1 % MOD;
  int r = bm(b, p >> 1);
  if(p&1) return (((r*r) % MOD) * b) % MOD;
  return (r*r) % MOD;
}
int inv(int b) { 
  return bm(b, MOD-2);
}
int fastlog(int x) {
  return (x == 0 ? -1 : 64 - __builtin_clzll(x) - 1);
}
void printcase(int i) { cout << "Case #" << i << ": "; }
void solve(int tc){
  int n;
  cin>>n;
  int p[n+1];
  for(int i=1;i<=n;i++)cin>>p[i];
  int dp[n+1];
  int bucket[n+1];
  for(int i=1;i<=n;i++)bucket[i]=1e9,dp[i]=1;
  for(int i=1;i<=n;i++){
    auto it=lower_bound(bucket+1,bucket+1+n,p[i]);
    dp[i]=distance(bucket,it);
    bucket[dp[i]]=min(bucket[dp[i]],p[i]);
  }
  int lis=0;
  for(int i=1;i<=n;i++)lis=max(lis,dp[i]);
  int pos[n+1];
  for(int i=1;i<=n;i++)pos[p[i]]=i;
  bool used[n+1];
  for(int i=1;i<=n;i++)used[i]=0;
  vector<vector<int>>ans;
  vector<int>ok[n+1];
  for(int i=1;i<=n;i++)ok[dp[i]].push_back(i);
  for(int x:ok[lis]){
    vector<int>seq;
    seq.push_back(x);
    used[x]=1;
    for(int i=lis-1;i>=1;i--){
      int lb=0,rb=ok[i].size()-1;
      while(lb<rb){
        int mid=(lb+rb)>>1;
        if(p[ok[i][mid]]>p[seq.back()]) lb=mid+1;
        else rb=mid;
      }
      if(p[ok[i][lb]]>p[seq.back()]) break;
      for(int j=lb; j<ok[i].size(); j++) {
        if(!used[ok[i][j]]) {
          used[ok[i][j]]=1;
          seq.push_back(ok[i][j]);
          break;
        }
      }
    }
    reverse(seq.begin(),seq.end());
    if(seq.size()==lis) ans.push_back(seq);
  }
  cout<<ans.size()<<" "<<lis<<"\n";
  for(vector<int>v:ans){
    for(int x:v)cout<<x<<" ";
    cout<<"\n";
  }
}
int32_t main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int t = 1; //cin >> t;
  for(int i=1; i<=t; i++) solve(i);
}
// 勿忘初衷

Compilation message

Main.cpp: In function 'void solve(long long int)':
Main.cpp:57:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |       for(int j=lb; j<ok[i].size(); j++) {
      |                     ~^~~~~~~~~~~~~
Main.cpp:66:18: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   66 |     if(seq.size()==lis) ans.push_back(seq);
      |        ~~~~~~~~~~^~~~~
Main.cpp:38:7: warning: variable 'pos' set but not used [-Wunused-but-set-variable]
   38 |   int pos[n+1];
      |       ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Incorrect 0 ms 212 KB Subsequence indices should be sorted
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Incorrect 0 ms 212 KB Subsequence indices should be sorted
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Incorrect 0 ms 212 KB Subsequence indices should be sorted
15 Halted 0 ms 0 KB -