#4707: about "terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc Aborted (core dumped)"


voicefark (小鴨)

學校 : 復旦高級中學
編號 : 1018
來源 : [192.168.4.5]
最後登入時間 :
2024-08-26 13:12:07
a837. sort?別開玩笑了(1) | From: [192.168.4.5] | 發表日期 : 2023-07-18 11:09

用陣列時會

Segmentation fault (core dumped)
用vector時是
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
Aborted (core dumped)

用vector時先預留空間
vec.reserve(n);//n為預留的大小
可以參考:https://zhuanlan.zhihu.com/p/361331817
 
ZeroJudge Forum