QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#360599#7932. AND-OR closureVengeful_Spirit#WA 35ms20156kbC++201.8kb2024-03-21 22:23:462024-03-21 22:23:46

Judging History

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

  • [2024-03-21 22:23:46]
  • 评测
  • 测评结果:WA
  • 用时:35ms
  • 内存:20156kb
  • [2024-03-21 22:23:46]
  • 提交

answer

#include<bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

map<ll, int> find(vector<ll> a) {
    map<ll, int> mp;
    int n = a.size();
    for(int i = 0; i < (1 << n); ++i) {
        ll pos = 0;
        for(int j = 0; j < n; ++j) if((i >> j) & 1) {
            pos |= a[j];
        }
        mp[pos] = 1;
    }
    return mp;
}

const int MN = 1 << 20;
int len = MN;

void FWT_or(ll *a, int m) {
    for(int k = 1; k < len; k <<= 1) {
        for(int i = 0; i < len; i += k << 1) {
            for(int j = 0; j < k; ++j) 
                a[i + j + k] = ~m ? a[i + j + k] + a[i + j] : a[i + j + k] - a[i + j];
        }
    }
}

ll A[MN], B[MN];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;
    ll inf = (1ll << 40) - 1;
    vector<ll> a(40, 0);
    for(int i = 1; i <= n; ++i) {
        ll x;
        cin >> x;
        for(int j = 40; j >= 0; --j) if((x >> j) & 1) {
            if(a[j]) a[j] &= x;
            else a[j] = x;
        }
    }
    sort(all(a));
    a.erase(unique(all(a)), a.end());
    // for(ll x : a) cerr << x << "a\n";
    vector<ll> b, c;
    int sz = a.size();
    for(int i = 0; i < sz / 2; ++i) b.push_back(a[i]);
    for(int i = sz / 2; i < sz; ++i) c.push_back(a[i]);
    ll pos = (1ll << 20) - 1;
    map<ll, int> mp1 = find(b), mp2 = find(c);
    for(auto [x, y] : mp1) {
        // cerr << x << " " << y << "\n";
        B[x & pos] += y;
    }
    for(auto [x, y] : mp2) {
        // cerr << x << " " << y << "\n";
        A[x & pos] += y;
    } 
    ll ans = 0;
    FWT_or(A, 1);
    FWT_or(B, 1);
    for(int i = 0; i < MN; ++i) A[i] *= B[i];
    FWT_or(A, -1);
    for(int i = 0; i < MN; ++i) ans += (A[i] >= 1);
    cout << ans << "\n";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 23ms
memory: 19940kb

input:

4
0 1 3 5

output:

5

result:

ok 1 number(s): "5"

Test #2:

score: 0
Accepted
time: 24ms
memory: 20156kb

input:

5
0 1 2 3 4

output:

8

result:

ok 1 number(s): "8"

Test #3:

score: -100
Wrong Answer
time: 35ms
memory: 20004kb

input:

49
1097363587067 1096810445814 275012137504 1096739142630 1096809921522 1087071335264 829364908576 949625500192 1087142638448 1096200190829 1097292808175 1095750860656 1087144145776 1097346808827 1095734082416 1096755396578 829230678048 1095663303524 1087072842592 1096216444777 949623992864 10962714...

output:

49

result:

wrong answer 1st numbers differ - expected: '52', found: '49'