缺省源

模板
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t,p) for(int i = s;i <= t; i += p)
#define drep(i,s,t,p) for(int i = s;i >= t; i -= p)
#ifdef LOCAL
    FILE *InFile = freopen("file/in.in","r",stdin),*OutFile = freopen("file/out.out","w",stdout);
#else
    FILE *InFile = stdin,*OutFile = stdout;
#endif
using ll=long long;using ull=unsigned long long;
using db = double;using ldb = long double;
signed main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    
}
vimrc
set noundofile
set nobackup
 
syntax on
 
set smartindent
set number
set mouse=a
set matchtime=0
set expandtab
set shiftwidth=4
set softtabstop=4
set ts=4
set tabstop=4
set autoindent
set showcmd
set showmatch
set cursorline
map <F2> <ESC>:w<CR>:!./run -DLOCAL %< <CR>
map <F3> <ESC>:w<CR>:!./run -DLOCAL -f %< <CR>
map <F4> <ESC>:w<CR>:!./run -DLOCAL -g %< <CR>
map <F5> <ESC>:w<CR>:!vim in.in<CR>
map <F6> <ESC>:w<CR>:!vim out.out<CR>
map <C-A> <ESC>:!cat muban.cpp > %<.cpp <CR> L <CR>
map <F7> <ESC>:w<CR>:!gedit % <CR>
imap <F2> <ESC>:w<CR>:!./run -DLOCAL %< <CR>
imap <F3> <ESC>:w<CR>:!./run -DLOCAL -f %< <CR>
imap <F4> <ESC>:w<CR>:!./run -DLOCAL -g %< <CR>
imap <F5> <ESC>:w<CR>:!vim in.in<CR>
imap <F6> <ESC>:w<CR>:!vim out.out<CR>
imap <C-A> <ESC>:!cat muban.cpp > %<.cpp <CR> L <CR>
imap <F7> <ESC>:w<CR>:!gedit % <CR>

终端颜色

          文本     背景
默认颜色  #76FCFF #3E008E
粗体颜色  #6DCDFF
光标颜色  #C397FF #ECABFF
高亮颜色  #63D3FF #62DED4
Use transparent background靠近none
内置方案为Solarized
以亮色显示粗体字

插件

run
#include<bits/stdc++.h>
using namespace std;
string version = "14",filename,fsanitize,fast = "-O2",gdb,define;
signed main(int argv,char **argc){
    #ifdef ON
        cerr<<"RES";
    #endif
    for(int  i = 1;i < argv; ++i){
        string s = argc[i];
        if((s[0] == 'C' || s[0] == 'c') && s[1] == '+' && s[2] == '+'){
            version.clear();
            version.push_back(s[3]);
            version.push_back(s[4]);
        }
        else if(s == "-f"){
            fsanitize = " -fsanitize=address,undefined";
        }
        else if(s == "-g"){
            gdb = "-g ";
        }
        else if(s[0] == '-' && (s[1] == 'o' || s[1] =='O')){
            fast = s;
        }
        else if(s[0] == '-'&& s[1] == 'D'){
            define=s;
        }
        else filename = s;
    }
    string p = "g++ -std=c++"+version+" "+fast+" "+gdb+define+fsanitize+" "+filename+".cpp -o"+filename+"&& ./"+filename;
    system(p.c_str());
    //g++ -std=c++14 -O2 -fsantize=address,undefined a.cpp -o  a && ./a
}

使用指南: 在./run后加 如,我想以c++20编译a.cpp,开启fsanitize(默认不开),开启Ofast优化(默认O2) 那么就 ./run a -f -Ofast c++2a -D 后加紧接着一个表示define了一个 如-DONLINE_JUDGE表示define了ONLINE_JUDGE 顺序无所谓

Linux内存检测器(by jijidawang)

watch -n 1 "/usr/bin/free | awk 'NR > 1{ if (\$3 / \$2 > 0.55) system(\"killall5\") }'"
rand
#include<bits/stdc++.h>
#include<bits/extc++.h>
// using namespace __gnu_pbds;
// using namespace __gnu_cxx;
using namespace std;
#define rep(i,s,t,p) for(int i = s;i <= t; i += p)
#define drep(i,s,t,p) for(int i = s;i >= t; i -= p)
#ifndef ONLINE_JUDGE
    FILE *File = freopen("in.in","w",stdout);
