头文件大全:
C++ 复制 #include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <limits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
数据类型定义:
C++ 复制 typedef short int sint;
typedef unsigned int uint ;
typedef __int128 bigInt;
typedef long long ll;
typedef unsigned long long ull;
typedef double d;
typedef long double ld;
快读:
C++ 复制 void read (int & x ){x= 0 ;char c= getchar ();char f= 'a' ;while (c< '0' || c> '9' ){if (! (c^ '-' ))f= 'b' ;c= getchar ();}while (c>= '0' && c<= '9' ){x= (x<< 1 )+ (x<< 3 )+ c- '0' ;c= getchar ();}if (f^ 'a' )x=- x;}
void read (sint & x ){x= 0 ;char c= getchar ();char f= 'a' ;while (c< '0' || c> '9' ){if (! (c^ '-' ))f= 'b' ;c= getchar ();}while (c>= '0' && c<= '9' ){x= (x<< 1 )+ (x<< 3 )+ c- '0' ;c= getchar ();}if (f^ 'a' )x=- x;}
void read (uint & x ){x= 0 ;char c= getchar ();while (c< '0' || c> '9' ){c= getchar ();}while (c>= '0' && c<= '9' ){x= (x<< 1 )+ (x<< 3 )+ c- '0' ;c= getchar ();}}
void read (ll & x ){x= 0 ;char c= getchar ();char f= 'a' ;while (c< '0' || c> '9' ){if (! (c^ '-' ))f= 'b' ;c= getchar ();}while (c>= '0' && c<= '9' ){x= (x<< 1 )+ (x<< 3 )+ c- '0' ;c= getchar ();}if (f^ 'a' )x=- x;}
void read (ull & x ){x= 0 ;char c= getchar ();while (c< '0' || c> '9' ){c= getchar ();}while (c>= '0' && c<= '9' ){x= (x<< 1 )+ (x<< 3 )+ c- '0' ;c= getchar ();}}
void read (bigInt & x ){x= 0 ;char c= getchar ();char f= 'a' ;while (c< '0' || c> '9' ){if (! (c^ '-' ))f= 'b' ;c= getchar ();}while (c>= '0' && c<= '9' ){x= (x<< 1 )+ (x<< 3 )+ c- '0' ;c= getchar ();}if (f^ 'a' )x=- x;}
快写:
C++ 复制 void write (int x ) {if (x< 0 ){putchar ('-' );x=- x;}if (x< 10 ){putchar (x+ '0' );}else {write (x/ 10 );putchar (x% 10 + '0' );}}
void write (sint x ) {if (x< 0 ){putchar ('-' );x=- x;}if (x< 10 ){putchar (x+ '0' );}else {write (x/ 10 );putchar (x% 10 + '0' );}}
void write (uint x ){if (x< 10 ){putchar (x+ '0' );}else {write (x/ 10 );putchar (x% 10 + '0' );}}
void write (ll x ) {if (x< 0 ){putchar ('-' );x=- x;}if (x< 10 ){putchar (x+ '0' );}else {write (x/ 10 );putchar (x% 10 + '0' );}}
void write (ull x ){if (x< 10 ){putchar (x+ '0' );}else {write (x/ 10 );putchar (x% 10 + '0' );}}
void write (bigInt x ) {if (x< 0 ){putchar ('-' );x=- x;}if (x< 10 ){putchar (x+ '0' );}else {write (x/ 10 );putchar (x% 10 + '0' );}}
gcd与lcm
C++ 复制 int gcd (int a ,int b ){if (! b)return a;return gcd (b,a% b);}
sint gcd (sint a ,sint b ){if (! b)return a;return gcd (b,a% b);}
uint gcd (uint a ,uint b ){if (! b)return a;return gcd (b,a% b);}
ll gcd (ll a ,ll b ){if (! b)return a;return gcd (b,a% b);}
ull gcd (ull a ,ull b ){if (! b)return a;return gcd (b,a% b);}
bigInt gcd (bigInt a ,bigInt b ){if (! b)return a;return gcd (b,a% b);}
#define lcm (x , y ) (x / gcd (x, y) * y)
pair类型定义
代码 复制 #define pii pair<int , int>
#define pil pair<int , ll>
#define pis pair<int , sint>
#define piu pair<int , uint>
#define piul pair<int , ull>
#define pild pair<int , ld>
#define pib pair<int , bigInt>
#define pli pair< ll, int>
#define pll pair< ll, ll>
#define pls pair< ll, sint>
#define plu pair< ll, uint>
#define plul pair< ll, ull>
#define plld pair< ll, ld>
#define plb pair< ll, bigInt>
#define psi pair< sint, int>
#define psl pair< sint, ll>
#define pss pair< sint, sint>
#define psu pair< sint, uint>
#define psul pair< sint, ull>
#define psld pair< sint, ld>
#define psb pair< sint, bigInt>
#define pui pair<uint , int>
#define pul pair<uint , ll>
#define pus pair<uint , sint>
#define puu pair<uint , uint>
#define puul pair<uint , ull>
#define puld pair<uint , ld>
#define pub pair<uint , bigInt>
#define puli pair< ull, int>
#define pull pair< ull, ll>
#define puls pair< ull, sint>
#define pulu pair< ull, uint>
#define pulul pair< ull, ull>
#define pulld pair< ull, ld>
#define pulb pair< ull, bigInt>
#define pldi pair< ld, int>
#define pldl pair< ld, ll>
#define plds pair< ld, sint>
#define pldu pair< ld, uint>
#define pldul pair< ld, ull>
#define pldld pair< ld, ld>
#define pldb pair< ld, bigInt>
#define pbi pair< bigInt, int>
#define pbl pair< bigInt, ll>
#define pbs pair< bigInt, sint>
#define pbu pair< bigInt, uint>
#define pbul pair< bigInt, ull>
#define pbld pair< bigInt, ld>
#define pbb pair< bigInt, bigInt>
#define MP (x , y ) make_pair (x, y)
#define MPP (x , y , z ) make_pair ( make_pair (x, y) , z)
#define MPPP (x , y , z , r ) make_pair ( make_pair (x, y) , make_pair (z, r) )
线段树与树状数组
代码 复制 #define lowbit (x ) (x & (- x))
#define half (l + r) >> 1
#define lc rt << 1
#define rc rt << 1 | 1
#define lson lc, l, mid
#define rson rc, mid + 1 , r
#define Ql lson, ql, qr
#define Qr rson, ql, qr
#define myself rt, l, r
常见的数
代码 复制 #define pi 3.141592653589793
#define e 2.718281828459045
#define inf 0x 3f3f3f3f
#define INF 0x 3f3f3f3f3f3f3f3f
#define eps 1 e- 8