跳到正文

个人记录

奇技淫巧

枫林晚约 2 分钟
原文
文章信息与版本

文章信息

发布
2018年5月6日
收录
2025年12月12日
更新
2026年11月13日
篇幅
约 2 分钟

版本

  1. v1当前

本篇博文记录一些机智操作,简洁方法,奇技淫巧。

1.快读:

C++
void read(int &x)
{
	char ch;bool flag=false;
	while(!isdigit(ch=getchar()))
		(ch=='-')&&(flag=true);
	for(x=num;isdigit(ch=getchar());x=x*10+num);
	 (flag)&&(x=-x);
}

注意:&x和&&前后两个的顺序

支持:整形读入。包括负数

2.取模优化:

C++
inline int mod(int x)
{
    return x-p*(x/p);
}

或者:

C++
inline int mod(int x)
{
	while(x>p) x-=p;
    while(x<0) x+=p;//适用于p>0
   	return x;
}

不过好像并没有什么卵用

3.线段树define操作

C++
struct node{
	int l,r;
	int add,ch;
	int mx,hx;
	int had,hch;//一段时间内最值
	#define ad(x) t[x].add
	#define ch(x) t[x].ch
	#define mx(x) t[x].mx
	#define hx(x) t[x].hx
	#define ha(x) t[x].had
	#define hc(x) t[x].hch
	#define l(x) t[x].l
	#define r(x) t[x].r
}t[4*N];

摘自:cpu监控

4.define int long long

适用于无脑调试

但是空间极其紧张,除非没时间改,否则不要用这个。

5.num[++num[0]]=x;

用num[0]计数,有多个数组的时候,不会弄混cnt名称

原文
存档评论1 条抓取于