小技巧&模板
更改栈空间和内存占用
- Linux 在当前终端使用
ulimit(-s)栈空间 kbytes,(-t)时间,单位为秒(-v)内存 kbytes,
例如 ulimit -s 262144 -t 1 -v 262144
为
- Windows
添加编译选项-Wl,--stack=<num>
如-Wl,--stack=268435456
将栈空间确定为 256 MiB
计算一个数的二进制表示有多少位为1
__builtin_popcount()
- 注意这个是unsigned int类型
__builtin_popcountll()
- 这个是unsigned long long类型
关闭同步流
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
哈希映射,比 快很多
include<ext/pb_ds/assoc_container.hpp>
include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
gp_hash_table<int,int>bz[1005];
快读
//#define gc() (p1==p2&&(p2=(p1=in)+fread(in,1,1<<20,stdin),p1==p2)?EOF:*p1++)
#define gc() getchar()
inline int read(){
int x(0),f(1);char ch=gc();
for(;ch<'0'||ch>'9';ch=gc())if(ch=='-')f=-1;
for(;ch>='0'&&ch<='9';ch=gc())x=(x<<1)+(x<<3)+(ch^48);
return x*f;
}
DFS序
void dfs(int s,int f){
dfn[s]=++id;
size[s]=1;
int to;
for(int i=head[s];i;i=e[i].next){
to=e[i].to;
if(to==f)continue;
dfs(to,s);
size[s]+=size[to];
}
return ;
}
欧拉序
void dfs(int s,int f){
dfn[++id]=s;
size[s]=1;
int to;
for(int i=head[s];i;i=e[i].next){
to=e[i].to;
if(to==f)continue;
dfs(to,s);
dfn[++id]=s;//返回时记录
size[s]+=size[to];
}
return ;
}
void dfs(int s,int f){
dfn[++id]=s;//入栈时记录
size[s]=1;
int to;
for(int i=head[s];i;i=e[i].next){
to=e[i].to;
if(to==f)continue;
dfs(to,s);
size[s]+=size[to];
}
dfn[++id]=s;//出栈时记录
return ;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】