模板
\[ft61
\]
试机
-
cerr
-
测速
sfmt19937 mt(20050827);
set<unsigned> s;
For(i,1,1e6) s.emplace(mt());
cout<<sz(s)<<'\n';
本地 0.67s CF 0.96s 牛客 0.7s
配置
- vscode
"editor.rulers": [85],
-
vim
-
缺省源
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx;
#define For(i,x,y,...) for(int i=(x),##__VA_ARGS__;i<=(y);++i)
#define rFor(i,x,y,...) for(int i=(x),##__VA_ARGS__;i>=(y);--i)
#define Rep(i,x,y,...) for(int i=(x),##__VA_ARGS__;i<(y);++i)
#define pb emplace_back
#define sz(a) int((a).size())
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define mkp make_pair
typedef long long LL; typedef vector<int> Vi; typedef pair<int,int> Pii;
auto ckmax=[](auto &x,auto y) { return x<y ? x=y,true : false; };
auto ckmin=[](auto &x,auto y) { return y<x ? x=y,true : false; };
sfmt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r) { return uniform_int_distribution<>(l,r)(mt); }
template<typename T=int>T read() { T x; cin>>x; return x; }
void MAIN() {
} signed main() {
#ifdef FT
freopen("in","r",stdin); freopen("out","w",stdout);
#endif
ios::sync_with_stdio(0);cin.tie(0);
int lft=1; while( lft-- ) {
MAIN();
}
return 0;
}
其他
-
运行时间:
(double)clock()/CLOCKS_PER_SEC
-
高精度类
不压位,\(O(n^2)\) 乘法
struct bint : Vi {
bint() { resize(1); }
bint(int x) { clear(); for(; x; x/=10) emplace_back(x%10); }
void clr() { while( size() > 1 && !back() ) pop_back(); }
friend istream& operator >> (istream &io,bint &a) {
string s; io>>s, reverse(all(s));
if( s.back() == '-' ) s.pop_back();
a.resize(sz(s)); Rep(i,0,sz(s)) a[i] = s[i]-'0';
return io;
}
friend ostream& operator << (ostream &io,const bint &a)
{ rFor(i,sz(a)-1,0) cout<<a[i]; return io; }
friend bool operator < (const bint &a,const bint &b) {
if( sz(a) != sz(b) ) return sz(a) < sz(b);
rFor(i,sz(a)-1,0) if( a[i] != b[i] ) return a[i] < b[i];
return 0;
}
friend bint operator + (const bint &a,const bint &b) {
bint c = a; c.resize(max(sz(a),sz(b))+1);
Rep(i,0,sz(b)) c[i] += b[i];
Rep(i,0,sz(c)) if( c[i] >= 10 ) ++c[i+1], c[i] -= 10;
return c.clr(), c;
}
friend bint operator * (const bint &a,const bint &b) {
bint c; c.resize(sz(a)+sz(b)+1);
Rep(i,0,sz(a)) Rep(j,0,sz(b)) c[i+j] += a[i] * b[j];
Rep(i,0,sz(c)) if( c[i] >= 10 ) c[i+1] += c[i]/10, c[i] %= 10;
return c.clr(), c;
}
friend bint operator - (bint a,bint b) {
b.resize(sz(a));
Rep(i,0,sz(a)) {
if( a[i] < b[i] ) --a[i+1], a[i] += 10;
a[i] -= b[i];
}
return a.clr(), a;
}
};
压位,乘法
-
分数类
-
取模
mint(int x)
要求 x < 2*mod
const int mod = 998244353;
struct mint {
int x; mint(int x=0):x(x<0?x+mod:x<mod?x:x-mod){}
mint(LL y) { y%=mod, x=y<0?y+mod:y; }
mint& operator += (const mint &y) { x=x+y.x<mod?x+y.x:x+y.x-mod; return *this; }
mint& operator -= (const mint &y) { x=x<y.x?x-y.x+mod:x-y.x; return *this; }
mint& operator *= (const mint &y) { x=1ll*x*y.x%mod; return *this; }
friend mint operator + (mint x,const mint &y) { return x+=y; }
friend mint operator - (mint x,const mint &y) { return x-=y; }
friend mint operator * (mint x,const mint &y) { return x*=y; }
}; mint Pow(mint x,LL y=mod-2) { mint z(1);for(;y;y>>=1,x*=x)if(y&1)z*=x;return z; }
- Barrett reduction
【条件】
struct {
LL p,m;
void init(int mod) { p = mod, m = (1ull<<63)/p; }
LL operator () (LL x) {
LL res = x-(__int128(x)*m>>63)*p;
return res<p ? res : res-p;
}
} mod;
- 快读
#define getchar() getchar_unlocked()
struct IO {
IO& operator >> (char &x) { while(isspace(x=getchar())); return *this; }
IO& operator >> (char *s) {
while(isspace(*s=getchar())); while(isgraph(*++s=getchar()));
return *s=0, *this;
}
template<typename T>IO& operator >> (T &x) {
x=0;bool f=0;char c;while(!isdigit(c=getchar()))f|=c=='-';
do x=x*10+c-48;while(isdigit(c=getchar()));if(f)x=-x;
return *this;
}
} io;
#define cin io
- linux 对拍
shell
clear; g++ g.cpp -og -DFT -O2
let i=0; while true; do
let i++; printf "#$i\n"
./g; ./a; ./a0
if ! diff out ans -bB; then break; fi
done
- windows 对拍
for(int i = 1; ; ++i) {
system("ag.exe"), system("a0.exe");
double s = clock(); system("a.exe"); double t = clock();
if( system("fc a.ans a.out") ) puts("WA"), exit(0);
printf("#%d: %.0lfms\n",i,t-s);
}
- 交互
所有输入都要读
endl
换行