求助:关于奇奇怪怪的 CE
  • 板块学术版
  • 楼主Otomachi_Una_
  • 当前回复4
  • 已保存回复4
  • 发布时间2022/1/27 21:54
  • 上次更新2023/10/28 10:41:49
查看原帖
求助:关于奇奇怪怪的 CE
248400
Otomachi_Una_楼主2022/1/27 21:54

源代码

#include<iostream>
#include<map>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
#define ll long long
const int MAXN=4e4+5;
const int MR=1e5+5;
int n,m,u,v,sq;
int tot=0,cnt=0,ans=0;
vector<int> ve[MAXN];
int p[MAXN];
int seq[2*MAXN],res[MAXN];
int sz[MAXN],dep[MAXN];
int st[MAXN],ed[MAXN];//st:进栈,ed出栈 
int faq[MAXN],anc[MAXN],sn[MAXN];//树刨祖先,链下儿子 
int que[MAXN];
bool used[MAXN];
map <int,int> M;
struct ask{
	int id,l,r,lca;
}a[MAXN];
bool cmp(ask x,ask y){
	if(x.l/sq!=y.l/sq) return x.l<y.l;
	else if(x.l/sq&1) return x.r<y.r;
	return x.r>y.r;
}
void init(){
	for(int i=1;i<=n;i++){
		if(!M[p[i]])
			M[p[i]]=++cnt;
		p[i]=M[p[i]];
	}
	return;//离散化 
}
void dfs(int u,int fa){
	faq[u]=fa;
	st[u]=++tot;
	seq[tot]=p[u];
	sz[u]=1;
	for(int i=0;i<ve[u].size();i++){
		int v=ve[u][i];
		if(v==fa) continue;
		dep[v]=dep[u]+1;
		dfs(v,u);
		sz[u]+=sz[v];
		if(sz[v]>sz[sn[u]]) sn[u]=v;
	}
	ed[u]=++tot;
	return;
}
void find(int u,int fa){
	cout<<u<<" "<<fa<<endl; 
	if(u==0) return;
	find(sn[u],u);
	for(int i=0;i<ve[u].size();i++){
		int v=ve[u][i];
		if(v==fa||v==sn[u]) continue;
		anc[v]=v;
		find(v,v);
	}
	return;
}
int lca(int u,int v){
	while(anc[u]!=anc[v]){
		if(dep[anc[u]]<dep[anc[v]]) swap(u,v);
		v=faq[anc[v]];
	}
	return (dep[v]>dep[u])?u:v;
}
void read(){
	for(int i=1;i<=m;i++){
		cin>>u>>v;
		if(st[u]>st[v]) swap(u,v);
		if(lca(u,v)==u) a[i].l=st[u],a[i].r=st[v];
		else a[i].l=ed[u],a[i].r=st[v],a[i].lca=p[lca(u,v)];
		a[i].id=i;
	}
	return;
}
void add(int x){
	if(res[x]++==0) ans++;
}
void del(int x){
	if(--res[x]==0) ans--;
}
void solve(){
	sort(a+1,a+m+1,cmp);
	int l=0,r=0;
	for(int i=1;i<=m;i++){
		while(r<a[i].r) add(p[++r]);
		while(r>a[i].r) del(p[r--]);
		while(l<a[i].l) del(p[l++]);
		while(l>a[i].l) add(p[--l]);
		if(a[i].lca) add(a[i].lca);
		res[a[i].id]=ans;
		if(a[i].lca) del(a[i].lca);
	}
	for(int i=1;i<=m;i++)
		cout<<res[i]<<endl;
	return;
}
int main(){
	cin>>n>>m;
	sq=sqrt(n);
	for(int i=1;i<=n;i++)
		cin>>p[i];
	init();
	for(int i=1;i<n;i++){
		cin>>u>>v;
		ve[u].push_back(v);
		ve[v].push_back(u);
	}
	anc[1]=dep[1]=1;
	dfs(1,0);
	find(1,0,1);
	read();solve();
	return 0;
} 

错误提示

