社区讨论

c++14下的珂怎么写?

学术版参与者 5已保存回复 10

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
10 条
当前快照
1 份
快照标识符
@mlhp9otx
此快照首次捕获于
2026/02/11 15:20
上周
此快照最后确认于
2026/02/11 16:05
上周
查看原帖
是这样的:我照着别人的blog写珂,写炸了,本地跑过,提交CE,用的c++14。求问c++14下的珂怎么写?下面是我的代码。(就是这题,只需要实现split和assign)。
如果有大佬在评论区能写出c++14下不会炸的珂,三关,蒟蒻感激不胜。
我认为本帖子不是单纯的求条帖子,它对所有题目下怎么写珂都有指导意义,所以没有发题目版而是来到了这里。
下面是我的代码:
CPP
struct odt{
	int l,r,v;
}tmp;
struct cmp{
	bool operator()(odt o0,odt o1){
		return o0.l<o1.l;
	}
};
set<odt,cmp> s;
set<odt,cmp>::iterator it,it0,it1;
set<odt,cmp>::iterator split(int x){
	it=s.lower_bound({x,0,0});
	if(it!=s.end()&&it->l==x)return it;
	it--,tmp=*it,s.erase(it);
	s.insert({tmp.l,x-1,tmp.v});
	return s.insert({x,tmp.r,tmp.v}).first;
}void assign(int l,int r,int v){
	it1=split(r+1),it0=split(l);
	s.erase(it0,it1),s.insert({l,r,v});
}
报错信息:
CPP
/tmp/compiler__72x8ttq/src: In function ‘int main()’:
/tmp/compiler__72x8ttq/src:32:16: 警告:格式 ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘std::size_t’ {aka ‘long unsigned int’} [-Wformat=]
   32 |         printf("%d",vis.count());
      |                ^~~~ ~~~~~~~~~~~
      |                              |
      |                              std::size_t {aka long unsigned int}
包含于文件 /nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-gcc-15.1.0/include/c++/15.1.0/set:64,
        于 /tmp/compiler__72x8ttq/src:2:
/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-gcc-15.1.0/include/c++/15.1.0/bits/stl_tree.h: In instantiation of ‘std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Base_ptr std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_lower_bound(_Base_ptr, _Base_ptr, const _Key&) const [with _Key = odt; _Val = odt; _KeyOfValue = std::_Identity<odt>; _Compare = cmp; _Alloc = std::allocator<odt>; _Base_ptr = std::__rb_tree::_Node_traits<odt, odt*>::_Node_base*]’:
/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-gcc-15.1.0/include/c++/15.1.0/bits/stl_tree.h:1894:25:   required from ‘std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::lower_bound(const key_type&) [with _Key = odt; _Val = odt; _KeyOfValue = std::_Identity<odt>; _Compare = cmp; _Alloc = std::allocator<odt>; iterator = std::_Rb_tree<odt, odt, std::_Identity<odt>, cmp, std::allocator<odt> >::iterator; key_type = odt]’
/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-gcc-15.1.0/include/c++/15.1.0/bits/stl_set.h:876:32:   required from ‘std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::lower_bound(const key_type&) [with _Key = odt; _Compare = cmp; _Alloc = std::allocator<odt>; iterator = std::_Rb_tree<odt, odt, std::_Identity<odt>, cmp, std::allocator<odt> >::const_iterator; key_type = odt]’
/tmp/compiler__72x8ttq/src:18:18:   required from here
   18 |         it=s.lower_bound({x,0,0});
      |            ~~~~~~~~~~~~~^~~~~~~~~
/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-gcc-15.1.0/include/c++/15.1.0/bits/stl_tree.h:2604:29: 错误:对‘(const cmp) (const odt&, const odt&)’的调用没有匹配
/tmp/compiler__72x8ttq/src:10:8: 附注:there is 1 candidate
   10 | struct cmp{
      |        ^~~
/tmp/compiler__72x8ttq/src:11:14: 附注:备选 1: ‘bool cmp::operator()(odt, odt)(near match)
   11 |         bool operator()(odt o0,odt o1){
      |              ^~~~~~~~
/tmp/compiler__72x8ttq/src:11:14: 附注:passing ‘const cmp*’ as ‘this’ argument discards qualifiers
/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-gcc-15.1.0/include/c++/15.1.0/bits/stl_tree.h: In instantiation of ‘static const _Key& std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_S_key(const _Node&) [with _Key = odt; _Val = odt; _KeyOfValue = std::_Identity<odt>; _Compare = cmp; _Alloc = std::allocator<odt>; _Node = std::_Rb_tree<odt, odt, std::_Identity<odt>, cmp, std::allocator<odt> >::_Node]’:
/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-gcc-15.1.0/include/c++/15.1.0/bits/stl_tree.h:1417:22:   required from ‘static const _Key& std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_S_key(_Base_ptr) [with _Key = odt; _Val = odt; _KeyOfValue = std::_Identity<odt>; _Compare = cmp; _Alloc = std::allocator<odt>; _Base_ptr = std::__rb_tree::_Node_traits<odt, odt*>::_Node_base*]’
/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-gcc-15.1.0/include/c++/15.1.0/bits/stl_tree.h:2604:36:   required from ‘std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Base_ptr std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_lower_bound(_Base_ptr, _Base_ptr, const _Key&) const [with _Key = odt; _Val = odt; _KeyOfValue = std::_Identity<odt>; _Compare = cmp; _Alloc = std::allocator<odt>; _Base_ptr = std::__rb_tree::_Node_traits<odt, odt*>::_Node_base*]’
/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-gcc-15.1.0/include/c++/15.1.0/bits/stl_tree.h:1894:25:   required from ‘std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::lower_bound(const key_type&) [with _Key = odt; _Val = odt; _KeyOfValue = std::_Identity<odt>; _Compare = cmp; _Alloc = std::allocator<odt>; iterator = std::_Rb_tree<odt, odt, std::_Identity<odt>, cmp, std::allocator<odt> >::iterator; key_type = odt]’
/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-gcc-15.1.0/include/c++/15.1.0/bits/stl_set.h:876:32:   required from ‘std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::lower_bound(const key_type&) [with _Key = odt; _Compare = cmp; _Alloc = std::allocator<odt>; iterator = std::_Rb_tree<odt, odt, std::_Identity<odt>, cmp, std::allocator<odt> >::const_iterator; key_type = odt]’
/tmp/compiler__72x8ttq/src:18:18:   required from here
   18 |         it=s.lower_bound({x,0,0});
      |            ~~~~~~~~~~~~~^~~~~~~~~
/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-gcc-15.1.0/include/c++/15.1.0/bits/stl_tree.h:1407:8: 错误:静态断言错误:comparison object must be invocable as const
/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-gcc-15.1.0/include/c++/15.1.0/bits/stl_tree.h:1407:8: 附注:‘std::is_invocable_v<const cmp&, const odt&, const odt&>’ 总是评估为假

回复

10 条回复,欢迎继续交流。

正在加载回复...