QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#849500#9878. A xor B plus CWuyanruRE 1ms4116kbC++142.5kb2025-01-09 15:51:252025-01-09 15:51:31

Judging History

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

  • [2025-01-09 15:51:31]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:4116kb
  • [2025-01-09 15:51:25]
  • 提交

answer

#include<bits/stdc++.h>
#define inf 0x3f3f3f3f3f3f3f3fll
#define debug(x) cerr<<#x<<"="<<x<<endl
using namespace std;
using ll=long long;
using ld=long double;
using pli=pair<ll,int>;
using pi=pair<int,int>;
template<typename A>
using vc=vector<A>;
template<typename A,const int N>
using aya=array<A,N>;
inline int read()
{
    int s=0,w=1;char ch;
    while((ch=getchar())>'9'||ch<'0') if(ch=='-') w=-1;
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    return s*w;
}
inline ll lread()
{
    ll s=0,w=1;char ch;
    while((ch=getchar())>'9'||ch<'0') if(ch=='-') w=-1;
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    return s*w;
}
const int mod=998244353;
ll X[2000005];
int S[3];
int A,B,C;ll n;
inline ll wtf(ll n,ll d)
{
    return (n-3)%d+3;
}
int main()
{
    A=read(),B=read(),C=read(),n=lread();
    if(n<=2){ printf("%d\n",n==1?A:B);return 0;}
    ll ans=0,now;int M=0;
    while(max(max(A,B),C)>=(1<<M)) M++;

    //先维护 <M 的序列
    X[1]=A,X[2]=B;vc<ll>Y;
    for(int i=3;i<3+3*(1<<(M-1));i++)
    {
        X[i]=(X[i-1]^X[i-2])+C;
        if(X[i]>=(1<<M)) X[i]-=1<<M,Y.push_back(i);
    }
    ll len=3*(1<<(M-1));
    ans=X[wtf(n,len)];now=1<<(M-1);
    // printf("M=%d len=%lld ans=%lld\n",M,len,ans);
    // printf("wtf %lld %lld : %lld\n",n,len,wtf(n,len));
    // debug(X[4]);
    // for(ll i:Y) printf("%lld ",i);;putchar('\n');
    while(Y.size())
    {
        if(len<n)//推出这一位的所有 Y
        {
            vc<ll>lst;
            for(ll i:Y) lst.push_back(i);
            for(ll i:Y) lst.push_back(i+len);
            Y.clear();

            S[0]=S[1]=S[2]=0;
            ll xw=wtf(n,2*len);int xn=0;
            for(ll i:lst)
            {
                if(S[i%3]^S[(i-1)%3]) Y.push_back(i);
                if(i<=xw&&(xw-i)%3!=2) xn^=1;
                S[i%3]^=1;
            }
            len<<=1,now=(now*2)%mod;
            if(xn) ans=(ans+now)%mod;
        }
        else
        {
            vc<ll>lst;
            for(ll i:Y) lst.push_back(i);
            Y.clear();

            S[0]=S[1]=S[2]=0;
            ll xw=n;int xn=0;
            for(ll i:lst)
            {
                if(S[i%3]^S[(i-1)%3]) Y.push_back(i);
                if(i<=xw&&(xw-i)%3!=2) xn^=1;
                S[i%3]^=1;
            }
            now=(now*2)%mod;
            if(xn) ans=(ans+now)%mod;
        }
        // printf("%d : %d\n",M++,(int)Y.size());
    }

    printf("%lld\n",ans);
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3744kb

input:

1 2 3 4

output:

7

result:

ok "7"

Test #2:

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

input:

123 456 789 123456789

output:

567982455

result:

ok "567982455"

Test #3:

score: -100
Runtime Error

input:

0 0 0 1000000000000000000

output:


result: