跳到正文

科技·工程

模板

Andy_hpy约 12 分钟
原文
文章信息与版本

文章信息

收录
2026年1月9日
更新
2026年6月28日
篇幅
约 12 分钟

版本

  1. v3当前
  2. v2
  3. v1

洛谷互助

缺省源
C++
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef __int128 LL;
const ll MAXN = 1e5 + 5;
const ll MOD = 1e9 + 7;
const ll INF = INT_MAX;
const ll LINF = LLONG_MAX;
const db EPS = 1e-5;
*|*
int main() {
    
    return 0;
}
快读快写
C++
#include <bits/stdc++.h>
#ifdef __unix__
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#endif
using namespace std;
typedef long long ll;
#ifdef __unix__
uint8_t* str;
#define gc() (*str++)
#else
#define gc() (_getchar_nolock())
#endif
ll read(){
    ll f = 1, k = 0; int8_t c = gc();
    for (; c <= 32 && c > 0; c = gc());
    for (; c == '-'; c = gc()) f *= -1;
    for (; c >= 48; c = gc()) k = (k << 3) + (k << 1) + (c ^ 48);
    return k * f;
}
ll s[35], t;
char buf[1000500];
ll top, msz = 1000000;
void write(ll x){
    if (x < 0){
        buf[top++] = '-'; x = -x;
    }
    if (x == 0) buf[top++] = '0';
    t = 0;
    while (x){
        s[t++] = x % 10;
        x /= 10;
    }
    while (t){
        buf[top++] = s[--t] + '0';
    }
    if (top > msz){
        fwrite(buf, sizeof(buf[0]), top, stdout);
        top = 0;
    }
}
void write(const char* s){
    for (ll i = 0; s[i]; i++){
        buf[top++] = s[i];
    }
    if (top > msz){
        fwrite(buf, sizeof(buf[0]), top, stdout);
        top = 0;
    }
}
void write(char c){
    buf[top++] = c;
    if (top > msz){
        fwrite(buf, sizeof(buf[0]), top, stdout);
        top = 0;
    }
}
int main(){
#ifdef __unix__
    struct stat s;
    fstat(0, &s);
    str = (uint8_t*) mmap(NULL, s.st_size, 1, 2, 0, 0);
#endif
	*|*
    fwrite(buf, sizeof(buf[0]), top, stdout);
    return 0;
}
高精度(暂未完结)
C++
class bignum
{
    public:
    ll len = 1, num[MAXN] = {};
    bignum(){
        len = 1;
        num[1] = 0;
    }
    bignum(ll x){
        len = 0;
        while (x){
            num[++len] = x % 10;
            x /= 10;
        }
    }
    bignum(string str){
        reverse(str.begin(), str.end());
        len = 0;
        for (int i = 0; i < str.size(); i++){
            num[++len] = str[i] - '0';
        }
    }
};

inline bignum operator + (const bignum& a, const bignum& b){
    bignum ans = 0;
    ans.len = max(a.len, b.len) + 1;
    ll r = 0;
    for (int i = 1; i <= ans.len; i++){
        ll tmp = a.num[i] + b.num[i] + r;
        r = tmp / 10;
        ans.num[i] = tmp % 10;
    }
    if (ans.num[ans.len] == 0)
        ans.len--;
    return ans;
}

inline bignum operator += (bignum& a, const bignum& b){
    a = a + b;
    return a;
}

inline bignum operator * (const bignum& a, const bignum& b){
    bignum ans;
    ans.len = a.len + b.len + 1;
    memset(ans.num, 0, sizeof(ans.num[0]) * (ans.len + 5));
    for (int i = 1; i <= a.len; i++){
        for (int j = 1; j <= b.len; j++){
            ans.num[i + j - 1] += a.num[i] * b.num[j];
            ans.num[i + j] += ans.num[i + j - 1] / 10;
            ans.num[i + j - 1] %= 10;
        }
    }
    while (ans.num[ans.len] == 0 && ans.len > 1){
        ans.len--;
    }
    return ans;
}

inline bignum operator *= (bignum& a, const bignum& b){
    a = a * b;
    return a;
}

inline bignum operator / (const bignum& a, const ll& b){
    bignum ans;
    ans.len = a.len;
    ll r = 0;
    for (int i = a.len; i >= 1; i--){
        r = r * 10 + a.num[i];
        ans.num[i] = r / b;
        r %= b;
    }
    while (ans.num[ans.len] == 0 && ans.len > 1){
        ans.len--;
    }
    return ans;
}

inline bignum operator /= (bignum& a, const ll& b){
    a = a / b;
    return a;
}

inline bool operator < (const bignum& a, const bignum& b){
    if (a.len != b.len) return a.len < b.len;
    for (int i = a.len; i >= 1; i--){
        if (a.num[i] != b.num[i]) return a.num[i] < b.num[i];
    }
    return false;
}

inline bool operator <= (const bignum& a, const bignum& b){
    if (a.len != b.len) return a.len < b.len;
    for (int i = a.len; i >= 1; i--){
        if (a.num[i] != b.num[i]) return a.num[i] < b.num[i];
    }
    return true;
}

inline bool operator > (const bignum& a, const bignum& b){
    if (a.len != b.len) return a.len > b.len;
    for (int i = a.len; i >= 1; i--){
        if (a.num[i] != b.num[i]) return a.num[i] > b.num[i];
    }
    return false;
}

inline bool operator >= (const bignum& a, const bignum& b){
    if (a.len != b.len) return a.len > b.len;
    for (int i = a.len; i >= 1; i--){
        if (a.num[i] != b.num[i]) return a.num[i] > b.num[i];
    }
    return true;
}

inline bool operator == (const bignum& a, const bignum& b){
    if (a.len != b.len) return false;
    for (int i = a.len; i >= 1; i--){
        if (a.num[i] != b.num[i]) return false;
    }
    return true;
}

inline bool operator != (const bignum& a, const bignum& b){
    if (a.len != b.len) return true;
    for (int i = a.len; i >= 1; i--){
        if (a.num[i] != b.num[i]) return true;
    }
    return false;
}

inline ostream& operator << (ostream& os, const bignum& o){
    for (int i = o.len; i >= 1; i--){
        os << o.num[i];
    }
    return os;
}

inline istream& operator >> (istream& is, bignum& o){
    o = 0;
    char c = getchar();
    bool flag = false;
    while ('0' > c || c > '9'){
        c = getchar();
    }
    if (c == '-'){
        flag = true;
        c = getchar();
    }
    while ('0' <= c && c <= '9'){
        o = o * 10 + bignum(c - '0');
        c = getchar();
    }
    if (flag) o = o * -1;
    return is;
}

inline string to_string(const bignum& o){
    string ans = "";
    for (int i = o.len; i >= 1; i--){
        ans += to_string(o.num[i]);
    }
    return ans;
}

inline bignum pow(const bignum& _a, const ll& _b){
    bignum ans = 1, base = _a;
    ll b = _b;
    while (b){
        if (b & 1){
            ans *= base;
        }
        base *= 2;
        b >>= 1;
    }
    return ans;
}
原文