跳到正文

剪贴板

剪贴板 gzjq709t

原文
剪贴板信息

剪贴板信息

收录
更新
C++
```cpp
inline char gc() {
  static constexpr int BufferSize = 1 << 22 | 5;
  static char buf[BufferSize], *p, *q;
  static std::streambuf *i = std::cin.rdbuf();
  return p == q ? p = buf, q = p + i->sgetn(p, BufferSize), p == q ? EOF : *p++ : *p++;
}
struct Reader {
  template <class T>
  Reader &operator>>(T &w) {
    char c, p = 0;
    for (; !std::isdigit(c = gc());) if (c == '-') p = 1;
    for (w = c & 15; std::isdigit(c = gc()); w = w * 10 + (c & 15)) ;
    if (p) w = -w;
    return *this;
  }
} cin;

#define LUOGU
#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt")
#if defined(LOCAL) or not defined(LUOGU)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,unroll-loops")
#endif

namespace slowIO
{
	const int _Pu = 1 << 23;
	const int _d = 32;
	char buf[_Pu];
	char obuf[_Pu];
	char *p1 = buf + _Pu;
	char *p2 = buf + _Pu;
	char *p3 = obuf, *p4 = obuf + _Pu - _d;
	inline void flushin()
	{
		memmove(buf, p1, p2 - p1);
		int rlen = fread(buf + (p2 - p1), 1, p1 - buf, stdin);
		if (p1 - rlen > buf) { buf[p2 - p1 + rlen] = EOF; }
		p1 = buf;
	}
	inline void flushout() { fwrite(obuf, p3 - obuf, 1, stdout), p3 = obuf; }
	template <typename T> inline void read(T &x)
	{
		if (p1 + _d > p2) { flushin(); }
		int isne = 0;
		for (; !isdigit(*p1); ++p1) { isne = (*p1 == '-'); }
		x = (*p1++ - '0');
	    for (; isdigit(*p1); ++p1) { x = x * 10 + (*p1 - '0'); }
		if (isne) { x = -x; }
	}
	template <typename T> inline void write(T x, char end = '\n')
	{
		if (p3 > p4) { flushout(); }
		if (x < 0) { *p3++ = '-'; x = -x; }
		char sta[20];
		char *top = sta;
		do { *top++ = (x % 10) + '0'; x /= 10; } while (x);
		do { *p3++ = *--top; } while (top != sta);
		(*p3++) = end;
	}
} using namespace slowIO;

#pragma GCC optimize(3,"Ofast","inline")
#pragma GCC optimize(3,"Ofast","inline","-fgcse","-fgcse-lm","-fipa-sra","-ftree-pre","-ftree-vrp","-fpeephole2","-ffast-math","-fsched-spec","unroll-loops","-falign-jumps","-falign-loops","-falign-labels","-fdevirtualize","-fcaller-saves","-fcrossjumping","-fthread-jumps","-funroll-loops","-fwhole-program","-freorder-blocks","-fschedule-insns","inline-functions","-ftree-tail-merge","-fschedule-insns2","-fstrict-aliasing","-fstrict-overflow","-falign-functions","-fcse-skip-blocks","-fcse-follow-jumps","-fsched-interblock","-fpartial-inlining","no-stack-protector","-freorder-functions","-findirect-inlining","-fhoist-adjacent-loads","-frerun-cse-after-loop","inline-small-functions","-finline-small-functions","-ftree-switch-conversion","-foptimize-sibling-calls","-fexpensive-optimizations","-funsafe-loop-optimizations","inline-functions-called-once","-fdelete-null-pointer-checks")
#pragma GCC target("avx,sse,sse2,sse3,sse4,mmx")

#pragma GCC optimize(3,"Ofast","inline")
#pragma GCC optimize(3,"Ofast","inline","-fgcse","-fgcse-lm","-fipa-sra","-ftree-pre","-ftree-vrp","-fpeephole2","-ffast-math","-fsched-spec","unroll-loops","-falign-jumps","-falign-loops","-falign-labels","-fdevirtualize","-fcaller-saves","-fcrossjumping","-fthread-jumps","-funroll-loops","-fwhole-program","-freorder-blocks","-fschedule-insns","inline-functions","-ftree-tail-merge","-fschedule-insns2","-fstrict-aliasing","-fstrict-overflow","-falign-functions","-fcse-skip-blocks","-fcse-follow-jumps","-fsched-interblock","-fpartial-inlining","no-stack-protector","-freorder-functions","-findirect-inlining","-fhoist-adjacent-loads","-frerun-cse-after-loop","inline-small-functions","-finline-small-functions","-ftree-switch-conversion","-foptimize-sibling-calls","-fexpensive-optimizations","-funsafe-loop-optimizations","inline-functions-called-once","-fdelete-null-pointer-checks")
#pragma GCC target("avx,sse,sse2,sse3,sse4,mmx")


struct FastMod {
    typedef unsigned long long ULL;
    typedef __uint128_t LLL;
    ULL b, m;
    inline void init(ULL b) { this->b = b, m = ULL((LLL(1) << 64) / b); }
    inline ULL mod(ULL a) {
        ULL q = (ULL)((LLL(m) * a) >> 64);
        ULL r = a - q * b;
        return r >= b ? r - b : r;
    }
} Q;
代码