QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#520910#1436. Split in SetskoukileeCompile Error//C++203.3kb2024-08-15 17:23:562024-08-15 17:23:56

Judging History

你现在查看的是最新测评结果

  • [2024-08-15 17:23:56]
  • 评测
  • [2024-08-15 17:23:56]
  • 提交

answer

/* The code is from koukilee*/
#include <cstdio>
#include <algorithm>
#include <vector>

using i32 = int; using i64 = long long; // std::mt19937 rd(time(0));
constexpr i64 MAXN = 1010100, mod = 1e9 + 7, INF = 992009100720100812; 

//static char buf[1000000],*p1=buf,*p2=buf,obuf[1000000],*p3=obuf;
//#define getchar() p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++
//#define putchar(x) (p3-obuf<1000000)?(*p3++=x):(fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=x)
inline void read (i64 &sum) noexcept {
    i64 tf = 0; char ch = getchar(); sum = 0;
    while (ch < '0' || ch > '9') tf = ch == '-' ? 1 : 0, ch = getchar();
    while (ch >= '0' && ch <= '9') sum = (sum << 1) + (sum << 3) + (ch ^ 48), ch = getchar();
    (tf) && (sum =- sum);
}template <typename i64,typename ...Args>
inline void read (i64 &tmp, Args &...tmps) noexcept{read(tmp); read(tmps...);}
void printt (i64 x) noexcept {if(x >= 10) printt(x / 10); putchar(x % 10 + '0');} 
inline void print (i64 x) noexcept{x < 0 ? putchar('-'), printt(-x) : printt(x);}
inline void put (i64 x) noexcept{print(x), putchar('\n');}

inline i64 min(i64 a, i64 b) noexcept{return a < b ? a : b;}

i64 n, k, s[MAXN], fac[MAXN], inv[MAXN], ans, cnt = 1;

i64 fpow(i64 x, i64 y) noexcept{
    if (!y) return 1;
    if (y & 1) return fpow(x, y - 1) * x % mod;
    else{
        i64 base = fpow(x, y >> 1) % mod;
        return base * base % mod;
    }
}

inline i64 C(i64 x, i64 y) noexcept{
    if (x < y || x < 0 || y < 0) return 0;
    return fac[x] * inv[y] % mod * inv[x - y] % mod;
}

inline i64 ask(i64 x, i64 y) noexcept{
    i64 res = 0;

    for (i32 i = 0; i <= y; i++){
        if (i & 1)
            res = (res + mod - C(y, i) * fpow(y - i, x) % mod) % mod;
        else  
            res = (res + C(y, i) * fpow(y - i, x) % mod) % mod;
    }

    return res * inv[y] % mod;
}

void dfs(std::vector<i64> A, i64 k, i64 dep){
    if (k > A.size()) return;

    i64 cnt0 = 0, cnt1 = 0;
    for (auto it : A)
        if ((it >> dep) & 1) ++cnt1;
        else ++cnt0;
    
    ans += min(k - (cnt0 > 0), cnt1) * (1ll << dep);

    if (!dep){
        if (k > cnt1)
            cnt = cnt * ask(cnt0, k - cnt1) % mod;
        else   
            cnt = cnt * ask(1 + cnt1, k) % mod;
        return;
    }

    std::vector<i64> B;
    if (k > cnt1){
        for (auto it : A)
            if ((~it >> dep) & 1) B.push_back(it);
            else ans += it & ((1 << dep) - 1);
        dfs(B, k - cnt1, dep - 1); 
    } else{
        i64 asum = INT_MAX;
        for (auto it : A)   
            if ((it >> dep) & 1) B.push_back(it);
            else asum &= it;
        
        if (cnt0) B.push_back(asum);
        dfs(B, k, dep - 1);
    }
}

int main() noexcept{
    read(n, k);

    for (i32 i = 1; i <= n; i++)
        read(s[i]);
    
    fac[0] = 1;
    for (i32 i = 1; i <= n; i++)
        fac[i] = fac[i - 1] * i % mod;
    inv[n] = fpow(fac[n], mod - 2);
    for (i32 i = n - 1; ~i; i--){
        inv[i] = inv[i + 1] * (i + 1) % mod;
    }

    // std::sort(s + 1, s + n + 1);

    std::vector<i64> all (s + 1, s + n + 1);
    dfs(all, k, 30);

    cnt = cnt * fac[k] % mod;

    print(ans), putchar(' '), put(cnt);
    //fwrite(obuf,p3-obuf,1,stdout);
    return 0;
}

详细

answer.code: In function ‘void dfs(std::vector<long long int>, i64, i64)’:
answer.code:79:20: error: ‘INT_MAX’ was not declared in this scope
   79 |         i64 asum = INT_MAX;
      |                    ^~~~~~~
answer.code:5:1: note: ‘INT_MAX’ is defined in header ‘<climits>’; did you forget to ‘#include <climits>’?
    4 | #include <vector>
  +++ |+#include <climits>
    5 |