Submission #853828

# Submission time Handle Problem Language Result Execution time Memory
853828 2023-09-25T09:53:37 Z NotLinux Volontiranje (COCI21_volontiranje) C++17
0 / 110
2 ms 8796 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
const int LIM = 1e7;
int sayac = 0;
struct SEGT{
	vector < int > tree;
	int sz;
	SEGT(int x){
		x += 5;
		sz = x;
		tree.assign(4 * sz , 0);
	}
	void _update(int ind , int l , int r , int qp , int qv){
		if(l == r){
			tree[ind] = qv;
			return;
		}
		int mid = (l+r)/2;
		if(mid >= qp){
			_update(ind*2,l,mid,qp,qv);
		}
		else{
			_update(ind*2+1,mid+1,r,qp,qv);
		}
		tree[ind] = max(tree[ind*2] , tree[ind*2+1]);
	}
	void update(int p , int v){
		_update(1,1,sz,p,v);
	}
	int _query(int ind , int l , int r , int ql , int qr){
		if(l >= ql and r <= qr){
			return tree[ind];
		}
		else if(l > qr or r < ql){
			return 0;
		}
		else{
			int mid = (l+r)/2;
			return max(_query(ind*2,l,mid,ql,qr) , _query(ind*2+1,mid+1,r,ql,qr));
		}
	}
	int query(int l , int r){
		return _query(1,1,sz,l,r);
	}
};
int n,arr[N],lis[N],nxt[N],mx = 0;
priority_queue < pair < int , int > > q[N];
vector < vector < int > > ans;
vector < int > locans;
bool dfs(int node){
	if(sayac++ > LIM){
		cout << "0 1" << endl;
		exit(0);
	}
	//cout << node << " " << arr[node] << endl;
	if(lis[node] == 1){
		locans.push_back(node);
		if(mx == 1){
			ans.push_back(locans);
			locans.clear();
		}
		return 1;
	}
	bool work = 0;
	while(q[lis[node]-1].size()){
		if(sayac++ > LIM){
			cout << "0 1" << endl;
			exit(0);
		}
		pair < int , int > cand = q[lis[node]-1].top();
		if(cand.first < node and cand.second < arr[node]){
			bool bl = dfs(cand.first);
			if(bl){
				work = 1;
				locans.push_back(node);
				q[lis[node]-1].pop();
				break;
			}
			else{
				q[lis[node]-1].pop();
			}
		}
		else if(cand.first > node and cand.second < arr[node]){
			q[lis[node]-1].pop();
		}
		else if(cand.first < node and cand.second > arr[node]){
			break;
		}
	}
	if(work == 0){
		return 0;
	}
	else if(work == 1 and lis[node] == mx){
		ans.push_back(locans);
		locans.clear();
	}
	return 1;
}
void solve(){
	memset(nxt , -1 , sizeof(nxt));
	cin >> n;
	SEGT segt(n);
	for(int i = 0;i<n;i++){
		cin >> arr[i];
		lis[i] = segt.query(1,arr[i]) + 1;
		mx = max(mx , lis[i]);
		q[lis[i]].push({i,arr[i]});
		segt.update(arr[i],lis[i]);
	}
	while(q[mx].size()){
		if(sayac++ > LIM){
			cout << "0 1" << endl;
			exit(0);
		}
		dfs(q[mx].top().first);
		q[mx].pop();
	}
	cout << ans.size() << " " << mx << endl;
	/*for(auto itr : ans){
		for(auto itr1 : itr){
			cout << itr1+1 << " ";
		}
		cout << endl;
	}*/
}
signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int testcase = 1;//cin >> testcase;
	while(testcase--)solve();
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8796 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8796 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8796 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -