Submission #943752

#TimeUsernameProblemLanguageResultExecution timeMemory
943752amirhoseinfar1385The Potion of Great Power (CEOI20_potion)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
using namespace std;
const int maxn=100000+10,maxd=40,maxq=50000+10;
int te=0,n,d,high[maxn];
struct cmp {
    bool operator() (int a, int b) const {
        if(high[a]!=high[b]){
        	return high[a]<high[b];
        }
        return a<b;
    }
};
struct hams{
	vector<int>timea;
	vector<vector<pair<int,int>>>allq;
	vector<set<int>>fi;
	set<int,cmp>st;
	hams(){
		timea.resize(1,0);
		allq.resize(1);
		fi.push_back(st);
	}
	void ins(int u){
		if(st.count(u)==1){
			allq.back().push_back(make_pair(te,-u));
			st.erase(u);
		}else{
			allq.back().push_back(make_pair(te,u));
			st.insert(u);
		}
		if((int)allq.back().size()==maxd){
			timea.push_back(te);
			allq.push_back({});
			fi.push_back(st);
		}
	}
	vector<int>pors(int w){
		int p=upper_bound(timea.begin(),timea.end(),w)-timea.begin();
		p--;
		set<int>fake=fi[p];
		for(auto x:allq[p]){
			if(x.first>w){
				break;
			}
			if(x.second<0){
				fake.erase(-x.second);
			}else{
				fake.insert(x.second);
			}
		}
		vector<int>ret;
		for(auto x:fake){
			ret.push_back(x);
		}
		return ret;
	}
}alle[maxn];

void init(int N, int D, int H[]) {
	n=N;
	d=D;
	for(int i=0;i<n;i++){
		high[i]=H[i];
	}
}

void curseChanges(int U, int A[], int B[]) {
	for(int i=1;i<=U;i++){
		te=i;
		alle[A[i-1]].ins(B[i-1]);
		alle[B[i-1]].ins(A[i-1]);
	}
}

bool cmp(int a,int b){
	return high[a]<high[b];
}

int question(int x, int y, int v) {
    vector<int>av=alle[x].pors(v);
    vector<int>dov=alle[y].pors(v);
    int i=0,j=0;
    if((int)av.size()==0||(int)dov.size()==0){
    	return 1000000000;
    }
    int res=1e9;
    while(i<(int)av.size()&&j<(int)dov.size()){
    	res=min(res,abs(high[av[i]]-high[dov[j]]));
    	if(high[av[i]]<high[dov[j]]){
    		i++;
    	}else{
    		j++;
    	}
    }
  	return res;
}

Compilation message (stderr)

potion.cpp: In constructor 'hams::hams()':
potion.cpp:21:18: error: no matching function for call to 'std::vector<std::set<int> >::push_back(std::set<int, cmp>&)'
   21 |   fi.push_back(st);
      |                  ^
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 potion.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::set<int>; _Alloc = std::allocator<std::set<int> >; std::vector<_Tp, _Alloc>::value_type = std::set<int>]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from 'std::set<int, cmp>' to 'const value_type&' {aka 'const std::set<int>&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::set<int>; _Alloc = std::allocator<std::set<int> >; std::vector<_Tp, _Alloc>::value_type = std::set<int>]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from 'std::set<int, cmp>' to 'std::vector<std::set<int> >::value_type&&' {aka 'std::set<int>&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
potion.cpp: In member function 'void hams::ins(int)':
potion.cpp:34:19: error: no matching function for call to 'std::vector<std::set<int> >::push_back(std::set<int, cmp>&)'
   34 |    fi.push_back(st);
      |                   ^
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 potion.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::set<int>; _Alloc = std::allocator<std::set<int> >; std::vector<_Tp, _Alloc>::value_type = std::set<int>]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from 'std::set<int, cmp>' to 'const value_type&' {aka 'const std::set<int>&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::set<int>; _Alloc = std::allocator<std::set<int> >; std::vector<_Tp, _Alloc>::value_type = std::set<int>]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from 'std::set<int, cmp>' to 'std::vector<std::set<int> >::value_type&&' {aka 'std::set<int>&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~