版本比较
Jason331 的武功秘籍
正文
增加 256 行删除 18 行
123456789101112131415161718192021222324256 行未改动3233343536373839404142434445462547484950515253545556575859606162636465666768697071727328747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921034211212213214215392162172182192204122122243223224225226227228229230231232233234235236237238239240241242243244245246454647484924724824925052251252253254255256257545525825926026126226326426526626726826927058271272273274275276636427727827928028128228328428528628728828929029129229329429529629729829930030130230330430530687 行未改动394395396397164398399400401402403:::info[代码模板]```cpp line-numbers// Code By Jason331#include <bits/stdc++.h>#include <cassert>#ifdef __unix__#include <sys/mman.h>#endif#include <sys/stat.h>#include <fcntl.h>#include <unistd.h>// #define TOOT_TOOT#ifdef TOOT_TOOT#pragma GCC optimize(2,3,"-fdelete-null-pointer-checks,inline-functions-called-once,-funsafe-loop-optimizations,-fexpensive-optimizations,-foptimize-sibling-calls,-ftree-switch-conversion,-finline-small-functions,inline-small-functions,-frerun-cse-after-loop,-fhoist-adjacent-loads,-findirect-inlining,-freorder-functions,no-stack-protector,-fpartial-inlining,-fsched-interblock,-fcse-follow-jumps,-fcse-skip-blocks,-falign-functions,-fstrict-overflow,-fstrict-aliasing,-fschedule-insns2,-ftree-tail-merge,inline-functions,-fschedule-insns,-freorder-blocks,-fwhole-program,-funroll-loops,-fthread-jumps,-fcrossjumping,-fcaller-saves,-fdevirtualize,-falign-labels,-falign-loops,-falign-jumps,unroll-loops,-fsched-spec,-ffast-math,-fpeephole2,-ftree-vrp,-ftree-pre,-fipa-sra,-fgcse-lm,-fgcse,inline,Ofast")#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")#endifusing namespace std;#define heap priority_queue#define uset unordered_set#define umap unordered_map#define mpr make_pair// #include <bits/extc++.h>// #define map gp_hash_table// using namespace __gnu_cxx;// using namespace __gnu_pbds;6 行未改动#define CONST __attribute__((const))#define PURE __attribute__((pure))#define PACKED __attribute__((packed))#define START __attribute__((constructor))#define END __attribute__((destructor))#define told __builtin_expect#define range(i,start,end) for(auto i = (start);i <= (end);i++)#define rrange(i,start,end) for(auto i = (start);i >= (end);i--)#define rep(i,start,end) for(auto i = (start);i < (end);i++)#define rrep(i,start,end) for(auto i = (start);i > (end);i--)#define print_list(name,start,end) \ printf("%s[%d-%d]: ",#name,start,end);\ range(i,start,end) printf("%d ",name[i]);\ printf("\n");
signed main()#ifdef ONLINE_JUDGE#define DEBUG 0#define READ_FROM_FILE 1#else#define DEBUG 0#define READ_FROM_FILE 1#endif
mt19937 rng(15);
namespace FastIO{ #if DEBUG // nothing #else constexpr int __ISIZ = 1 << 16,__OSIZ = 1 << 16;// buf size char __ibuf[__ISIZ],__obuf[__OSIZ];// buf char *__ip1 = __ibuf,*__ip2 = __ibuf,*__op1 = __obuf; char *const __op2 = __obuf + __OSIZ; #ifdef __unix__ #ifdef READ_FROM_FILE struct stat __state; uint8_t *__ip;
int __mmap_init = []{ fstat(0,&__state); __ip = (uint8_t*)mmap(NULL,__state.st_size,PROT_READ,MAP_PRIVATE,0,0); return 0; return 0; } (); #else #define buf_read(buf,size) read(0,buf,size) #endif #define buf_write(buf,size) write(1,buf,size) #else #define buf_read(buf,size) fread(buf,1,size,stdin) #define buf_write(buf,size) fwrite(buf,1,size,stdout) #endif inline END void flush() { buf_write(__obuf,__op1 - __obuf); __op1 = __obuf; } #endif
inline char getc() { #if DEBUG return getchar(); #else #if defined(__unix__) && READ_FROM_FILE return *__ip++; #else if(told(__ip1 == __ip2,false)) __ip2 = (__ip1 = __ibuf) + buf_read(__ibuf,__ISIZ); return __ip1 == __ip2?-1:*__ip1++; #endif #endif }
inline void putc(char c) { #if DEBUG putchar(c); #else *__op1++ = c; if(told(__op1 == __op2,false)) flush(); #endif }
inline void write(char c) {putc(c);}
inline void write(const char *s) { for(const char *p = s;*p;p++) putc(*p); }
inline void read(char &c) {c = getc();} inline void read(char *s) { char *p = s - 1; do *++p = getc(); while(!isspace(*p)); *p = '\0'; }
template <typename T> inline bool check_read(T &x) { bool f = false; char c; for(c = getc();!isdigit(c) && c != '-' && ~c;c = getc()); if(c == '-') { f = true; c = getc(); } if(told(c == -1,false)) return false; for(x = 0;isdigit(c);c = getc()) x = x * 10 + (c ^ '0'); if(f) x = -x; return true; }
template <typename T> inline void read(T &x) { bool f = false; char c; for(c = getc();!isdigit(c) && c != '-';c = getc()); if(c == '-') { f = true; c = getc(); } for(x = 0;isdigit(c);c = getc()) x = x * 10 + (c ^ '0'); if(f) x = -x; }
template <typename T> inline void write(T x) { static constexpr int PSIZ = 40; static char sta[PSIZ]; signed char top = 0; if(x < 0) x = -x,putc('-'); do sta[top++] = x % 10 + '0'; while(x /= 10); while(top--) putc(sta[top]); }
template <typename T,typename... Ts> inline void read(T &x,Ts&... other) { read(x); read(other...); }
template <typename T,typename... Ts> inline void write(T x,Ts... other) { write(x); write(other...); }
template <typename... Ts> inline void writeln(Ts... x) {write(x...,'\n');} inline int readint() {int x;read(x);return x;} inline ll readll() {ll x;read(x);return x;}}
using namespace FastIO;
signed main(){ return 0;}```:::
:::success[快读]:::success[Fast IO(快速输入输出)]
膜拜(目前)天下第一快读:[link](https://www.luogu.com.cn/article/2pbig65w)
本人常用的快读模板:本人常用的输入输出模板:
注意:此模板无法正确输出 `INT_MIN` 和 `LONG_LONG_MIN`,需要转换为范围更大的类型再输出,输入此类数时会产生有符号整型溢出的 UB,但是一般不会出锅。
```cpp line-numbersnamespace fast_readnamespace{ inline char getc() constexpr int PSIZ = 40,ISIZ = 1 << 16,OSIZ = ISIZ; char ibuf[ISIZ],obuf[OSIZ],st[PSIZ]; char *ip1 = ibuf,*ip2 = ibuf,*outp1 = obuf,*const outp2 = obuf + OSIZ,ltop; inline END void flush() {fwrite(obuf,1,outp1 - obuf,stdout);outp1 = obuf;} inline char getc() {if(ip1 == ip2) ip2 = (ip1 = ibuf) + fread(ibuf,1,ISIZ,stdin);return ip1 == ip2?-1:*ip1++;} inline void putc(char c) {*outp1++ = c;if(outp1 == outp2) flush();} template <typename T> inline void read(T &x) {bool flag = false;char c;for(c = getc();c < '0' && c != '-';c = getc());if(c == '-') flag = true,c = getc();for(x = 0;c >= '0';c = getc()) x = x * 10 + (c ^ '0');if(flag) x = -x;} template <typename T> inline void write(T x) {if(x < 0) putc('-'),x = -x;ltop = 0;do st[ltop++] = char(x % 10 ^ '0');while(x /= 10);while(ltop--) putc(st[ltop]);} template <typename T,typename... Ts> inline void read(T &x,Ts&... other) {read(x);read(other...);} template <typename T,typename... Ts> inline void write(char gap,T x,Ts... other) {write(x),putc(gap);write(other...);}}```
:::info[非压行版本]
```cpp line-numbersnamespace{ constexpr int PSIZ = 40,ISIZ = 1 << 16,OSIZ = ISIZ; char ibuf[ISIZ],obuf[OSIZ],st[PSIZ]; char *ip1 = ibuf,*ip2 = ibuf,*outp1 = obuf,*const outp2 = obuf + OSIZ,ltop;
inline END void flush() { static constexpr int SIZ = 1 << 16; static char buf[SIZ],*begin = buf,*end = buf; if(begin == end) end = (begin = buf) + fread(buf,1,SIZ,stdin); return *begin++; fwrite(obuf,1,outp1 - obuf,stdout); outp1 = obuf; }
inline void read() {} inline char getc() { if(ip1 == ip2) ip2 = (ip1 = ibuf) + fread(ibuf,1,ISIZ,stdin); return ip1 == ip2?-1:*ip1++; }
template <class T> inline void read(T &x) inline void putc(char c) { *outp1++ = c; if(outp1 == outp2) flush(); }
//WARNING: this function will make UB when input the min value of the variable //however, the result is correct most of the time template <typename T> inline void read(T &x) { bool flag = false; char c; for(c = getc();c < '0';c = getc()); for(c = getc();c < '0' && c != '-';c = getc()); if(c == '-') flag = true,c = getc(); for(x = 0;c >= '0';c = getc()) x = x * 10 + (c ^ '0'); }
template <class T,class... types> inline void read(T &x,types&... other) //WARNING: this function cannot output the min value of the variable correctly //if you want to output an variable int x = INT_MIN //you should use "write((long long) x)" template <typename T> inline void write(T x) { if(x < 0) putc('-'),x = -x; ltop = 0; do st[ltop++] = x % 10 + '0'; while(x /= 10); while(ltop--) putc(st[ltop]); }
template <typename T,typename... Ts> inline void read(T &x,Ts&... other) { read(x); read(other...); }
template <typename T,typename... Ts> inline void write(char gap,T x,Ts... other) { write(x),putc(gap); write(other...); }}```
:::87 行未改动```:::
:::warning[属性(attribute)]C++ 中的属性(attribute)是C++ 中的属性(attribute)是可以让我们沟通编译器的神器。
很多属性并不会改变代码功能,但依旧起着很重要的作用。
以后再来填坑吧。:::