QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#19749 | #1085. Brave Seekers of Unicorns | wlzhouzhuan | AC ✓ | 151ms | 11532kb | C++17 | 2.1kb | 2022-02-10 14:13:28 | 2022-05-06 06:58:33 |
Judging History
answer
// Author: wlzhouzhuan
#include<bits/stdc++.h>
using namespace std;
#define rep(i,l,r) for(int i=(l);i<=(r);i++)
#define per(i,l,r) for(int i=(l);i>=(r);i--)
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define mset(s,t) memset(s,t,sizeof(s))
#define mcpy(s,t) memcpy(s,t,sizeof(t))
#define SZ(x) ((int)x.size())
#define pb push_back
#define eb emplace_back
#define fir first
#define sec second
template<class T1,class T2>bool ckmax(T1 &a,T2 b){if(a<b)return a=b,1;else return 0;}
template<class T1,class T2>bool ckmin(T1 &a,T2 b){if(a>b)return a=b,1;else return 0;}
inline int read(){
int x=0,f=0;char ch=getchar();
while(!isdigit(ch))f|=ch=='-',ch=getchar();
while(isdigit(ch))x=10*x+ch-'0',ch=getchar();
return f?-x:x;
}
template<typename T>void print(T x){
if(x<0)putchar('-'),x=-x;
if(x>=10)print(x/10);
putchar(x%10+'0');
}
template<typename T>void print(T x,char ch){
print(x),putchar(ch);
}
const int N=1000005;
const int mod=998244353;
int dp[N],n;
int sum[N],coef;
void dfs(int bit,int pre,int i,int zip){
if(!zip){
// printf("pre=%d,bit=%d,i=%d\n",pre,bit,i);
int L=pre<<bit+1,R=L+(1<<bit+1)-1;
// printf("add range[%d,%d]\n",L,R);
coef=(coef+1ll*sum[R]+mod-sum[L-1])%mod;
return;
}
if(bit==-1)return;
int k1=i>>bit&1;
// 0
{
int nzip=zip;
if(k1&&(nzip&1))nzip^=1;
dfs(bit-1,2*pre,i,nzip);
}
// 1
{
int nzip=zip;
if(!k1){
if(nzip&2)return;
}else{
if(nzip&1)return;
if(nzip&2)nzip^=2;
}
dfs(bit-1,2*pre+1,i,nzip);
}
}
int main(){
cin>>n;
dp[1]=1,sum[1]=1;
rep(i,2,n){
dp[i]=sum[i-1]+1;
// rep(j,1,i-1){
// if(j<(j^i)&&(j^i)<i)
// // dp[i]=(dp[i]-dp[j]+mod)%mod;
// printf("i=%d,j=%d\n",i,j);
// }
coef=0;
dfs(30,0,i,3);
dp[i]=(dp[i]+mod-coef)%mod;
sum[i]=(sum[i-1]+dp[i])%mod;
}
print(sum[n],'\n');
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5632kb
input:
1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 3ms
memory: 5636kb
input:
2
output:
3
result:
ok 1 number(s): "3"
Test #3:
score: 0
Accepted
time: 3ms
memory: 5764kb
input:
3
output:
6
result:
ok 1 number(s): "6"
Test #4:
score: 0
Accepted
time: 3ms
memory: 5712kb
input:
5
output:
26
result:
ok 1 number(s): "26"
Test #5:
score: 0
Accepted
time: 0ms
memory: 5704kb
input:
322
output:
782852421
result:
ok 1 number(s): "782852421"
Test #6:
score: 0
Accepted
time: 1ms
memory: 5696kb
input:
10
output:
728
result:
ok 1 number(s): "728"
Test #7:
score: 0
Accepted
time: 1ms
memory: 5496kb
input:
100
output:
234222727
result:
ok 1 number(s): "234222727"
Test #8:
score: 0
Accepted
time: 2ms
memory: 5752kb
input:
10000
output:
348787098
result:
ok 1 number(s): "348787098"
Test #9:
score: 0
Accepted
time: 151ms
memory: 11532kb
input:
1000000
output:
246427510
result:
ok 1 number(s): "246427510"
Test #10:
score: 0
Accepted
time: 147ms
memory: 11404kb
input:
999999
output:
525546416
result:
ok 1 number(s): "525546416"
Test #11:
score: 0
Accepted
time: 144ms
memory: 11136kb
input:
950000
output:
154241852
result:
ok 1 number(s): "154241852"
Test #12:
score: 0
Accepted
time: 142ms
memory: 11332kb
input:
999888
output:
254589934
result:
ok 1 number(s): "254589934"
Test #13:
score: 0
Accepted
time: 146ms
memory: 11400kb
input:
999423
output:
917909701
result:
ok 1 number(s): "917909701"
Test #14:
score: 0
Accepted
time: 94ms
memory: 10228kb
input:
600000
output:
546076071
result:
ok 1 number(s): "546076071"
Test #15:
score: 0
Accepted
time: 2ms
memory: 5716kb
input:
1337
output:
616951443
result:
ok 1 number(s): "616951443"