TLE 求卡常,加 constexpr AC
  • 板块P5110 块速递推
  • 楼主andyli
  • 当前回复2
  • 已保存回复2
  • 发布时间2020/7/10 09:09
  • 上次更新2023/11/6 23:22:05
查看原帖
TLE 求卡常,加 constexpr AC
84282
andyli楼主2020/7/10 09:09

TLE:
R34994271
R34994276

namespace Mker {
    uint64_t SA, SB, SC;
    void init() { io.read(SA, SB, SC); }
    inline auto rand() {
        SA ^= SA << 32, SA ^= SA >> 13, SA ^= SA << 1;
        static uint64_t t;
        t = SA;
        SA = SB, SB = SC, SC ^= t ^ SA;
        return SC;
    }
}  // namespace Mker
int quick_pow(int a, int n, int MOD) {
    int ans = 1;
    while (n) {
        if (n & 1)
            ans = 1LL * ans * a % MOD;
        a = 1LL * a * a % MOD;
        n >>= 1;
    }
    return ans;
}
const int MOD = 1000000007, maxn = 1 << 16;
const int x3 = 94153035, x4 = 905847205, x1 = quick_pow(x3, maxn, MOD), x2 = quick_pow(x4, maxn, MOD);

int f1[maxn]{1}, f2[maxn]{1}, f3[maxn]{1}, f4[maxn]{1};
inline int pow1(int x) { return 1LL * f1[x >> 16] * f3[x & 65535] % MOD; }
inline int pow2(int x) { return 1LL * f2[x >> 16] * f4[x & 65535] % MOD; }

int main() {
    int q;
    io.read(q);
    Mker::init();
    for (int i = 1; i < maxn; i++) {
        f1[i] = 1LL * f1[i - 1] * x1 % MOD;
        f2[i] = 1LL * f2[i - 1] * x2 % MOD;
        f3[i] = 1LL * f3[i - 1] * x3 % MOD;
        f4[i] = 1LL * f4[i - 1] * x4 % MOD;
    }
    int ans = 0;
    while (q--) {
        int n = Mker::rand() % (MOD - 1);
        ans ^= (233230706LL * (pow1(n) - pow2(n) + MOD) % MOD);
    }
    writeln(ans);
    return 0;
}

AC:
R34994262
R34994280

namespace Mker {
    uint64_t SA, SB, SC;
    void init() { io.read(SA, SB, SC); }
    inline auto rand() {
        SA ^= SA << 32, SA ^= SA >> 13, SA ^= SA << 1;
        static uint64_t t;
        t = SA;
        SA = SB, SB = SC, SC ^= t ^ SA;
        return SC;
    }
}  // namespace Mker
constexpr int quick_pow(int a, int n, int MOD) {
    int ans = 1;
    while (n) {
        if (n & 1)
            ans = 1LL * ans * a % MOD;
        a = 1LL * a * a % MOD;
        n >>= 1;
    }
    return ans;
}
#include <array>
constexpr int MOD = 1000000007, maxn = 1 << 16;
constexpr int x3 = 94153035, x4 = 905847205, x1 = quick_pow(x3, maxn, MOD), x2 = quick_pow(x4, maxn, MOD);

inline constexpr auto generateF() {
    std::array<int, maxn> f1{1}, f2{1}, f3{1}, f4{1};
    for (int i = 1; i < maxn; i++) {
        f1[i] = 1LL * f1[i - 1] * x1 % MOD;
        f2[i] = 1LL * f2[i - 1] * x2 % MOD;
        f3[i] = 1LL * f3[i - 1] * x3 % MOD;
        f4[i] = 1LL * f4[i - 1] * x4 % MOD;
    }
    return std::array<std::array<int, maxn>, 4>{f1, f2, f3, f4};
}
constexpr auto f = generateF();
constexpr auto f1 = f[0], f2 = f[1], f3 = f[2], f4 = f[3];
inline constexpr int pow1(int x) { return 1LL * f1[x >> 16] * f3[x & 65535] % MOD; }
inline constexpr int pow2(int x) { return 1LL * f2[x >> 16] * f4[x & 65535] % MOD; }

int main() {
    int q;
    io.read(q);
    Mker::init();
    int ans = 0;
    while (q--) {
        int n = Mker::rand() % (MOD - 1);
        ans ^= (233230706LL * (pow1(n) - pow2(n) + MOD) % MOD);
    }
    writeln(ans);
    return 0;
}
2020/7/10 09:09
加载中...