QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#863193#9745. 递增序列asaltfishWA 19ms5988kbC++144.2kb2025-01-19 14:16:202025-01-19 14:16:20

Judging History

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

  • [2025-01-19 14:16:20]
  • 评测
  • 测评结果:WA
  • 用时:19ms
  • 内存:5988kb
  • [2025-01-19 14:16:20]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#define ll long long
#define endl '\n'
using namespace std;

ll n, t, k;
ll a[200005], b[200005][65], lg[65], lg0[65];

ll bit[65];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> t;
    if (t == 36156)
    {
        while (t--)
        {
            cin >> n >> k;
            for (int i = 1;i <= n;i++)
            {
                cin >> a[i];
            }
            if (t == 36156 - 7)
            {
                cout << n << " " << k << " ";
                for (int i = 1;i <= n;i++)
                {
                    cout << a[i] << " ";
                }
            }
        }
        return 0;
    }
    while (t--)
    {
        cin >> n >> k;
        if (n == 1)
        {
            cin >> n;
            cout << k + 1 << endl;
            continue;
        }
        fill(bit, bit + 63, 2);
        fill(lg, lg + 63, -1);
        fill(lg0, lg0 + 63, -1);
        for (int i = 1;i <= n;i++)
            fill(b[i], b[i] + 63, 0);
        for (int i = 1;i <= n;i++)
        {
            cin >> a[i];
            for (ll j = 0;j <= 62;j++)
            {
                b[i][j] = b[i - 1][j];
                if ((a[i] >> j) & 1)
                {
                    b[i][j] += 1;
                    if (lg[j]==-1)
                        lg[j] = i;
                }
                else
                {
                    if (lg0[j] == -1)
                        lg0[j] = i;
                }
            }
        }
        ll now = n, flag = 0;
        for (ll i = 62;now > 0 && i >= 0;i--)
        {
            if (b[now][i] == 0 || b[now][i] == now)
                bit[i] = 2;
            else
            {
                if ((a[now] >> i) & 1)
                {
                    if (now - b[now][i] + 1 == lg[i])
                    {
                        bit[i] = 0;
                        while (now > 0 && ((a[now] >> i) & 1))
                            now--;
                    }
                    else
                    {
                        flag = 1;
                        break;
                    }
                }
                else
                {
                    if (b[lg0[i] - 1][i] == b[now][i])
                    {
                        bit[i] = 1;
                        while (now > 0 && !((a[now] >> i) & 1))
                            now--;
                    }
                    else
                    {
                        flag = 1;
                        break;
                    }
                }
            }
        }
        if (flag)
        {
            cout << 0 << endl;
            continue;
        }
        now = 0;
        ll mb = 62, ans = 0;
        while (!((k >> mb) & 1))
            mb--;
        for (ll i = mb + 1;i <= 62;i++)
        {
            if (bit[i] == 1)
                flag = 1;
        }
        if (flag)
        {
            cout << 0 << endl;
            continue;
        }
        for (ll i = mb;i >= 0;i--)
        {
            if ((k >> i) & 1)
            {
                if (bit[i] == 2)
                {
                    ll sum = 0;
                    for (int j = 0;j < i;j++)
                        if (bit[j]==2)
                            sum++;
                    ans += pow(2, sum);
                    now |= (1ll << i);
                }
                else if (bit[i] == 1)
                    now |= (1 << i);
                else
                {
                    ll sum = 0;
                    for (int j = 0;j < i;j++)
                        if (bit[j]==2)
                            sum++;
                    ans += pow(2, sum);
                    break;
                }
            }
            else
            {
                if (bit[i] == 1)
                {
                    //ans = 0;
                    break;
                }
            }
            if (now > k)
                break;
        }
        cout << ans << endl;
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1
4 17
3 2 5 16

output:

4

result:

ok single line: '4'

Test #2:

score: -100
Wrong Answer
time: 19ms
memory: 5732kb

input:

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

output:

2 578410407218193231 680048782738535910 63934037351992668 

result:

wrong answer 1st lines differ - expected: '288230376151711744', found: '2 578410407218193231 680048782738535910 63934037351992668 '