QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#794057#9745. 递增序列pengpeng_fudan#WA 34ms3748kbC++231.3kb2024-11-30 10:21:342024-11-30 10:21:36

Judging History

This is the latest submission verdict.

  • [2024-11-30 10:21:36]
  • Judged
  • Verdict: WA
  • Time: 34ms
  • Memory: 3748kb
  • [2024-11-30 10:21:34]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'

#define maxn 200005
#define maxlgn 62

int64_t a[maxn];
int choice[maxn];
int64_t suf[maxlgn];

void solve(int t, int l, int r) {
    if (t == -1 || l == r) return;
    int x = -1;
    for (int i = l; i < r; i++)
        if ((a[i] >> t & 1) ^ (a[i + 1] >> t & 1)) {
            if (~x) return choice[t] = 0, void();
            x = i;
        }
    if (!~x) return solve(t - 1, l, r);
    choice[t] &= (1 << (a[x] >> t & 1));
    return solve(t - 1, l, x), solve(t - 1, x + 1, r);
}

void solve(void) {
    int n;
    int64_t k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i];

    for (int t = maxlgn - 1; ~t; t--) choice[t] = 3;
    solve(maxlgn - 1, 1, n);
    for (int i = 0; i < maxlgn; i++)
        if (!choice[i]) return cout << 0 << endl, void();

    suf[0] = 1;
    for (int i = 1; i < maxlgn; i++) suf[i] = suf[i - 1] * __builtin_popcount(choice[i - 1]);

    int64_t ans = 0;
    for (int i = maxlgn - 1; ~i; i--) {
        bool t = (k >> i & 1);
        if (t && (choice[i] & 1)) ans += suf[i];
        if (!(choice[i] >> t & 1)) break;
    }

    cout << ans << endl;

    return;
}

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

    int _ = 1;
    cin >> _;
    while (_--) solve();

    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3748kb

input:

1
4 17
3 2 5 16

output:

4

result:

ok single line: '4'

Test #2:

score: -100
Wrong Answer
time: 34ms
memory: 3604kb

input:

36156
2 732025001343805266
563399128172323734 55283226774627822
7 388099190813067712
564150557919527813 457487771983557281 332055400678110195 760833651510929158 785768483273197875 690506113272551236 463276585748519124
2 798714574862593347
426890163990834364 434764725667883272
1 414708220571820990
42...

output:

288230376151711744
0
432345564227567616
414708220571820990
716398192192370637
0
1949654914769743
0
0
0
811009189367843522
0
0
0
114457959388827197
36028797018963968
0
0
91540211282631658
0
694703231769895639
144115188075855872
0
0
0
0
432345564227567616
65333152962117910
753346372609875092
180143985...

result:

wrong answer 4th lines differ - expected: '414708220571820991', found: '414708220571820990'