QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#784231#1085. Brave Seekers of Unicornsydzr00000AC ✓66ms23144kbC++17715b2024-11-26 14:12:582024-11-26 14:12:59

Judging History

你现在查看的是最新测评结果

  • [2024-11-26 14:12:59]
  • 评测
  • 测评结果:AC
  • 用时:66ms
  • 内存:23144kb
  • [2024-11-26 14:12:58]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
inline int Add(const int &x,const int &y){return x+y>=mod?x+y-mod:x+y;}
inline int Minus(const int &x,const int &y){return x-y<0?x-y+mod:x-y;} 
long long f[1000001],sum[1000001];
int pw[21],hb[1000001];
int main(){
    pw[0]=1;
    for(int i=1;i<=20;i++)
        pw[i]=pw[i-1]*2;

    int n;
    cin>>n;
    hb[0]=-1;
    for(int i=1;i<=n;i++)
    {
        f[i]=Add(sum[i-1],1);
        hb[i]=hb[i>>1]+1;
        for(int k=0;k<hb[i];k++)
            if((i>>k)&1)
                f[i]=Minus(f[i],Minus(sum[pw[k+1]-1],sum[pw[k]-1]));
        sum[i]=Add(sum[i-1],f[i]);
    }
    cout<<sum[n]<<endl;
    
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 7704kb

input:

1

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 1ms
memory: 7716kb

input:

2

output:

3

result:

ok 1 number(s): "3"

Test #3:

score: 0
Accepted
time: 1ms
memory: 7592kb

input:

3

output:

6

result:

ok 1 number(s): "6"

Test #4:

score: 0
Accepted
time: 1ms
memory: 7588kb

input:

5

output:

26

result:

ok 1 number(s): "26"

Test #5:

score: 0
Accepted
time: 1ms
memory: 7688kb

input:

322

output:

782852421

result:

ok 1 number(s): "782852421"

Test #6:

score: 0
Accepted
time: 1ms
memory: 7784kb

input:

10

output:

728

result:

ok 1 number(s): "728"

Test #7:

score: 0
Accepted
time: 0ms
memory: 7704kb

input:

100

output:

234222727

result:

ok 1 number(s): "234222727"

Test #8:

score: 0
Accepted
time: 2ms
memory: 9784kb

input:

10000

output:

348787098

result:

ok 1 number(s): "348787098"

Test #9:

score: 0
Accepted
time: 66ms
memory: 23124kb

input:

1000000

output:

246427510

result:

ok 1 number(s): "246427510"

Test #10:

score: 0
Accepted
time: 66ms
memory: 23144kb

input:

999999

output:

525546416

result:

ok 1 number(s): "525546416"

Test #11:

score: 0
Accepted
time: 63ms
memory: 22728kb

input:

950000

output:

154241852

result:

ok 1 number(s): "154241852"

Test #12:

score: 0
Accepted
time: 57ms
memory: 23124kb

input:

999888

output:

254589934

result:

ok 1 number(s): "254589934"

Test #13:

score: 0
Accepted
time: 58ms
memory: 23116kb

input:

999423

output:

917909701

result:

ok 1 number(s): "917909701"

Test #14:

score: 0
Accepted
time: 32ms
memory: 19148kb

input:

600000

output:

546076071

result:

ok 1 number(s): "546076071"

Test #15:

score: 0
Accepted
time: 1ms
memory: 7592kb

input:

1337

output:

616951443

result:

ok 1 number(s): "616951443"