/tmp/compiler_rsuav5zx/src: 在函数‘void dfs(int, int)’中:
/tmp/compiler_rsuav5zx/src:42:23: 警告:comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   42 |         for(int i=0;i < ve[u].size();i++){
      |                     ~~^~~~~~~~~~~~~~
/tmp/compiler_rsuav5zx/src: 在函数‘void find(int, int)’中:
/tmp/compiler_rsuav5zx/src:57:23: 警告:comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   57 |         for(int i=0;i < ve[u].size();i++){
      |                     ~~^~~~~~~~~~~~~~
In file included from /nix/store/fdbr19mgwzmp1f17nbd9pqjv9vl9kzrq-luogu-gcc-11.2.0/include/c++/11.2.0/bits/char_traits.h:39,
                 from /nix/store/fdbr19mgwzmp1f17nbd9pqjv9vl9kzrq-luogu-gcc-11.2.0/include/c++/11.2.0/ios:40,
                 from /nix/store/fdbr19mgwzmp1f17nbd9pqjv9vl9kzrq-luogu-gcc-11.2.0/include/c++/11.2.0/ostream:38,
                 from /nix/store/fdbr19mgwzmp1f17nbd9pqjv9vl9kzrq-luogu-gcc-11.2.0/include/c++/11.2.0/iostream:39,
                 from /tmp/compiler_rsuav5zx/src:1:
/nix/store/fdbr19mgwzmp1f17nbd9pqjv9vl9kzrq-luogu-gcc-11.2.0/include/c++/11.2.0/bits/stl_algobase.h: In instantiation of ‘_Iterator std::__find_if(_Iterator, _Iterator, _Predicate) [with _Iterator = int; _Predicate = __gnu_cxx::__ops::_Iter_equals_val<const int>]’:
/nix/store/fdbr19mgwzmp1f17nbd9pqjv9vl9kzrq-luogu-gcc-11.2.0/include/c++/11.2.0/bits/stl_algo.h:3884:28:   required from ‘_IIter std::find(_IIter, _IIter, const _Tp&) [with _IIter = int; _Tp = int]’
/tmp/compiler_rsuav5zx/src:117:6:   required from here
/nix/store/fdbr19mgwzmp1f17nbd9pqjv9vl9kzrq-luogu-gcc-11.2.0/include/c++/11.2.0/bits/stl_algobase.h:2115:48: 错误:对‘__iterator_category(int&)’的调用没有匹配的函数
 2115 |                        std::__iterator_category(__first));
      |                        ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
In file included from /nix/store/fdbr19mgwzmp1f17nbd9pqjv9vl9kzrq-luogu-gcc-11.2.0/include/c++/11.2.0/bits/stl_algobase.h:65,
                 from /nix/store/fdbr19mgwzmp1f17nbd9pqjv9vl9kzrq-luogu-gcc-11.2.0/include/c++/11.2.0/bits/char_traits.h:39,
                 from /nix/store/fdbr19mgwzmp1f17nbd9pqjv9vl9kzrq-luogu-gcc-11.2.0/include/c++/11.2.0/ios:40,
                 from /nix/store/fdbr19mgwzmp1f17nbd9pqjv9vl9kzrq-luogu-gcc-11.2.0/include/c++/11.2.0/ostream:38,
                 from /nix/store/fdbr19mgwzmp1f17nbd9pqjv9vl9kzrq-luogu-gcc-11.2.0/include/c++/11.2.0/iostream:39,
                 from /tmp/compiler_rsuav5zx/src:1:
/nix/store/fdbr19mgwzmp1f17nbd9pqjv9vl9kzrq-luogu-gcc-11.2.0/include/c++/11.2.0/bits/stl_iterator_base_types.h:238:5: 附注:candidate: ‘template<class _Iter> constexpr typename std::iterator_traits< <模板形参-1-1> >::iterator_category std::__iterator_category(const _Iter&)’
  238 |     __iterator_category(const _Iter&)
      |     ^~~~~~~~~~~~~~~~~~~
/nix/store/fdbr19mgwzmp1f17nbd9pqjv9vl9kzrq-luogu-gcc-11.2.0/include/c++/11.2.0/bits/stl_iterator_base_types.h:238:5: 附注:  template argument deduction/substitution failed:
/nix/store/fdbr19mgwzmp1f17nbd9pqjv9vl9kzrq-luogu-gcc-11.2.0/include/c++/11.2.0/bits/stl_iterator_base_types.h: In substitution of ‘template<class _Iter> constexpr typename std::iterator_traits< <模板形参-1-1> >::iterator_category std::__iterator_category(const _Iter&) [with _Iter = int]’:
/nix/store/fdbr19mgwzmp1f17nbd9pqjv9vl9kzrq-luogu-gcc-11.2.0/include/c++/11.2.0/bits/stl_algobase.h:2115:34:   required from ‘_Iterator std::__find_if(_Iterator, _Iterator, _Predicate) [with _Iterator = int; _Predicate = __gnu_cxx::__ops::_Iter_equals_val<const int>]’
/nix/store/fdbr19mgwzmp1f17nbd9pqjv9vl9kzrq-luogu-gcc-11.2.0/include/c++/11.2.0/bits/stl_algo.h:3884:28:   required from ‘_IIter std::find(_IIter, _IIter, const _Tp&) [with _IIter = int; _Tp = int]’
/tmp/compiler_rsuav5zx/src:117:6:   required from here
/nix/store/fdbr19mgwzmp1f17nbd9pqjv9vl9kzrq-luogu-gcc-11.2.0/include/c++/11.2.0/bits/stl_iterator_base_types.h:238:5: 错误:no type named ‘iterator_category’ in ‘struct std::iterator_traits<int>’

可是蒟蒻找了半天都发现不了哪里 CE 了。有没有巨佬帮我看看。。。

2022/1/27 21:54
加载中...