QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#113207 | #1944. Circle of Friends | ckiseki# | WA | 1ms | 3424kb | C++14 | 3.3kb | 2023-06-16 17:47:01 | 2023-06-16 17:47:04 |
Judging History
answer
#include <bits/stdc++.h>
#ifdef CKISEKI
#define safe cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
using std::cerr;
template <typename ...T>
void debug_(const char *s, T ...a) {
cerr << "\e[1;32m(" << s << ") = (";
int cnt = sizeof...(T);
(..., (cerr << a << (--cnt ? ", " : ")\e[0m\n")));
}
template <typename I>
void orange_(const char *s, I L, I R) {
cerr << "\e[1;32m[ " << s << " ] = [ ";
for (int f = 0; L != R; ++L)
cerr << (f++ ? ", " : "") << *L;
cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) ((void)0)
#define orange(...) ((void)0)
#endif
#define all(v) begin(v),end(v)
using namespace std;
const int mod = 998244353;
const int64_t INF = (1LL << 60) - 1;
int modadd(int a, int b) {
return a + b >= mod ? a + b - mod : a + b;
}
int modsub(int a, int b) {
return a - b < 0 ? a - b + mod : a - b;
}
signed main() {
cin.tie(nullptr) -> sync_with_stdio(false);
int n;
cin >> n;
vector<int64_t> a(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
debug(bitset<5>(a[i]));
}
{
int64_t totand = INF;
for (int i = 1; i <= n; i++)
totand &= a[i];
if (totand) {
int ans = 1;
for (int i = 0; i < n; i++)
ans = modadd(ans, ans);
cout << ans << '\n';
return 0;
}
}
vector<int> bad(n + 1);
{
int idx[60] = {};
// memset(idx, -1, sizeof(idx));
for (int i = 1; i <= n; i++) {
int mn = 1e9;
for (int j = 0; j < 60; j++) {
if (!(a[i] >> j & 1)) {
idx[j] = i;
}
mn = min(idx[j], mn);
}
bad[i] = mn;
}
}
orange(all(bad));
vector<int64_t> pre(n + 2), suf(n + 2);
pre[0] = INF;
for (int i = 1; i <= n; i++) {
pre[i] = pre[i - 1] & a[i];
}
suf[n + 1] = INF;
for (int i = n; i >= 1; i--)
suf[i] = suf[i + 1] & a[i];
vector<int> dp(n + 2);
vector<int> predp(n + 2);
int ans = 0;
{
dp[0] = 1;
predp[0] = 1;
for (int i = 1; i <= n; i++) {
// bad[i] := minimum j, AND(a[j], a[j+1], ... a[i]) != 0
// dp[i] =
// dp[i-1]+dp[i-2]+...+dp[bad[i]+1] + dp[bad[i]]
dp[i] = modsub(predp[i - 1], (bad[i] == 0 ? 0 : predp[bad[i] - 1]));
predp[i] = modadd(predp[i - 1], dp[i]);
}
debug(dp[n]);
ans = dp[n];
}
for (int i = 1, j; i <= n; i = j) {
for (j = i; j <= n; j++)
if (pre[j] != pre[i])
break;
debug(pre[i], i, j);
fill(dp.begin(), dp.end(), 0);
for (int t = i; t < j; t++)
dp[t] = 1;
dp[0] = predp[0] = 0;
for (int t = 1; t <= n; t++) {
dp[t] = modadd(dp[t], modsub(predp[t - 1], (bad[t] == 0 ? 0 : predp[bad[t] - 1])));
predp[t] = modadd(predp[t - 1], dp[t]);
if (t + 1 <= n && suf[t + 1] & pre[i]) {
debug(t, suf[t + 1], pre[i], dp[t], predp[t]);
ans = modadd(ans, dp[t]);
}
}
}
cout << ans << '\n';
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3424kb
input:
1 1
output:
2
result:
wrong answer 1st lines differ - expected: '1', found: '2'