QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#130564 | #1944. Circle of Friends | karuna# | AC ✓ | 767ms | 72872kb | C++17 | 1.5kb | 2023-07-24 16:14:42 | 2023-07-24 16:14:44 |
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;
ll x = a[1];
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] & x) == x) --l;
ans = (ans + dp[n + r - 1] - dp[n + l - 1] + MOD) % MOD;
r = l;
x &= a[l];
if (x == 0) break;
}
ll y = a[1];
for (int i = 2; i <= n; i++) y &= a[i];
if (y != 0) ans = (ans + MOD - n) % MOD;
cout << ans << '\n';
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 9784kb
input:
1 1
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 2ms
memory: 9524kb
input:
1 1152921504606846975
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 18ms
memory: 71740kb
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: 72164kb
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: 0
Accepted
time: 38ms
memory: 69236kb
input:
200000 18031990763159554 108095195748368386 36029346783428610 184085739649376272 577639437895209218 72057594042191904 4508276314083330 9078671805521920 144255925580990466 432490704060547904 72059793094738017 562967269607456 26424786302976 68719476738 333275855713337352 11370333479109156 290271086772...
output:
697849429
result:
ok single line: '697849429'
Test #6:
score: 0
Accepted
time: 48ms
memory: 71604kb
input:
200000 38878877261704467 606583538776039621 325557318447172624 513696235393139082 288309595180245073 22000404187620950 28465258695911754 432534927738538528 217932069505099992 8444275091048961 378456596858036610 909745820721741897 10707049231951490 869769773255361289 1054197601224687632 2974146034978...
output:
472024961
result:
ok single line: '472024961'
Test #7:
score: 0
Accepted
time: 63ms
memory: 70548kb
input:
200000 231835759121035702 510237390901680560 1089228954142887951 546561500990948259 452812301317437416 674492659073810407 610376405449845423 336095507987037999 1104321677521773827 257064906190991194 551711390461204674 320506912224540602 57990152440076744 845010071877357771 403229887439671683 2693178...
output:
117345155
result:
ok single line: '117345155'
Test #8:
score: 0
Accepted
time: 97ms
memory: 70800kb
input:
200000 1041523633558056719 1133745259996491747 395753651864850428 1151926721450571413 1114422491360386046 1152921229520204786 1116662492370558395 1006273041715269578 86101463265049534 359143197109542363 242065648916576479 903956062749589338 1091893347132366767 670735077154993663 1142330444352434159 ...
output:
648136624
result:
ok single line: '648136624'
Test #9:
score: 0
Accepted
time: 206ms
memory: 69348kb
input:
200000 1148136361283288575 864128178497519103 504403123704430591 1080722898202656703 1150660907089100671 1148417885111055871 1133781167519004367 1152921229712162815 1152902245931548635 1152846703454314239 1152358485925492735 1134766329820016511 1080863910560530363 1071715973758713727 468354552857362...
output:
21378100
result:
ok single line: '21378100'
Test #10:
score: 0
Accepted
time: 424ms
memory: 71724kb
input:
200000 576460752303419383 1150669704793159679 1152921504606846847 1152921504598458367 1143914030474199039 1152921504606846975 1152921504606846967 1152921504590069759 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152640029630136319 11529215046068...
output:
557285638
result:
ok single line: '557285638'
Test #11:
score: 0
Accepted
time: 707ms
memory: 71504kb
input:
200000 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606...
output:
438039103
result:
ok single line: '438039103'
Test #12:
score: 0
Accepted
time: 767ms
memory: 71840kb
input:
200000 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606...
output:
440098984
result:
ok single line: '440098984'
Test #13:
score: 0
Accepted
time: 764ms
memory: 72872kb
input:
200000 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606...
output:
413438309
result:
ok single line: '413438309'