/*
In the name of Allah
made by: Ahmed_Solyman
*/
#include <bits/stdc++.h>
#include <ext/rope>
using namespace std;
using namespace __gnu_cxx;
#pragma GCC optimize("-Ofast")
#pragma GCC optimize("-O1")
//-------------------------------------------------------------//
typedef long long ll;
typedef unsigned long long ull;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI acos(-1)
#define lb lower_bound
#define ub upper_bound
#define endl '\n'
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define sum_to(n) (n*(n+1))/2
#define pb push_back
#define pf push_front
#define fil(arr,x) memset(arr,x,sizeof(arr))
const ll mod=1e9+7;
int dx[8]={0,1,0,-1,1,1,-1,-1};
int dy[8]={1,0,-1,0,1,-1,-1,1};
//-------------------------------------------------------------//
ll lcm(ll a,ll b)
{
return (max(a,b)/__gcd(a,b))*min(a,b);
}
void person_bool(bool x)
{
cout<<(x?"YES":"NO")<<endl;
}
map<int,bool>vis;
vector<int> LIS(vector<int>p){
vector<int>arr;
for(auto i:p){
if(!vis[i])arr.push_back(i);
}
set<int>s;
int n=arr.size();
int next[p.size()+1]={},dp[p.size()+1]={};
for(int i=0;i<n;i++){
if(!s.size()){
next[arr[i]]=arr[i];
dp[arr[i]]=1;
}
else{
auto iter=s.ub(arr[i]);
if(iter==s.begin()){
next[arr[i]]=arr[i];
dp[arr[i]]=1;
}
else{
iter--;
next[arr[i]]=*iter;
dp[arr[i]]=dp[*iter]+1;
}
}
s.insert(arr[i]);
}
int mx=0;
for(int i=p.size();i>=1;i--){
mx=max(mx,dp[i]);
}
vector<int>v;
for(int i=1;i<=p.size();i++){
if(mx==dp[i]){
v.push_back(i);
int j=i;
while(next[j]!=j){
j=next[j];
v.push_back(j);
}
reverse(all(v));
break;
}
}
for(auto i:v){
vis[i]=1;
}
return v;
}
void run(){
#ifndef ONLINE_JUDGE
freopen("input.in", "r", stdin);
freopen("output.out", "w", stdout);
#endif
}
int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
fast
//run();
int n;cin>>n;
vector<int>arr(n);
map<int,int>mp;
int j=1;
for(auto &i:arr)cin>>i,mp[i]=j++;
int lis=LIS(arr).size();
for(auto i:arr)vis[i]=0;
int cnt=0;
vector<vector<int>>ans;
while(1){
vector<int>v=LIS(arr);
if(v.size()==lis){
cnt++;
ans.push_back(v);
}
else{
break;
}
}
cout<<cnt<<" "<<lis<<endl;
for(auto i:ans){
for(auto j:i)cout<<mp[j]<<" ";
cout<<endl;
}
return 0;
}
Compilation message
Main.cpp: In function 'std::vector<int> LIS(std::vector<int>)':
Main.cpp:71:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for(int i=1;i<=p.size();i++){
| ~^~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:111:14: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
111 | if(v.size()==lis){
| ~~~~~~~~^~~~~
Main.cpp: In function 'void run()':
Main.cpp:90:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
90 | freopen("input.in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:91:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
91 | freopen("output.out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
length of the longest increasing subsequence doesn't match |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
length of the longest increasing subsequence doesn't match |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
length of the longest increasing subsequence doesn't match |
5 |
Halted |
0 ms |
0 KB |
- |