QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#113193 | #1944. Circle of Friends | ckiseki# | WA | 1ms | 3456kb | C++14 | 3.1kb | 2023-06-16 17:20:40 | 2023-06-16 17:20:42 |
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);
for (int i = 0; i < n; i++) {
cin >> a[i];
debug(bitset<5>(a[i]));
}
{
int64_t totand = INF;
for (int i = 0; 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);
{
int idx[60] = {};
for (int i = 0; i < n; i++) {
int mn = 1e9;
for (int j = 0; j < 60; j++) {
if (!(a[i] >> j & 1)) {
idx[j] = i + 1;
}
mn = min(idx[j], mn);
}
bad[i] = mn;
}
}
vector<int64_t> pre(n + 1), suf(n + 1);
pre[0] = INF;
for (int i = 0; i < n; i++) {
pre[i + 1] = pre[i] & a[i];
}
suf[n] = INF;
for (int i = n - 1; i >= 0; i--)
suf[i] = suf[i + 1] & a[i];
orange(all(bad));
vector<int> dp(n + 1);
vector<int> predp(n + 1);
int ans = 0;
{
predp[0] = 0;
for (int t = 0; t + 1 < n; t++) {
if (pre[t + 1]) dp[t] = modadd(dp[t], 1);
dp[t] = modadd(dp[t], modsub(predp[t], predp[bad[t]]));
predp[t + 1] = modadd(predp[t], dp[t]);
debug(t, dp[t], predp[t], suf[t + 1]);
if (suf[t + 1]) ans = modadd(ans, dp[t]);
}
debug(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] = 1;
predp[0] = 0;
for (int t = 0; t + 1 < n; t++) {
dp[t] = modadd(dp[t], modsub(predp[t], predp[bad[t]]));
predp[t + 1] = modadd(predp[t], dp[t]);
if (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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3456kb
input:
1 1
output:
2
result:
wrong answer 1st lines differ - expected: '1', found: '2'