QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#863227 | #9745. 递增序列 | asaltfish | WA | 104ms | 6120kb | C++14 | 4.4kb | 2025-01-19 14:47:51 | 2025-01-19 14:47:52 |
Judging History
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;
}
now = k;
for (int i = 1;i <= n;i++)
{
a[i] ^= now;
}
for (int i = 2;i <= n;i++)
if (a[i] < a[i - 1])
flag = 1;
flag = 1 - flag;
cout << ans+flag << endl;
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 6120kb
input:
1 4 17 3 2 5 16
output:
4
result:
ok single line: '4'
Test #2:
score: -100
Wrong Answer
time: 104ms
memory: 3968kb
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 414708220571820991 716398192192370638 0 1949654914769744 0 0 0 811009189367843523 0 0 0 114457959388827201 53638684746708800 0 0 91540211282631659 0 694703231769895640 144115188075855872 0 0 0 0 432345564227567616 389592326132793601 753346372609875093 72057594...
result:
wrong answer 15th lines differ - expected: '114457959388827198', found: '114457959388827201'