本篇博文记录一些机智操作,简洁方法,奇技淫巧。
1.快读:
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.取模优化:
inline int mod(int x)
{
return x-p*(x/p);
}
或者:
inline int mod(int x)
{
while(x>p) x-=p;
while(x<0) x+=p;//适用于p>0
return x;
}
不过好像并没有什么卵用
3.线段树define操作
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名称