QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#378311 | #1944. Circle of Friends | ohiostatescarlet | AC ✓ | 3151ms | 57548kb | C++17 | 1.7kb | 2024-04-06 11:07:07 | 2024-04-06 11:07:09 |
Judging History
answer
#include"bits/stdc++.h"
using namespace std;
#define L long long
L MOD = 998244353;
void calcDP(vector<L>&nums, vector<L>&dp) {
L n = nums.size();
vector<vector<L>> andR(n);
for (L i = 0; i < n; i++) {
andR[i].push_back(nums[i]);
L j = 0;
L p = 1;
while (i-2*p+1 >= 0) {
andR[i].push_back(andR[i][j] & andR[i-p][j]);
j++;
p <<= 1;
}
}
dp.assign(n, 0);
dp[0] = 1;
vector<L> dpp(n+2, 0);
dp[0] = dpp[1] = 1;
dpp[2] = 2;
for (L i = 1; i < n; i++) {
L curr = nums[i];
L p = i;
L j = andR[p-1].size()-1;
while (j >= 0 && p > 0) {
if (curr & andR[p-1][j]) {
curr &= andR[p-1][j];
p -= (1 << j);
j = min(j, (L)andR[p-1].size());
}
j--;
}
// cout << i << " -> " << p << "\n";
dp[i] = (dpp[i+1] - dpp[p] + MOD) % MOD;
dpp[i+2] = (dp[i] + dpp[i+1]) % MOD;
}
// for (L v : dp) {
// cout << v << " ";
// }
// cout << '\n';
}
// g++ -std=c++17 -O2 -DLOCAL -o a a.cpp
int main() {
L n;
cin >> n;
vector<L> nums(n,0);
L all = -1;
for (L i = 0; i < n; i++) {
cin >> nums[i];
all &= nums[i];
}
vector<L> dp;
calcDP(nums, dp);
L res = dp[n-1];
if (all) {
cout << ((2 * res) % MOD - n + MOD) % MOD << '\n';
return 0;
}
while (nums.size()>2&&nums[0]) {
// cout << res << '\n';
while (nums.size()>2 && (nums.back()&nums[0])==nums[0]) {
nums.pop_back(); n--;
res = (res + dp[n-1]) % MOD;
}
nums[0] = nums[0]&nums.back();
nums.pop_back(); n--;
if (nums[0]) {
calcDP(nums, dp);
res = (res + dp[n-1]) % MOD;
}
}
cout << res << "\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3796kb
input:
1 1
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3508kb
input:
1 1152921504606846975
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 70ms
memory: 57408kb
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: 138ms
memory: 57492kb
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: 160ms
memory: 57512kb
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: 207ms
memory: 57412kb
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: 316ms
memory: 57432kb
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: 478ms
memory: 57480kb
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: 1095ms
memory: 57496kb
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: 2219ms
memory: 57440kb
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: 3151ms
memory: 57448kb
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: 2980ms
memory: 57548kb
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: 1363ms
memory: 57408kb
input:
200000 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606...
output:
413438309
result:
ok single line: '413438309'