#else
#endif
using ll=long long;using ull=unsigned long long;
using db = double;using ldb = long double;
mt19937 rnd((ull)(new char));
signed main(){
    cin.tie(nullptr)->sync_with_stdio(false);
}
while
#include <bits/stdc++.h>
using namespace std;
void Black() { printf("\033[37m"); }
void Red() { printf("\033[31m"); }
void Green() { printf("\033[32m"); }
void Yellow() { printf("\033[33m"); }
void Blue() { printf("\033[34m"); }
void Purple() { printf("\033[35m"); }
void DeepGreen() { printf("\033[36m"); }
void White() { printf("\033[37m"); }
int sys(string cmd) { return system(cmd.c_str()); }
#define nnow steady_clock::now()
#define dc duration_cast<duration<double>>(t2 - t1)
#define time ut.count()
#define pc putchar
#define pr printf
#define ps puts
#define Wall ps("--------------------------------------------")
#define CE(x)  Re(), ps("Error"), Bl(), Wall, exit(1);
#define COM(x) Pu(), pr("Compile " #x " "), Bl();
#define WA()   Wh(), pr("%03d ", i), Re(), ps("Wrong Answer"), Bl(), exit(1);
#define Bls "\033[37m"
#define Res "\033[31m"
#define Grs "\033[32m"
#define Yes "\033[33m"
#define BLs "\033[34m"
#define Pus "\033[35m"
#define DGs "\033[36m"
void BLK() { pr("\033[30m"); }
void Bl() { pr("\033[37m"); }
void Re() { pr("\033[31m"); }
void Gr() { pr("\033[32m"); }
void Ye() { pr("\033[33m"); }
void BL() { pr("\033[34m"); }
void Pu() { pr("\033[35m"); }
void DG() { pr("\033[36m"); }
void Wh() { pr("\033[37m"); }
void Bo() { pr("\033[1m"); }
#include <thread>
#include <mutex>
typedef long long ll;
using namespace std;
using namespace chrono;
string args[10], targ[10];
 
int cnt;
bool no_com = 0, out_ac = 0, qstop = 0;
int cas = 1000; double t = 1000; bool fast = 0; bool fast2 = 0; bool online = 0;
int mem = 128 * 1024; int Max = 10;
queue<thread> q;
 
bool Compile(string filename, string tf) {
    if (sys("g++ " + tf + ".cpp -o cf/" + filename + " -Wall -Wno-unused-result " + (fast ? " -O2" : (fast2 ? "" : " -O2 -fsanitize=address,undefined")) + (online ? "" : " -DONLINE_JUDGE"))) return Bo(), 0;
    Bo(), Gr(), ps("Done"), Bl();
    return 1;
}
 
mutex m;
double cpp_tot = 0, std_tot = 0, rd_tot = 0;
ll cpp_mem = 0, std_mem = 0, rd_mem = 0;
int cas_tot = 0, unac_tot = 0;
 
