QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#752433#858. GCD vs. XORkangkunmaWA 7ms32588kbC++201.4kb2024-11-16 02:56:492024-11-16 02:56:50

Judging History

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

  • [2024-11-16 02:56:50]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:32588kb
  • [2024-11-16 02:56:49]
  • 提交

answer

#include <iostream>
#include <vector>
#include <set>

using namespace std;

const int MAX = 1000001;

vector<vector<int>> D(MAX);

void initialize() {
    for (int i = 0; i < 1000; ++i) {
        for (int j = i + 1; j < MAX / (i + 1); ++j) {
            if (((i + 2) * j) == (j | (i + 1) * j)) {
                D[(i + 1) * j].push_back(i + 1);
            }
        }
    }
}

long long s(const vector<int>& l) {
    vector<int> C(MAX, 0);
    long long A = 0;

    // Count occurrences
    for (int i : l) {
        C[i]++;
    }

    set<int> unique_l(l.begin(), l.end());
    for (int i : unique_l) {
        for (int j : D[i]) {
            if (i + j > MAX) break;

            if ((i + j) == (j | i)) {
                A += static_cast<long long>(C[i]) * C[i + j];
            }

            if (i / j + i <= MAX) {
                if ((i + i / j) == ((i / j) | i) && j * j != i) {
                    A += static_cast<long long>(C[i]) * C[i / j + i];
                }
            }
        }
    }

    return A;
}

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

    initialize();

    int t;
    cin >> t;

    while (t--) {
        int n;
        cin >> n;

        vector<int> l(n);
        for (int i = 0; i < n; ++i) {
            cin >> l[i];
        }

        cout << s(l) << endl;
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 7ms
memory: 32588kb

input:

1
4
2 3 4 3

output:

0

result:

wrong answer 1st numbers differ - expected: '2', found: '0'