比赛 2024暑假C班集训7 评测结果 AAAAAAAAATTTTTTTTTTT
题目名称 收益 最终得分 45
用户昵称 darkMoon 运行时间 52.048 s
代码语言 C++ 内存使用 319.21 MiB
提交时间 2024-07-07 11:32:30
显示代码纯文本
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define mp make_pair
using namespace std;
//#define fin cin
//#define fout cout
ifstream fin("x.in");
ofstream fout("x.out");
auto mread = [](){
    int x;
    fin >> x;
    return x;
};
const int N = 4e6 + 5;
int n = mread(), k = mread(), seed = mread(), a[N], ans, e[N], d[N], s[N], fa[N];
vector<int> v[N];
set<pair<int, int> > q;
void build(int x){
    s[x] += a[x];
    for(int y : v[x]){
        d[y] = d[x] + 1;
        s[y] = s[x];
        build(y);
    }
    q.insert(mp(s[x], x));
    return;
}
void dfs(int x, int root){
    q.erase(mp(s[x], x));
    s[x] -= a[root];
    q.insert(mp(s[x], x));
    for(int y : v[x]){
        dfs(y, root);
    }
    return;
}
void solve(){
    if(q.size() == 0)
    return;
    auto tmp = q.end();
    tmp --;
    int p = (*tmp).se;
    ans += (*tmp).fi;
    int x = p;
    while(x && e[x] == 0){
        e[x] = 1;
        dfs(x, x);
        x = fa[x];
        q.erase(mp(s[x], x));
    }
    return;
}
signed main(){
    a[1] = seed;
    for(int i = 2; i <= n; i ++){
        a[i] = (a[i - 1] * 23333333 + 6666666) % 1000000007;
        fa[i] = (a[i] ^ 23333333) % (i - 1) + 1;
        v[fa[i]].push_back(i);
    }
    d[1] = 1;
    build(1);
    for(int i = 1; i <= k; i ++)
    solve(); 
    fout << ans;
    return 0;
}