Submission #862249

# Submission time Handle Problem Language Result Execution time Memory
862249 2023-10-17T20:40:48 Z Ahmed_Solyman Volontiranje (COCI21_volontiranje) C++14
0 / 110
1000 ms 7888 KB
/*
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;
}
vector<int>a(100005);
struct segtree{
	vector<ll>tree;
	int size;
	void init(int n){
		size=n;
		tree.assign(n*4+5,0);
	}
	void set(int l,int r,int p,int i,int v){
		if(l>r){
			return;
		}
		if(l==r){
			tree[p]=v;
			return;
		}
		int mid=(l+r)/2;
		if(i>mid){
			set(mid+1,r,p*2+1,i,v);
		}
		else{
			set(l,mid,p*2,i,v);
		}
		tree[p]=max(tree[p*2],tree[p*2+1]);
	}
	void set(int i,int v){
		set(1,size,1,i,v);
	}
	int query(int l,int r,int p,int l_q,int r_q){
		if(l>=l_q && r<=r_q){
			return tree[p];
		}
		if(r<l_q || l>r_q){
			return 0;
		}
		int mid=(l+r)/2;
		return max(query(l,mid,p*2,l_q,r_q),query(mid+1,r,p*2+1,l_q,r_q));
	}
	int query(int l,int r){
		return query(1,size,1,l,r);
	}
};
map<int,bool>vis;
vector<int> LIS(vector<int>p){
	vector<int>arr;
	for(auto i:p){
		if(!vis[i])arr.push_back(i);
	}
	segtree s;
	s.init(p.size());
	int n=arr.size();
	int next[p.size()+1]={},dp[p.size()+1]={};
	vector<set<int>>d(p.size()+1);
	for(int i=n-1;i>=0;i--){
		int mx=s.query(arr[i],p.size());
		if(!mx){
			next[arr[i]]=arr[i];
			dp[arr[i]]=1;
			s.set(arr[i],1);
			d[1].insert(arr[i]);
		}
		else{
			next[arr[i]]=*(d[mx].upper_bound(arr[i]));
			dp[arr[i]]=dp[next[arr[i]]]+1;
			s.set(arr[i],dp[arr[i]]);
			d[dp[arr[i]]].insert(arr[i]);
		}
	}
	int i=*(d[s.query(1,p.size())].begin());
	if(i==0){
		return {};
	}
	vector<int>v;
	v.push_back(i);
	vis[i]=1;
	while(next[i]!=i){
		i=next[i];vis[i]=1;
		v.push_back(i);
	}
	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 'int main()':
Main.cpp:142:14: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  142 |   if(v.size()==lis){
      |      ~~~~~~~~^~~~~
Main.cpp: In function 'void run()':
Main.cpp:121:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  121 |     freopen("input.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:122:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  122 |     freopen("output.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1045 ms 7888 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1045 ms 7888 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1045 ms 7888 KB Time limit exceeded
2 Halted 0 ms 0 KB -