跳到正文

芝麻馅儿汤圆

53141

看灰机!!

在洛谷打开
资料、奖项与版本

资料

编号
53141
抓取

920418653

C++
vector<long long> B;
    int insert(long long x)
    {
        for (auto b : B)
            x = min(x, b ^ x);
        for (auto& b : B)
            b = min(b, b ^ x);
        if (x)
            B.push_back(x);
        if (x)	return 1;
        return 0;
    }

离散化

C++
for (int i = 1; i <= n; i++) {
	cin >> a1[i];
	a2[i] = a1[i];
}
sort(a1 + 1, a1 + n + 1);
int len = unique(a1 + 1, a1 + n + 1) - a1 - 1;
for (int i = 1; i <= n; i++)
	a2[i] = lower_bound(a1 + 1, a1 + 1 + len, a2[i]) - a1;

三目并查集

C++
int find(int x) {
	return f[x] == x ? x : f[x] = find(f[x]);
}

三目二元gcd

C++
int gcd(int a, int b) {
	return b > 0 ? gcd(b, a % b) : a;
}

带模运算模板类

C++
template<const int T>
struct ModInt {
    const static int mod = T;
    int x;
    ModInt(int x = 0) : x(x % mod) {}
    int val() { return x; }
    ModInt operator + (const ModInt &a) const { int x0 = x + a.x; return ModInt(x0 < mod ? x0 : x0 - mod); }
    ModInt operator - (const ModInt &a) const { int x0 = x - a.x; return ModInt(x0 < mod ? x0 + mod : x0); }
    ModInt operator * (const ModInt &a) const { return ModInt(1LL * x * a.x % mod); }
    ModInt operator / (const ModInt &a) const { return *this * a.inv(); }
    void operator += (const ModInt &a) { x += a.x; if (x >= mod) x -= mod; }
    void operator -= (const ModInt &a) { x -= a.x; if (x < 0) x += mod; }
    void operator *= (const ModInt &a) { x = 1LL * x * a.x % mod; }
    void operator /= (const ModInt &a) { *this = *this / a; }
    friend ostream &operator<<(ostream &os, const ModInt &a) { return os << a.x;}
    
    ModInt pow(int64_t n) const {
        ModInt res(1), mul(x);
        while(n){
            if (n & 1) res *= mul;
            mul *= mul;
            n >>= 1;
        }
        return res;
    }
    
    ModInt inv() const {
        int a = x, b = mod, u = 1, v = 0;
        while (b) {
            int t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        if (u < 0) u += mod;
        return u;
    }
    
};
typedef ModInt<mod> mint;

还没有收录这位用户的文章。