QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#785089#1085. Brave Seekers of Unicornswjy2020AC ✓29ms35128kbC++111.2kb2024-11-26 16:49:152024-11-26 16:49:15

Judging History

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

  • [2024-11-26 16:49:15]
  • 评测
  • 测评结果:AC
  • 用时:29ms
  • 内存:35128kb
  • [2024-11-26 16:49:15]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define int long long
using namespace std;
template<typename T>void read(T &x)
{
    T f=1;x=0;char s=getchar();
    while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
    while(s>='0'&&s<='9') {x=x*10+s-'0';s=getchar();}
    x*=f;
}
int High[1000005],mod;
ll f[1000005],g[1000005],Sum[1000005];
int qpow(int a,int b)
{
    int ret=1;
    while(b)
    {
        if(b&1) (ret+=a)%=mod;//Mul(ret,a);
        b>>=1;a=a*a%mod;
    }
    return ret;
}
signed main() {
    int n;read(n);
   mod=998244353;
    for(int i=1;i<=n;i++)
    {
        if(i&(i-1)) High[i]=High[i-1];
        else High[i]=i;
    }//二进制下最大高度 
    ll Tmp=0;
    for(int i=1;i<=n;i++)
    {
        if(!(i&(i-1))) Tmp=0;
        f[i]=(Sum[High[i]-1]+1)*(i-High[i])%mod;//最高位小于High[i]的两个数异或和一定不等于i 
        for(int j=i^High[i];j;j^=High[j])
            f[i]-=(Sum[(High[j]<<1)-1]-Sum[High[j]-1])%mod,(f[i]+=mod)%mod;
        g[i]=(f[i]+1+Sum[High[i]-1]+Tmp)%mod;//结尾为i的方案数 
        Tmp*=2,Tmp+=f[i];
        Tmp%=mod;
        Sum[i]=(Sum[i-1]+g[i])%mod;//前缀和 
    }
    printf("%lld",Sum[n]);
    return 0;
}

詳細信息

Test #1:

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

input:

1

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

input:

2

output:

3

result:

ok 1 number(s): "3"

Test #3:

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

input:

3

output:

6

result:

ok 1 number(s): "6"

Test #4:

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

input:

5

output:

26

result:

ok 1 number(s): "26"

Test #5:

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

input:

322

output:

782852421

result:

ok 1 number(s): "782852421"

Test #6:

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

input:

10

output:

728

result:

ok 1 number(s): "728"

Test #7:

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

input:

100

output:

234222727

result:

ok 1 number(s): "234222727"

Test #8:

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

input:

10000

output:

348787098

result:

ok 1 number(s): "348787098"

Test #9:

score: 0
Accepted
time: 26ms
memory: 35128kb

input:

1000000

output:

246427510

result:

ok 1 number(s): "246427510"

Test #10:

score: 0
Accepted
time: 29ms
memory: 35048kb

input:

999999

output:

525546416

result:

ok 1 number(s): "525546416"

Test #11:

score: 0
Accepted
time: 29ms
memory: 34668kb

input:

950000

output:

154241852

result:

ok 1 number(s): "154241852"

Test #12:

score: 0
Accepted
time: 23ms
memory: 35064kb

input:

999888

output:

254589934

result:

ok 1 number(s): "254589934"

Test #13:

score: 0
Accepted
time: 27ms
memory: 34980kb

input:

999423

output:

917909701

result:

ok 1 number(s): "917909701"

Test #14:

score: 0
Accepted
time: 18ms
memory: 28748kb

input:

600000

output:

546076071

result:

ok 1 number(s): "546076071"

Test #15:

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

input:

1337

output:

616951443

result:

ok 1 number(s): "616951443"