【杂文】黑科技和杂事

本文探讨了一些编程中的黑科技和实用技巧,包括线性预处理逆元、大质数的处理、cin关闭同步以提高效率,以及重载小于号等。还提到了在特定场景下可能使用的卡常黑科技,但要注意其可能导致的负面影响。另外,文章介绍了bitset的使用及其在遍历1时的复杂度分析,并提醒读者注意运算符的优先级问题。
线性预处理逆元
	for (int i = 1 ; i <= n ; i++) inv[i] = (mod - mod / i) * inv[mod % i] % mod;

大质数

NTT模数&原根表
1e14 : 360023843327831
快速乘:

ll mul(ll a,ll b){
	return ((a*b-(long long)(a / (long double)mod * b + 1e-3)*mod+mod)%mod);
}
偶尔可以用的卡常黑科技(好像codeforces上被封了?有一次反而变慢了)

bzoj会CE,只能手动O3

#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("avx")
cin关闭同步
std::ios::sync_with_stdio(false);
重载小于号

http://c.biancheng.net/view/520.html

// Compares keys that are unique_ptr<string> objects
class Key_compare
{
public:
    bool operator () (const std::unique_ptr<string>& p1, const std::unique_ptr <string>& p2) const
    {
        return *p1 < *p2;
    }
};

或者在struct中重载

bool operator>(const Name& name) const
{
    return second > name.second ||(second == name.second && first > name.first);
}

std::map<Name,size_t, std::greater<Name>>people
bitset

bitset遍历所有的1
实测复杂度是O(max(count,n / w)) , 在1很少时很快。1满时比直接for慢4倍
1e9 本机 4s(codeforces 8s)(不含输出)

for(int i=BS._Find_first();i< BS.size();i = BS._Find_next(i))
    cout<<i<<endl;
运算符优先级

https://blog.youkuaiyun.com/wu_tongtong/article/details/78176175

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值