QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#130559 | #1944. Circle of Friends | karuna# | WA | 2ms | 9604kb | C++17 | 1.3kb | 2023-07-24 16:06:04 | 2023-07-24 16:06:07 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 202020;
const ll MOD = 998244353;
int n; ll a[2 * MAXN], s[20][2 * MAXN], dp[2 * MAXN];
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[n + i] = a[i];
}
for (int i = 1; i <= 2 * n; i++) {
s[0][i] = a[i];
}
for (int j = 1; j < 20; j++) {
for (int i = (1 << j); i <= 2 * n; i++)
s[j][i] = s[j - 1][i] & s[j - 1][i - (1 << (j - 1))];
}
ll ans = 0;
for (int r = n + 1; r >= 1; ) {
dp[r - 1] = 1;
for (int i = r; i <= n; i++) dp[i] = 1;
for (int i = n + 1; i <= 2 * n; i++) {
ll x = a[i];
int p = i;
for (int j = 19; j >= 0; j--) {
if ((x & s[j][p]) != 0) {
x = x & s[j][p];
p = p - (1 << j);
}
dp[i] = (dp[i - 1] + dp[i - 1]) % MOD;
if (p != 0)
dp[i] = (dp[i] + MOD - dp[p - 1]) % MOD;
}
}
int l = r;
while (l >= 1 && (a[l] & a[r]) == a[r]) --l;
ans = (ans + dp[n + r - 1] - dp[n + l - 1] + MOD) % MOD;
r = l;
}
cout << ans << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 9604kb
input:
1 1
output:
2
result:
wrong answer 1st lines differ - expected: '1', found: '2'