bool Test(int i) {
    char s = 'P', s2 = 'P';
    double cpp = NAN, std = NAN, rd = NAN;
    int cppm = -1, stdm  = -1, rdm = -1;
    FILE * fe; int ret; char tmp[34];
    // run rand
    string tm = (string) "./data/tm" + to_string(i).c_str() + ".log";
    ret = sys("ulimit -s " + to_string(mem + 100) + " && /usr/bin/time -f \"%e %M\" -o " + tm + " ./cf/" + args[3] + " > ./data/rd" + to_string(i));
    if (ret) goto out;
    fe = fopen(tm.c_str(), "r"); fscanf(fe, "%lf%d", &rd, &rdm); rd *= 1000; fclose(fe);
    // run cpp
    ret = sys("ulimit -s " + to_string(mem + 100) + " && timeout 2> sb " + to_string(t / 1000 + 0.3) + " /usr/bin/time -f \"%e %M\" -o " + tm + " ./cf/" + args[1] + " < ./data/rd" + to_string(i) + " > ./data/cpp" + to_string(i));
    if (ret == 31744) { s = 'T'; goto out; }
    if (ret == 35584) { s = 'M'; goto out; }
    if (ret) { s = 'R'; goto out; }
    fe = fopen(tm.c_str(), "r"); fscanf(fe, "%lf%d", &cpp, &cppm); cpp *= 1000; fclose(fe);
    if (cpp >= t) { s = 'T'; goto out; }
    if (cppm > mem) { s = 'M'; goto out; }
    // run std
    ret = sys("ulimit -s " + to_string(mem + 100) + " && timeout 2> sb " + to_string(t / 1000 + 0.3) + " /usr/bin/time -f \"%e %M\" -o " + tm + " ./cf/" + args[2] + " < ./data/rd" + to_string(i) + " > ./data/std" + to_string(i));
    if (ret == 31744) { s2 = 'T'; goto out; }
    if (ret == 35584) { s2 = 'M'; goto out; }
    if (ret) { s2 = 'R'; goto out; }
    fe = fopen(tm.c_str(), "r"); fscanf(fe, "%lf%d", &std, &stdm); std *= 1000; fclose(fe);
    if (std >= t) { s2 = 'T'; goto out; }
    if (stdm > mem) { s2 = 'M'; goto out; }
    // diff
    if (sys("diff -Z ./data/cpp" + to_string(i) + " ./data/std" + to_string(i) + " > ./data/diff.log")) s = s2 = 'W';
    else s = s2 = 'A';
    // output
    out:
    lock_guard<mutex> Lock(m);
    ++cas_tot;
    if (s != 'A') ++unac_tot;
    if (s == 'A') cpp_tot += cpp, std_tot += std, rd_tot += rd, cpp_mem += cppm, std_mem += stdm, rd_mem += rdm;
    if (s != 'A' || out_ac) {
        if (s == 'A') Gr();
        else if (s == 'T' || s2 == 'T') Ye();
        else if (s == 'R' || s2 == 'R') Pu();
        else if (s == 'M' || s2 == 'M') BLK();
        else if (s == 'W') Re();
        pr("%03d ", i);
        putchar(s), putchar(' '), putchar(s2);
        pr(" %.0lfms %.0lfms %.0lfms %dMB %dMB %dMB\n", rd, cpp, std, rdm / 1024, cppm / 1024, stdm / 1024), Bl();
        if (qstop && s != 'A') { Wall, abort(); }
    }
    if (s != 'P' && s2 != 'P') sys(("rm " + tm).c_str());
    if (s != 'P') sys("rm ./data/cpp" + to_string(i));
    if (s2 != 'P') sys("rm ./data/std" + to_string(i));
    if (s == 'A') sys("rm ./data/rd" + to_string(i));
    return 0;
}
 
int main(int argv, char **argc) {
    Bo(), sys("rm -f ./data/*");
    for (int i = 1; i < argv; ++i) {
        string tmp = argc[i];
        if (tmp == "-n") no_com = 1;
        // no_com complie
        else if (tmp == "-l") ++i, cas = stoi(string(argc[i]));
        // testcases
        else if (tmp == "-t") ++i, t = stoi(string(argc[i]));
        // time limit
        else if (tmp == "-f") fast = 1;
        // fast mode (no_com fsanitize)
        else if (tmp == "-ff") fast2 = 1;
        // fast2 mode (no_com O2 & fsanitize)
        else if (tmp == "-m") ++i, mem = stoi(string(argc[i])) * 1024;
        // memory limit
        else if (tmp == "-a") out_ac = 1;
        // echo accept message
        else if (tmp == "-s") qstop = 1;
        // immediately stop when unaccepted
        else if (tmp == "-c") ++i, Max = stoi(string(argc[i]));
        // max number of threads
        else if (tmp == "-o") online = 1;
        // not online judge
        else args[++cnt] = argc[i];
    }
    targ[1] = args[1], targ[2] = args[2], targ[3] = args[3];
    pr("%scpp: %s%s.cpp\n", Pus, BLs, args[1].c_str());
    pr("%sstd: %s%s.cpp\n", Pus, BLs, args[2].c_str());
    pr("%srand: %s%s.cpp\n", Pus, BLs, args[3].c_str());
    if (fast) pr("%sFast Mode %sOn\n", Pus, BLs), pr("%sFsanitize %sDisabled\n", Pus, BLs);
    else if (fast2) pr("%sFast II Mode %sOn\n", Pus, BLs), pr("%sO2 %sDisabled\n", Pus, BLs), pr("%sFsanitize %sDisabled\n", Pus, BLs);
    if (no_com) pr("%sCompile %sDisabled\n", Pus, BLs);
    pr("%sTest Count: %s%d\n", Pus, BLs, cas);
    pr("%sThread Number: %s%d\n", Pus, BLs, Max);
    pr("%sTime Limit: %s%dms\n", Pus, BLs, int(t));
    pr("%sMemory Limit: %s%dMB\n", Pus, BLs, mem / 1024), Bl();
    Wall;
    if (!no_com) {
        COM(cpp); if (!Compile(args[1], targ[1])) CE(cpp);
        COM(std); if (!Compile(args[2], targ[2])) CE(std);
        COM(rand); if (!Compile(args[3], targ[3])) CE(rand);
    }
    Pu(), ps("Now Begin Test"), Bl(), Wall;
    steady_clock::time_point t1, t2; duration<double> ut;
    t1 = nnow;
    for (int i = 1; i != (cas + 1); ++i) {
        if ((int) q.size() > Max) q.front().join(), q.pop();
        q.push(thread(Test, i));
        if (i % 100 == 0) {
            lock_guard<mutex> Lock(m);
            int ac = cas_tot - unac_tot;
            printf("%s%d %sCases, %s%d %sWrongs, %s%.2lf%%%s\n", BLs, cas_tot, Pus, BLs, unac_tot, Pus, BLs, ac * 1.0 / cas_tot * 100, Pus);
            t2 = nnow; ut = dc;
            printf("Total: %s%.3lfs\n", BLs, ut.count());
            printf("%sAverage: %s%.0lfms %.0lfms %.0lfms %.0lfMB %.0lfMB %.0lfMB\n", Pus, BLs, rd_tot / ac, cpp_tot / ac, std_tot / ac, 1.0 * rd_mem / ac / 1024, 1.0 * cpp_mem / ac / 1024, 1.0 * std_mem / ac / 1024), Bl();
            Wall;
        }
    }
    while (!q.empty()) q.front().join(), q.pop();
    t2 = nnow; ut = dc;
    int ac = cas_tot - unac_tot;
    printf("%s%d %sCases, %s%d %sWrongs, %s%.2lf%%%s\n", BLs, cas_tot, Pus, BLs, unac_tot, Pus, BLs, ac * 1.0 / cas_tot * 100, Pus);
    printf("Total: %s%.3lfs\n", BLs, ut.count());
    printf("%sAverage: %s%.0lfms %.0lfms %.0lfms %.0lfMB %.0lfMB %.0lfMB\n", Pus, BLs, rd_tot / ac, cpp_tot / ac, std_tot / ac, 1.0 * rd_mem / ac / 1024, 1.0 * cpp_mem / ac / 1024, 1.0 * std_mem / ac / 1024), Bl();
    Bl(), Wall;
    sys("rm -f ./data/.f*");
    sys("rm sb");
    Gr(), ps("Finished"), Bl(), Wall;
}

