QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#130563 | #1944. Circle of Friends | karuna# | TL | 36ms | 70740kb | C++17 | 1.4kb | 2023-07-24 16:12:49 | 2023-07-24 16:12:56 |
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;
}
ll x = a[1];
for (int i = 2; i <= n; i++) x &= a[i];
if (x != 0) ans = (ans + MOD - n) % MOD;
cout << ans << '\n';
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 9576kb
input:
1 1
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 2ms
memory: 9628kb
input:
1 1152921504606846975
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 25ms
memory: 70560kb
input:
200000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
792053081
result:
ok single line: '792053081'
Test #4:
score: 0
Accepted
time: 36ms
memory: 70740kb
input:
200000 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606...
output:
792053081
result:
ok single line: '792053081'
Test #5:
score: -100
Time Limit Exceeded
input:
200000 18031990763159554 108095195748368386 36029346783428610 184085739649376272 577639437895209218 72057594042191904 4508276314083330 9078671805521920 144255925580990466 432490704060547904 72059793094738017 562967269607456 26424786302976 68719476738 333275855713337352 11370333479109156 290271086772...