功能介绍
写了I/O函数,支持以下几种方式
1 read(num); //读入一个数num(任意整数类型,下同) 2 read(num1,num2,num3,num4); //读入任意多个数 3 read(arr,n); //对一个整数数组arr读入n个值,[0,n-1] 4 read(arr,first,last); //对一个整数数组arr读入区间last-first+1个值,[first,last] 5 read(s); //读入一个字符串数组(string和char数组都支持) 6 print(num); //输出一个数num 7 print(num1,num2,num3,num4); //输出任意多个数,中间用空格隔开 8 print(arr,n); //对一个整数数组arr输出n个值,[0,n-1],中间用空格隔开 9 print(arr,first,last); //对一个整数数组arr输出last-first+1个值,[first,last],中间用空格隔开
10 //read()有返回值,遇到EOF返回0。多组数据时可以放心使用while(read(n)){} 11 //至于字符串的输出没有进行优化,测试显示直接cout或者printf比较快
关于define nc getchar,是因为用到了fread,本地调试时候请不要注释,否则无法从键盘读入数据,提交时注释这句话即可。
支持以下几个函数
1 gcd(a,b); //求两数gcd(任意整数类型,下同) 2 lowbit(x); //求一个整数的lowbit 3 mishu(x); //判断一个数是不是2的幂 4 q_mul(a,b,p); //求(a*b)%p的值,防止溢出,O(logN) 5 f_mul(a,b,p); //求(a*b)%p的值,防止溢出,O(1),可能丢失精度 6 q_pow(a,b,p); //求(a^b)%p的值,不防溢出,O(logN) 7 s_pow(a,b,p); //求(a^b)%p的值,防溢出,O(logN*logN) 8 ex_gcd(a,b,x,y); //扩展GCD 9 com(m,n); //求C(m,n) 10 isprime(num); //判断一个数是否质数
其他一些宏定义自行查看即可了解,大部分的东西我都尽可能的进行了优化,之前有个很冗长的,现在修改成这样了,基本也就是最终版本。
1 //XDDDDDDi 2 #include <bits/stdc++.h> 3 using namespace std; 4 #define PB push_back 5 #define MT make_tuple 6 #define MP make_pair 7 #define pii pair<int,int> 8 #define pdd pair<double,double> 9 #define F first 10 #define S second 11 12 #define MOD 1000000007 13 #define PI (acos(-1.0)) 14 #define EPS 1e-6 15 #define MMT(s,a) memset(s, a, sizeof s) 16 #define GO(i,a,b) for(int i = (a); i < (b); ++i) 17 #define GOE(i,a,b) for(int i = (a); i <= (b); ++i) 18 #define OG(i,a,b) for(int i = (a); i > (b); --i) 19 #define OGE(i,a,b) for(int i = (a); i >= (b); --i) 20 21 typedef unsigned long long ull; 22 typedef long long ll; 23 typedef double db; 24 typedef long double ldb; 25 typedef stringstream sstm; 26 int fx[8][2] = {{1,0},{-1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,-1},{-1,1}}; 27 28 template<typename T> using maxHeap = priority_queue<T, vector<T>, less<T> >; 29 template<typename T> using minHeap = priority_queue<T, vector<T>, greater<T> >; 30 31 inline char nc(){ static char buf[1000000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf,1,1000000,stdin),p1 == p2) ? EOF : *p1++; } 32 #define nc getchar 33 template<typename T> inline int read(T& sum){ char ch = nc(); if(ch == EOF || ch == -1) return 0; int tf = 0; sum = 0; while((ch < '0' || ch > '9') && (ch != '-')) ch = nc(); tf = ((ch == '-') && (ch = nc())); while(ch >= '0' && ch <= '9') sum = sum*10 + (ch-48), ch = nc(); (tf) && (sum = -sum); return 1; } 34 template<typename T,typename... Arg> inline int read(T& sum,Arg&... args){ int ret = read(sum); if(!ret) return 0; return read(args...); } 35 template<typename T1,typename T2> inline void read(T1* a,T2 num){ for(int i = 0; i < num; i++){read(a[i]);} } 36 template<typename T1,typename T2> inline void read(T1* a,T2 bn,T2 ed){ for(;bn <= ed; bn++){read(a[bn]);} } 37 inline void read(char* s){ char ch = nc(); int num = 0; while(ch != ' ' && ch != ' ' && ch != ' ' && ch != EOF){s[num++] = ch;ch = nc();} s[num] = '