魔改了一下,更符合个人习惯。

具体用法:
1.标准输入输出,开一个data文件夹
2.编译时加上 -pthread 后接 my std data (省略拓展名.cpp)
即 g++ -pthread while.cpp -o while && ./while my std data
接下来的,省略即为默认值
3.-l n :将测试点数设为n个(默认为1000个)
4.-t time :将时间限制设为time毫秒(默认为1000ms)
5.-m Mem :将内存限制设为MemMB(默认为128MB)
6.-f :关闭fsanitize
7.-ff :关闭O2和fsantize
8.-a :返回Accepted信息
9.-s :出现错误时立即终止
(转载自eafoo

高精度
namespace BIG_num{
	using cpx=complex<double>;const double PI=acos(-1);vector<cpx>roots= {{0,0},{1,0}};
	void ensure_capacity(int min_capacity) {
		for(int len=roots.size(); len<min_capacity; len*=2) {for(int i=len>>1; i<len; i++) {
			roots.emplace_back(roots[i]);double angle=2*PI*(2*i+1-len)/(len*2);roots.emplace_back(cos(angle),sin(angle));
		}}
	}
	void fft(vector<cpx>&z,bool inverse) {
		int n=z.size();ensure_capacity(n);
		for(int i=1,j=0; i<n; i++) {int BIGt=n>>1;for(; j>=BIGt; BIGt>>=1)j-=BIGt;j+=BIGt;if(i<j)swap(z[i],z[j]);}
		for(int len=1; len<n; len<<=1) {for(int i=0; i<n; i+=len*2) {for(int j=0; j<len; j++) {
			cpx root=inverse?conj(roots[j+len]):roots[j+len];cpx u=z[i+j];cpx v=z[i+j+len]*root;z[i+j]=u+v;z[i+j+len]=u-v;
		}}}if(inverse)for(int i=0; i<n; i++)z[i]/=n;
	}
	vector<int>multiply_BIG(const vector<int>&a,const vector<int>&b,int base) {
		int need=a.size()+b.size();int n=1;while(n<need)n<<=1;vector<cpx>p(n);
		for(int i=0; i<n; i++) {p[i]=cpx(i<(int)a.size()?a[i]:0,i<(int)b.size()?b[i]:0);}
		fft(p,false);vector<cpx>ab(n);cpx r(0,-0.25);
		for(int i=0; i<n; i++) {int j=(n-i)&(n-1);ab[i]=(p[i]*p[i]-conj(p[j]*p[j]))*r;}
		fft(ab,true);vector<int>result(need);long long carry=0;
		for(int i=0; i<need; i++) {long long d=(long long)(ab[i].real()+0.5)+carry;carry=d/base;result[i]=d%base;}
		return result;
	}
	vector<int>multiply_mod(const vector<int>&a,const vector<int>&b,int m) {
		int need=a.size()+b.size()-1;int n=1;while(n<need)n<<=1;vector<cpx>A(n);
		for(size_t i=0; i<a.size(); i++) {int x=(a[i]%m+m)%m;A[i]=cpx(x&((1<<15)-1),x>>15);}
		fft(A,false);vector<cpx>B(n);
		for(size_t i=0; i<b.size(); i++) {int x=(b[i]%m+m)%m;B[i]=cpx(x&((1<<15)-1),x>>15);}
		fft(B,false);vector<cpx>fa(n);vector<cpx>fb(n);
		for(int i=0,j=0; i<n; i++,j=n-i) {
			cpx a1=(A[i]+conj(A[j]))*cpx(0.5,0);cpx a2=(A[i]-conj(A[j]))*cpx(0,-0.5);
			cpx b1=(B[i]+conj(B[j]))*cpx(0.5,0);cpx b2=(B[i]-conj(B[j]))*cpx(0,-0.5);
			fa[i]=a1*b1+a2*b2*cpx(0,1);fb[i]=a1*b2+a2*b1;
		}fft(fa,true);fft(fb,true);vector<int>res(need);
		for(int i=0; i<need; i++) {
			long long aa=(long long)(fa[i].real()+0.5);long long bb=(long long)(fb[i].real()+0.5);
			long long cc=(long long)(fa[i].imag()+0.5);res[i]=(aa%m+(bb%m<<15)+(cc%m<<30))%m;
		}return res;
	}
	constexpr int digits(int base)noexcept {return base<=1?0:1+digits(base/10);} constexpr int base=1000000000;
	constexpr int base_digits=digits(base);constexpr int fft_base=10000;constexpr int fft_base_digits=digits(fft_base);
	struct BIG {
		vector<int>z;int sign;
		BIG(long long v=0) {*this=v;} 
        BIG&operator=(long long v) {
			sign=v<0?-1:1;v*=sign;z.clear();for(; v>0; v=v/base)z.push_back((int)(v%base));return*this;} 
        BIG(const string&s) {read(s);} 
		BIG&operator+=(const BIG&other) {
			if(sign==other.sign) {for(int i=0,carry=0; i<(int)other.z.size()||carry; ++i) {
					if(i==(int)z.size())z.push_back(0);z[i]+=carry+(i<(int)other.z.size()?other.z[i]:0);
					carry=z[i]>=base;if(carry)z[i]-=base;
			}} else if(other!=0) {*this-=-other;}return*this;} 
        friend BIG operator+(BIG a,const BIG&b) {a+=b;return a;} 
		BIG&operator-=(const BIG&other) {if(sign==other.sign) 
			{if((sign==1&&*this>=other)||(sign==-1&&*this<=other)){for(int i=0,carry=0;i<(int)other.z.size()||carry;++i)
			{z[i]-=carry+(i<(int)other.z.size()?other.z[i]:0);carry=z[i]<0;if(carry)z[i]+=base;}trim();
			} else {*this=other-*this;this->sign=-this->sign;}} else {*this+=-other;}return*this;} 
        friend BIG operator-(BIG a,const BIG&b) {a-=b;return a;}
		BIG&operator*=(int v) {if(v<0)sign=-sign,v=-v;
			for(int i=0,carry=0; i<(int)z.size()||carry; ++i) {
				if(i==(int)z.size())z.push_back(0);long long cur=(long long)z[i]*v+carry;
				carry=(int)(cur/base);z[i]=(int)(cur%base);
			}trim();return*this;} 
        BIG operator*(int v)const {return BIG(*this)*=v;}
		friend pair<BIG,BIG>divmod(const BIG&a1,const BIG&b1) {
			int norm=base/(b1.z.back()+1);BIG a=a1.abs()*norm;BIG b=b1.abs()*norm;BIG q,r;q.z.resize(a.z.size());
			for(int i=(int)a.z.size()-1; i>=0; i--) {
				r*=base;r+=a.z[i];int s1=b.z.size()<r.z.size()?r.z[b.z.size()]:0;
				int s2=b.z.size()-1<r.z.size()?r.z[b.z.size()-1]:0;int d=(int)(((long long)s1*base+s2)/b.z.back());
				r-=b*d;while(r<0)r+=b,--d;q.z[i]=d;
			}q.sign=a1.sign*b1.sign;r.sign=a1.sign;q.trim();r.trim();return {q,r/norm};} 
        friend BIG sqrt(const BIG&a1) {BIG a=a1;
			while(a.z.empty()||a.z.size()%2==1)a.z.push_back(0);int n=a.z.size();
			int firstDigit=(int)::sqrt((double)a.z[n-1]*base+a.z[n-2]);int norm=base/(firstDigit+1);
			a*=norm;a*=norm;while(a.z.empty()||a.z.size()%2==1)a.z.push_back(0);BIG r=(long long)a.z[n-1]*base+a.z[n-2];
			firstDigit=(int)::sqrt((double)a.z[n-1]*base+a.z[n-2]);int q=firstDigit;BIG res;
			for(int j=n/2-1; j>=0; j--) {for(;; --q) {
				BIG r1=(r-(res*2*base+q)*q)*base*base+(j>0?(long long)a.z[2*j-1]*base+a.z[2*j-2]:0);if(r1>=0){r=r1;break;}
				}res*=base;res+=q;if(j>0) {
					int d1=res.z.size()+2<r.z.size()?r.z[res.z.size()+2]:0;
					int d2=res.z.size()+1<r.z.size()?r.z[res.z.size()+1]:0;
					int d3=res.z.size()<r.z.size()?r.z[res.z.size()]:0;
					q=(int)(((long long)d1*base*base+(long long)d2*base+d3)/(firstDigit*2));
			}}res.trim();return res/norm;} 
        BIG operator/(const BIG&v)const {return divmod(*this,v).first;} 
		BIG operator%(const BIG&v)const {return divmod(*this,v).second;} 
		BIG&operator/=(int v) {if(v<0)sign=-sign,v=-v;
			for(int i=(int)z.size()-1,rem=0; i>=0; --i) {
				long long cur=z[i]+rem*(long long)base;z[i]=(int)(cur/v);rem=(int)(cur%v);
			}trim();return*this;} 
        BIG operator/(int v)const {return BIG(*this)/=v;} 
		int operator%(int v)const {
			if(v<0)v=-v;int m=0;for(int i=(int)z.size()-1; i>=0; --i)m=(int)((z[i]+m*(long long)base)%v);return m*sign;} 
        BIG&operator*=(const BIG&v) {*this=*this*v;return*this;} 
		BIG&operator/=(const BIG&v) {*this=*this/v;return*this;} 
		BIG&operator%=(const BIG&v) {*this=*this%v;return*this;} 
		bool operator<(const BIG&v)const {if(sign!=v.sign)return sign<v.sign;
			if(z.size()!=v.z.size())return z.size()*sign<v.z.size()*v.sign;
			for(int i=(int)z.size()-1; i>=0; i--)if(z[i]!=v.z[i])return z[i]*sign<v.z[i]*sign;return false;} 
        bool operator>(const BIG&v)const {return v<*this;} 
		bool operator<=(const BIG&v)const {return!(v<*this);} 
		bool operator>=(const BIG&v)const {return!(*this<v);} 
		bool operator==(const BIG&v)const {return sign==v.sign&&z==v.z;} 
		bool operator!=(const BIG&v)const {return!(*this==v);
		}void trim(){while(!z.empty()&&z.back()==0)z.pop_back();if(z.empty())sign=1;} 
		bool isZero()const {return z.empty();} 
		friend BIG operator-(BIG v) {if(!v.z.empty())v.sign=-v.sign;return v;} 
		BIG abs()const {return sign==1?*this:-*this;} 
		long long to_num()const {
			long long res=0;for(int i=(int)z.size()-1; i>=0; i--)res=res*base+z[i];return res*sign;} 
        friend BIG gcd(const BIG&a,const BIG&b) {return b.isZero()?a:gcd(b,a%b);} 
		friend BIG lcm(const BIG&a,const BIG&b) {return a/gcd(a,b)*b;} 
		friend BIG fpw(BIG a,BIG b) {BIG ans=1;while(!b.isZero()){if(b%2) ans*=a;a*=a,b/=2;}return ans;} 
		void read(const string&s) {
			sign=1;z.clear();int pos=0;
			while(pos<(int)s.size()&&(s[pos]=='-'||s[pos]=='+')) {if(s[pos]=='-')sign=-sign;++pos;}
			for(int i=(int)s.size()-1; i>=pos; i-=base_digits) {int x=0;
				for(int j=max(pos,i-base_digits+1); j<=i; j++)x=x*10+s[j]-'0';z.push_back(x);
			}trim();} 
        friend istream&operator>>(istream&stream,BIG&v) {string s;stream>>s;v.read(s);return stream;} 
		friend ostream&operator<<(ostream&stream,const BIG&v) {
			if(v.sign==-1)stream<<'-';stream<<(v.z.empty()?0:v.z.back());
			for(int i=(int)v.z.size()-2; i>=0; --i)stream<<setw(base_digits)<<setfill('0')<<v.z[i];return stream;
		} static vector<int>convert_base(const vector<int>&a,int old_digits,int new_digits) {
			vector<long long>p(max(old_digits,new_digits)+1);p[0]=1;
			for(int i=1; i<(int)p.size(); i++)p[i]=p[i-1]*10;vector<int>res;long long cur=0;int cur_digits=0;
			for(int v:a) {cur+=v*p[cur_digits];cur_digits+=old_digits;while(cur_digits>=new_digits)
				{res.push_back(int(cur%p[new_digits]));cur/=p[new_digits];cur_digits-=new_digits;}
			}res.push_back((int)cur);while(!res.empty()&&res.back()==0)res.pop_back();return res;} 
        BIG operator*(const BIG&v)const {
			if(min(z.size(),v.z.size())<150)return mul_simple(v);BIG res;res.sign=sign*v.sign;
			res.z=multiply_BIG(convert_base(z,base_digits,fft_base_digits),convert_base(v.z,base_digits,fft_base_digits),fft_base);
			res.z=convert_base(res.z,fft_base_digits,base_digits);res.trim();return res;} 
        BIG mul_simple(const BIG&v)const {BIG res;res.sign=sign*v.sign;res.z.resize(z.size()+v.z.size());
			for(int i=0; i<(int)z.size(); ++i)if(z[i])for(int j=0,carry=0; j<(int)v.z.size()||carry; ++j) {
				long long cur=res.z[i+j]+(long long)z[i]*(j<(int)v.z.size()?v.z[j]:0)+carry;
				carry=(int)(cur/base);res.z[i+j]=(int)(cur%base);
			}res.trim();return res;
		}
	};
	mt19937 rng(std::chrono::system_clock::now().time_since_epoch().count());
	BIG BIG_rnd(int n) {string s;for(int i=0; i<n; i++) {s+=uniform_int_distribution<int>('0','9')(rng);}return BIG(s);}
}

注意:

int a;BIG b;
if(b>a) return a;

是对的

int a;BIG b;
if(a<b) return a;

是错的

快读1
char *p1,*p2,buf[1<<20];
#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++)
#ifdef linux
#define pc putchar_unlocked
#else
#define pc putchar
#endif
namespace IO{
    template<typename T>inline bool read(T &x){x=0;char s=gc();bool f=true;for(;(s<'0'||'9'<s);s=gc()) {if(s=='-') f=false;if(s==EOF)return false;}for(;'0'<=s&&s<='9';s=gc()) x=(x<<1)+(x<<3)+(s^48);if(!f) x=~x+1;return true;}
    inline bool read(double &x){x=0.0;char s=gc();bool f=true;for(;(s<'0'||'9'<s);s=gc()){if(s=='-') f=false;if(s==EOF)return false;}for(;'0'<=s&&s<='9';s=gc())x=(x*10)+(s^48);if(s!='.'){x=f?x:-x;return true;}double res=0.1;s=gc();for(;'0'<=s&&s<='9';res/=10,s=gc()) x+=(s^48)*res;x=f?x:-x;return true;}
    inline bool read(long double &x){x=0.0;char s=gc();bool f=true;for(;(s<'0'||'9'<s);s=gc()){if(s=='-') f=false;if(s==EOF)return false;}for(;'0'<=s&&s<='9';s=gc())x=(x*10)+(s^48);if(s!='.'){x=f?x:-x;return true;}double res=0.1;s=gc();for(;'0'<=s&&s<='9';res/=10,s=gc()) x+=(s^48)*res;x=f?x:-x;return true;}
    inline bool read(float &x){x=0.0;char s=gc();bool f=true;for(;(s<'0'||'9'<s);s=gc()){if(s=='-') f=false;if(s==EOF)return false;}for(;'0'<=s&&s<='9';s=gc())x=(x*10)+(s^48);if(s!='.'){x=f?x:-x;return true;}double res=0.1;s=gc();for(;'0'<=s&&s<='9';res/=10,s=gc()) x+=(s^48)*res;x=f?x:-x;return true;}
    inline bool read(string &str){string ().swap(str);char s=gc();for(;s==' '||s=='\n'||s == '\r';s=gc());if(s==EOF) return false; for(;s!=' '&&s!='\n'&&s!='\r'&&s!=EOF;s=gc())str.push_back(s);return true;}
    inline bool read_line(string &str){string ().swap(str);char s=gc();for(;s==' '||s=='\n'||s=='\r';s=gc());if(s==EOF) return false;for(;s!='\n'&&s!='\r'&&s!=EOF;s=gc()){str.push_back(s);}return true;}
    inline bool read_line(char *str){int len=0;char s=gc();for(;s==' '||s=='\n'||s=='\r';s=gc());if(s==EOF) return false;for(;s!='\n'&&s=='\r'&&s!=EOF;s=gc()){str[len]=s;len++;}str[len]='\0';return true;}
    inline bool read(char &s){char x=gc();for(;x==' '||x=='\n'||x=='\r';x=gc());if(x==EOF||x==' '||x=='\n'||x=='\r')return false;s=x;return true;}
    inline bool read(char *s){int len=0;char x=gc();for(;x==' '||x=='\n'||x=='\r';x=gc());if(x==EOF)return false;for(;x!=' '&&x!='\n'&&x!='\r'&&x!=EOF;x=gc())s[len++]=x;s[len]='\0';return true;}
    template<class T,class... Args> inline bool read(T &x,Args&... args){return (read(x)&&read(args...));}
    template<class T>inline void write(T x){static T st[45];int top=0;if(x<0)x=~x+1,pc('-');do{st[top++]=x%10;}while(x/=10);while(top)pc(st[--top]^48);}
    inline void write(char x){pc(x);}
    inline void write(string s){for(int i=0;s[i];++i) pc(s[i]);}
    inline void write(char *s){int len=strlen(s);for(int i=0;i<len;++i) pc(s[i]);}
    inline void write(const char *s){int len=strlen(s);for(int i=0;i<len;++i) pc(s[i]);}
    template<class T,class... Args> inline void write(T x,Args... args){write(x);write(args...);}
}using namespace IO;
快读2 by wkh
namespace IO{
    #ifdef LOCAL
    FILE*Fin(fopen("in.in","r")),*Fout(fopen("out.out","w"));
    #else
    FILE*Fin(stdin),*Fout(stdout);
    #endif
    class qistream{static const size_t SIZE=1<<26,BLOCK=64;FILE*fp;char buf[SIZE];int p;public:qistream(FILE*_fp=stdin):fp(_fp),p(0){fread_unlocked(buf+p,1,SIZE-p,fp);}void flush(){memmove(buf,buf+p,SIZE-p),fread_unlocked(buf+SIZE-p,1,p,fp),p=0;}qistream&operator>>(char&str){str=getch();while(isspace(str))str=getch();return*this;}template<class T>qistream&operator>>(T&x){x=0;p+BLOCK>=SIZE?flush():void();bool flag=false;for(;!isdigit(buf[p]);++p)flag=buf[p]=='-';for(;isdigit(buf[p]);++p)x=x*10+buf[p]-'0';x=flag?-x:x;return*this;}char getch(){return buf[p++];}qistream&operator>>(char*str){char ch=getch();while(ch<=' ')ch=getch();for(int i=0;ch>' ';++i,ch=getch())str[i]=ch;return*this;}}qcin(Fin);
    class qostream{static const size_t SIZE=1<<26,BLOCK=64;FILE*fp;char buf[SIZE];int p;public:qostream(FILE*_fp=stdout):fp(_fp),p(0){}~qostream(){fwrite_unlocked(buf,1,p,fp);}void flush(){fwrite_unlocked(buf,1,p,fp),p=0;}template<class T>qostream&operator<<(T x){int len=0;p+BLOCK>=SIZE?flush():void();x<0?(x=-x,buf[p++]='-'):0;do buf[p+len]=x%10+'0',x/=10,++len;while(x);for(int i=0,j=len-1;i<j;++i,--j)swap(buf[p+i],buf[p+j]);p+=len;return*this;}qostream&operator<<(char x){putch(x);return*this;}void putch(char ch){p+BLOCK>=SIZE?flush():void();buf[p++]=ch;}qostream&operator<<(char*str){for(int i=0;str[i];++i)putch(str[i]);return*this;}}qcout(Fout);
}using namespace IO;
posted @ 2024-04-17 17:29  CuFeO4  阅读(30)  评论(0编辑  收藏  举报