F 题求调
  • 板块学术版
  • 楼主1234567890sjx
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/12/14 21:57
  • 上次更新2024/12/15 09:19:54
查看原帖
F 题求调
1013955
1234567890sjx楼主2024/12/14 21:57

咋调不出来了/kel

#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#include <bits/stdc++.h>
#define int long long
#define eb emplace_back
#define range(x) x.begin(),x.end()
using namespace std;
const int N = 1000100;
const int mod = 998244353;
const int base = 256;
const int inf = 0x0d000721ll << 2 | 0xAC66666;
 
namespace ttq012 {
int read() {
    int o = 1, x = 0;
    char ch;
    while (!isdigit(ch = getchar())) {
        if (ch == '-') {
            o = -o;
        }
    }
    x = ch & 15;
    while (isdigit(ch = getchar())) {
        x = (x << 3) + (x << 1) + (ch & 15);
    }
    return x * o;
}
 
int exgcd(int a, int b, int &x, int &y) {
    if (!b) {
        x = 1, y = 0;
        return a;
    }
    int g, xp, yp;
    g = exgcd(b, a % b, xp, yp); 
    x = yp, y = xp - yp * (a / b);
    return g;
}
 
int ksm(int a, int b, int c) {
    a %= c;
    int ans = 1;
    while (b) {
        if (b & 1) {
            ans = 1ll * ans * a % c;
        }
        a = 1ll * a * a % c;
        b >>= 1;
    }
    return ans;
}

int Inv(int a, int Mod) {
    return ksm(a, Mod - 2, Mod);
}

int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
 
int lcm(int a, int b) {
    return a / gcd(a, b) * b;
}

void swap(int &a, int &b) {
    if (a != b) a ^= b ^= a ^= b;
} } // using namespace ttq012;

namespace ttq012 {

void chkmax(int &x, int y) {
    if (x < y) x = y;
}
void chkmin(int &x, int y) {
    if (x > y) x = y;
}

int a[N];
int f(int x) {
    if (x & 1) return x;
    return f(x >> 1);
}
int s1[N], s2[N], s;
void get(vector<int> v1, vector<int> v2, int dep = 0) {
    if (v1.empty() && v2.empty()) return;
    if (v1.size() + v2.size() == 1) return;
    int n1 = v1.size(), n2 = v2.size();
    if (dep % 2 == 0) {
        int s1 = accumulate(range(v1), 0ll);
        int s2 = accumulate(range(v2), 0ll);
        int ts = s;
        s += n1 * s2 + n2 * s1 + n1 * n2 * dep;
        // cout << "awa: ";
        // for (auto &x : v1) cout << x << ' ';
        // cout << "; ";
        // for (auto &x : v2) cout << x << ' ';
        // cout << ' ';
        // cout << s - ts << '\n';
    } else {
        if (v1.size()) s1[0] = v1[0];
        for (int i = 1; i < v1.size(); ++i) s1[i] = s1[i - 1] + v1[i];
        if (v2.size()) s2[0] = v2[0];
        for (int i = 1; i < v2.size(); ++i) s2[i] = s2[i - 1] + v2[i];
        int ts = s;
        for (int i = 1; i < v1.size(); ++i) s += s1[i - 1] + v1[i] + i * dep;
        for (int i = 1; i < v2.size(); ++i) s += s2[i - 1] + v2[i] + i * dep;
        // cout << "qwq: ";
        // for (auto &x : v1) cout << x << ' ';
        // cout << "; ";
        // for (auto &x : v2) cout << x << ' ';
        // cout << ' ';
        // cout << s - ts << '\n';
    }
    for (auto &i : v1) i >>= 1;
    for (auto &i : v2) i >>= 1;
    vector<int> v3, v4;
    for (auto &i : v2)
        if (i & 1) v3.eb(i);
        else v4.eb(i);
    get(v3, v4, dep);
    v3.clear(), v4.clear();
    for (auto &i : v1)
        if (i & 1) v3.eb(i);
        else v4.eb(i);
    get(v3, v4, dep + 1);
}
int buc[10001000], buc2[10001000];
void run() {
    int n = read(), pre = 0;
    for (int i = 1; i <= n; ++i) a[i] = read(), s += ((pre += a[i]) + a[i] * i);
    int t = 0;
    for (int i = 1; i <= n; ++i) t += f(a[i] + a[i]);
    vector<int> ji, ou;
    for (int i = 2; i <= 1e7; i <<= 1) {
        for (int j = 0; j < i; ++j) buc[j] = buc2[j] = 0;
        int t = 0;
        for (int j = 1; j <= n; ++j) {
            ++buc2[a[j] % i];
            buc[a[j] % i] += a[j];
            t += buc[(i - a[j] % i) % i] + a[j] * buc2[(i - a[j] % i) % i];
        }
        s = s - t / i;
    }
    cout << s << '\n';
} 
}

signed main() {
    ttq012::run();
    return 0;
}

2024/12/14 21:57
加载中...