Submission #853880

# Submission time Handle Problem Language Result Execution time Memory
853880 2023-09-25T11:44:04 Z NotLinux Volontiranje (COCI21_volontiranje) C++14
110 / 110
402 ms 148576 KB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
const int N = 1e6 + 7;
struct SEGT{
	vector < int > tree;
	int sz;
	SEGT(int x){
		x += 5;
		sz = x;
		tree.assign(4 * sz , 0);
	}
	inline 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);
	}
	inline 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;
vector < pair < int , int > > q[N];
vector < vector < int > > ans;
vector < int > locans;
inline bool dfs(int node){
	//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()){
		pair < int , int > cand = q[lis[node]-1].back();
		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_back();
				break;
			}
			else{
				q[lis[node]-1].pop_back();
			}
		}
		else if(cand.first > node and cand.second < arr[node]){
			q[lis[node]-1].pop_back();
		}
		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_back({i,arr[i]});
		segt.update(arr[i],lis[i]);
	}
	for(int i = 0;i<N;i++){
		sort(q[i].begin() , q[i].end());
	}
	while(q[mx].size()){
		dfs(q[mx].back().first);
		q[mx].pop_back();
	}
	cout << ans.size() << " " << mx << '\n';
	for(auto itr : ans){
		for(auto itr1 : itr){
			cout << itr1+1 << " ";
		}
		cout << '\n';
	}
}
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 Correct 7 ms 31320 KB Output is correct
2 Correct 8 ms 31520 KB Output is correct
3 Correct 7 ms 31324 KB Output is correct
4 Correct 7 ms 31320 KB Output is correct
5 Correct 8 ms 31320 KB Output is correct
6 Correct 7 ms 31320 KB Output is correct
7 Correct 7 ms 31320 KB Output is correct
8 Correct 8 ms 31320 KB Output is correct
9 Correct 8 ms 31324 KB Output is correct
10 Correct 9 ms 31324 KB Output is correct
11 Correct 7 ms 31320 KB Output is correct
12 Correct 8 ms 31320 KB Output is correct
13 Correct 8 ms 31320 KB Output is correct
14 Correct 7 ms 31320 KB Output is correct
15 Correct 7 ms 31320 KB Output is correct
16 Correct 8 ms 31320 KB Output is correct
17 Correct 7 ms 31324 KB Output is correct
18 Correct 8 ms 31320 KB Output is correct
19 Correct 8 ms 31320 KB Output is correct
20 Correct 7 ms 31828 KB Output is correct
21 Correct 7 ms 31320 KB Output is correct
22 Correct 8 ms 31320 KB Output is correct
23 Correct 7 ms 31324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 31320 KB Output is correct
2 Correct 8 ms 31520 KB Output is correct
3 Correct 7 ms 31324 KB Output is correct
4 Correct 7 ms 31320 KB Output is correct
5 Correct 8 ms 31320 KB Output is correct
6 Correct 7 ms 31320 KB Output is correct
7 Correct 7 ms 31320 KB Output is correct
8 Correct 8 ms 31320 KB Output is correct
9 Correct 8 ms 31324 KB Output is correct
10 Correct 9 ms 31324 KB Output is correct
11 Correct 7 ms 31320 KB Output is correct
12 Correct 8 ms 31320 KB Output is correct
13 Correct 8 ms 31320 KB Output is correct
14 Correct 7 ms 31320 KB Output is correct
15 Correct 7 ms 31320 KB Output is correct
16 Correct 8 ms 31320 KB Output is correct
17 Correct 7 ms 31324 KB Output is correct
18 Correct 8 ms 31320 KB Output is correct
19 Correct 8 ms 31320 KB Output is correct
20 Correct 7 ms 31828 KB Output is correct
21 Correct 7 ms 31320 KB Output is correct
22 Correct 8 ms 31320 KB Output is correct
23 Correct 7 ms 31324 KB Output is correct
24 Correct 8 ms 31320 KB Output is correct
25 Correct 8 ms 31324 KB Output is correct
26 Correct 8 ms 31320 KB Output is correct
27 Correct 7 ms 31524 KB Output is correct
28 Correct 8 ms 31320 KB Output is correct
29 Correct 8 ms 31320 KB Output is correct
30 Correct 7 ms 31320 KB Output is correct
31 Correct 8 ms 31324 KB Output is correct
32 Correct 8 ms 31320 KB Output is correct
33 Correct 8 ms 31320 KB Output is correct
34 Correct 8 ms 31320 KB Output is correct
35 Correct 8 ms 31320 KB Output is correct
36 Correct 8 ms 31320 KB Output is correct
37 Correct 8 ms 31320 KB Output is correct
38 Correct 8 ms 31324 KB Output is correct
39 Correct 7 ms 31320 KB Output is correct
40 Correct 8 ms 31320 KB Output is correct
41 Correct 7 ms 31320 KB Output is correct
42 Correct 7 ms 31320 KB Output is correct
43 Correct 7 ms 31324 KB Output is correct
44 Correct 8 ms 31320 KB Output is correct
45 Correct 9 ms 31576 KB Output is correct
46 Correct 7 ms 31320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 31320 KB Output is correct
2 Correct 8 ms 31520 KB Output is correct
3 Correct 7 ms 31324 KB Output is correct
4 Correct 7 ms 31320 KB Output is correct
5 Correct 8 ms 31320 KB Output is correct
6 Correct 7 ms 31320 KB Output is correct
7 Correct 7 ms 31320 KB Output is correct
8 Correct 8 ms 31320 KB Output is correct
9 Correct 8 ms 31324 KB Output is correct
10 Correct 9 ms 31324 KB Output is correct
11 Correct 7 ms 31320 KB Output is correct
12 Correct 8 ms 31320 KB Output is correct
13 Correct 8 ms 31320 KB Output is correct
14 Correct 7 ms 31320 KB Output is correct
15 Correct 7 ms 31320 KB Output is correct
16 Correct 8 ms 31320 KB Output is correct
17 Correct 7 ms 31324 KB Output is correct
18 Correct 8 ms 31320 KB Output is correct
19 Correct 8 ms 31320 KB Output is correct
20 Correct 7 ms 31828 KB Output is correct
21 Correct 7 ms 31320 KB Output is correct
22 Correct 8 ms 31320 KB Output is correct
23 Correct 7 ms 31324 KB Output is correct
24 Correct 8 ms 31320 KB Output is correct
25 Correct 8 ms 31324 KB Output is correct
26 Correct 8 ms 31320 KB Output is correct
27 Correct 7 ms 31524 KB Output is correct
28 Correct 8 ms 31320 KB Output is correct
29 Correct 8 ms 31320 KB Output is correct
30 Correct 7 ms 31320 KB Output is correct
31 Correct 8 ms 31324 KB Output is correct
32 Correct 8 ms 31320 KB Output is correct
33 Correct 8 ms 31320 KB Output is correct
34 Correct 8 ms 31320 KB Output is correct
35 Correct 8 ms 31320 KB Output is correct
36 Correct 8 ms 31320 KB Output is correct
37 Correct 8 ms 31320 KB Output is correct
38 Correct 8 ms 31324 KB Output is correct
39 Correct 7 ms 31320 KB Output is correct
40 Correct 8 ms 31320 KB Output is correct
41 Correct 7 ms 31320 KB Output is correct
42 Correct 7 ms 31320 KB Output is correct
43 Correct 7 ms 31324 KB Output is correct
44 Correct 8 ms 31320 KB Output is correct
45 Correct 9 ms 31576 KB Output is correct
46 Correct 7 ms 31320 KB Output is correct
47 Correct 148 ms 44180 KB Output is correct
48 Correct 156 ms 46676 KB Output is correct
49 Correct 208 ms 51024 KB Output is correct
50 Correct 374 ms 62252 KB Output is correct
51 Correct 82 ms 37484 KB Output is correct
52 Correct 375 ms 148576 KB Output is correct
53 Correct 383 ms 121772 KB Output is correct
54 Correct 329 ms 76880 KB Output is correct
55 Correct 402 ms 76880 KB Output is correct
56 Correct 10 ms 31576 KB Output is correct
57 Correct 293 ms 62436 KB Output is correct
58 Correct 66 ms 37456 KB Output is correct
59 Correct 57 ms 36688 KB Output is correct
60 Correct 293 ms 62800 KB Output is correct
61 Correct 192 ms 53144 KB Output is correct
62 Correct 7 ms 31320 KB Output is correct
63 Correct 8 ms 31320 KB Output is correct
64 Correct 8 ms 31320 KB Output is correct
65 Correct 7 ms 31320 KB Output is correct
66 Correct 8 ms 31320 KB Output is correct
67 Correct 7 ms 31320 KB Output is correct
68 Correct 8 ms 31320 KB Output is correct
69 Correct 7 ms 31324 KB Output is correct