Submission #853535

# Submission time Handle Problem Language Result Execution time Memory
853535 2023-09-24T14:28:56 Z NotLinux Volontiranje (COCI21_volontiranje) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
struct SEGT{
	vector < int > tree;
	int sz;
	SEGT(int x){
		x += 5;
		sz += x;
		tree.assign(4 * sz);
	}
	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);
	}
};
void solve(){
	int n;
	cin >> n;
	int arr[n],lis[n],nxt[n],mx = 0;
	SEGT segt(n);
	priority_queue < pair < int , int > , greater < int > > q[n+1];
	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({arr[i],i});
		segt.update(arr[i],lis[i]);
	}
	for(int i = n;i>0;i--){
		vector < pair < int , int > > willadd;
		while(q[i].size()){
			pair < int , int > cur = q[i].front();
			q[i].pop();
			int child = -1;
			while(q[i-1].size()){
				pair < int , int > cand = q[i-1].front();
				q[i-1].pop();
				if(cand.second < cur.second){
					willadd.push_back(cand);
					child = cand.second;
					break;
				}
			}
			if(child != -1){
				nxt[child] = cur.second;
			}
		}
		for(auto itr : willadd){
			q[i-1].push(itr);
		}
	}
	int valid[n];
	vector < vector < int > > ans;
	for(int i = n-1;i>=0;i--){
		if(nxt[i] == -1){
			valid[i] = 1;
		}
		else{
			valid[i] = valid[nxt[i]] + 1;
		}

		if(valid[i] == mx){
			vector < int > locans;
			int cur = i;
			do {
				locans.push_back(cur);
				cur = nxt[cur];
			} while(cur != -1);
		}
	}
	cout << ans.size() << " " << mx << '\n';
	for(auto itr : ans){
		for(auto itr1 : itr){
			cout << itr1 << " ";
		}
		cout << '\n';
	}
}
signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int testcase = 1;//cin >> testcase;
	while(testcase--)solve();
}

Compilation message

Main.cpp: In constructor 'SEGT::SEGT(int)':
Main.cpp:9:21: error: no matching function for call to 'std::vector<int>::assign(int)'
    9 |   tree.assign(4 * sz);
      |                     ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from Main.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:749:7: note: candidate: 'void std::vector<_Tp, _Alloc>::assign(std::vector<_Tp, _Alloc>::size_type, const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::size_type = long unsigned int; std::vector<_Tp, _Alloc>::value_type = int]'
  749 |       assign(size_type __n, const value_type& __val)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:749:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/10/bits/stl_vector.h:768:2: note: candidate: 'template<class _InputIterator, class> void std::vector<_Tp, _Alloc>::assign(_InputIterator, _InputIterator) [with _InputIterator = _InputIterator; <template-parameter-2-2> = <template-parameter-1-2>; _Tp = int; _Alloc = std::allocator<int>]'
  768 |  assign(_InputIterator __first, _InputIterator __last)
      |  ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:768:2: note:   template argument deduction/substitution failed:
Main.cpp:9:21: note:   candidate expects 2 arguments, 1 provided
    9 |   tree.assign(4 * sz);
      |                     ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from Main.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:794:7: note: candidate: 'void std::vector<_Tp, _Alloc>::assign(std::initializer_list<_Tp>) [with _Tp = int; _Alloc = std::allocator<int>]'
  794 |       assign(initializer_list<value_type> __l)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:794:43: note:   no known conversion for argument 1 from 'int' to 'std::initializer_list<int>'
  794 |       assign(initializer_list<value_type> __l)
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
Main.cpp: In member function 'int SEGT::_query(int, int, int, int, int)':
Main.cpp:37:38: error: no matching function for call to 'SEGT::query(int, int&, int&, int&, int&)'
   37 |    return max(query(ind*2,l,mid,ql,qr) , query(ind*2+1,mid+1,r,ql,qr));
      |                                      ^
Main.cpp:40:6: note: candidate: 'int SEGT::query(int, int)'
   40 |  int query(int l , int r){
      |      ^~~~~
Main.cpp:40:6: note:   candidate expects 2 arguments, 5 provided
Main.cpp:37:69: error: no matching function for call to 'SEGT::query(int, int, int&, int&, int&)'
   37 |    return max(query(ind*2,l,mid,ql,qr) , query(ind*2+1,mid+1,r,ql,qr));
      |                                                                     ^
Main.cpp:40:6: note: candidate: 'int SEGT::query(int, int)'
   40 |  int query(int l , int r){
      |      ^~~~~
Main.cpp:40:6: note:   candidate expects 2 arguments, 5 provided
Main.cpp: In function 'void solve()':
Main.cpp:49:56: error: no type named 'value_type' in 'struct std::greater<int>'
   49 |  priority_queue < pair < int , int > , greater < int > > q[n+1];
      |                                                        ^
Main.cpp:49:56: error: template argument 3 is invalid
Main.cpp:54:13: error: request for member 'push' in 'q[lis[i]]', which is of non-class type 'int'
   54 |   q[lis[i]].push({arr[i],i});
      |             ^~~~
Main.cpp:59:14: error: request for member 'size' in 'q[i]', which is of non-class type 'int'
   59 |   while(q[i].size()){
      |              ^~~~
Main.cpp:60:34: error: request for member 'front' in 'q[i]', which is of non-class type 'int'
   60 |    pair < int , int > cur = q[i].front();
      |                                  ^~~~~
Main.cpp:61:9: error: request for member 'pop' in 'q[i]', which is of non-class type 'int'
   61 |    q[i].pop();
      |         ^~~
Main.cpp:63:17: error: request for member 'size' in 'q[(i - 1)]', which is of non-class type 'int'
   63 |    while(q[i-1].size()){
      |                 ^~~~
Main.cpp:64:38: error: request for member 'front' in 'q[(i - 1)]', which is of non-class type 'int'
   64 |     pair < int , int > cand = q[i-1].front();
      |                                      ^~~~~
Main.cpp:65:12: error: request for member 'pop' in 'q[(i - 1)]', which is of non-class type 'int'
   65 |     q[i-1].pop();
      |            ^~~
Main.cpp:77:11: error: request for member 'push' in 'q[(i - 1)]', which is of non-class type 'int'
   77 |    q[i-1].push(itr);
      |           ^~~~