QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#190375 | #1944. Circle of Friends | SolitaryDream# | AC ✓ | 188ms | 37080kb | C++20 | 1.5kb | 2023-09-28 19:34:43 | 2023-09-29 03:29:49 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+1e3+7,P=998244353;
int n,a[N];
int f[N],s[N];
int st[21][N];
int qry(int l,int r)
{
int k=__lg(r-l+1);
return st[k][l]&st[k][r-(1<<k)+1];
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n;
vector<int> v;
for(int i=1;i<=n;i++)
{
cin>>a[i];
if(!v.size())
v.push_back(a[i]);
else
{
if((v.back()&a[i])!=v.back())
v.push_back(v.back()&a[i]);
}
}
for(int i=1;i<=n;i++)
st[0][i]=a[i];
for(int j=1;j<=20;j++)
for(int i=1;i+(1<<j)-1<=n;i++)
st[j][i]=(st[j-1][i]&st[j-1][i+(1<<(j-1))]);
int ans=0;
//start from 0
for(int i=1,j=1;i<=n;i++)
{
while(qry(j,i)==0)
j++;
f[i]=(s[i-1]-(j<2?0:s[j-2])+P)%P;
if(qry(1,i)!=0)
f[i]=(f[i]+1)%P;
s[i]=(s[i-1]+f[i])%P;
}
ans=(ans+f[n])%P;
for(auto val:v)
{
if(val==0)
continue;
for(int i=1,j=1;i<=n;i++)
{
f[i]=0;
while(qry(j,i)==0)
j++;
f[i]=(s[i-1]-(j<2?0:s[j-2])+P)%P;
if(qry(1,i)==val)
f[i]=(f[i]+1)%P;
s[i]=(s[i-1]+f[i])%P;
if(i!=n&&((qry(i+1,n)&val)!=0))
ans=(ans+f[i])%P;
}
}
if(v.back()!=0)
ans=(ans-n+1+P)%P;
printf("%lld\n",ans);
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5812kb
input:
1 1
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 1ms
memory: 5696kb
input:
1 1152921504606846975
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 11ms
memory: 36340kb
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: 31ms
memory: 36152kb
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: 33ms
memory: 36228kb
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: 40ms
memory: 36540kb
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: 46ms
memory: 36628kb
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: 73ms
memory: 36332kb
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: 87ms
memory: 36488kb
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: 158ms
memory: 37064kb
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: 188ms
memory: 36516kb
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: 175ms
memory: 36408kb
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: 129ms
memory: 37080kb
input:
200000 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606...
output:
413438309
result:
ok single line: '413438309'