結果

問題 No.2265 Xor Range Substring Sum Query
ユーザー nononnonon
提出日時 2024-04-08 17:56:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 831 ms / 5,000 ms
コード長 2,172 bytes
コンパイル時間 2,628 ms
コンパイル使用メモリ 215,568 KB
実行使用メモリ 48,724 KB
最終ジャッジ日時 2024-04-08 17:56:59
合計ジャッジ時間 18,585 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,676 KB
testcase_01 AC 5 ms
6,676 KB
testcase_02 AC 5 ms
6,676 KB
testcase_03 AC 5 ms
6,676 KB
testcase_04 AC 588 ms
48,724 KB
testcase_05 AC 590 ms
48,724 KB
testcase_06 AC 567 ms
48,724 KB
testcase_07 AC 604 ms
48,724 KB
testcase_08 AC 590 ms
48,724 KB
testcase_09 AC 783 ms
48,724 KB
testcase_10 AC 788 ms
48,724 KB
testcase_11 AC 831 ms
48,724 KB
testcase_12 AC 779 ms
48,724 KB
testcase_13 AC 770 ms
48,724 KB
testcase_14 AC 678 ms
48,724 KB
testcase_15 AC 669 ms
48,724 KB
testcase_16 AC 705 ms
48,724 KB
testcase_17 AC 664 ms
48,724 KB
testcase_18 AC 370 ms
48,724 KB
testcase_19 AC 364 ms
48,724 KB
testcase_20 AC 765 ms
48,724 KB
testcase_21 AC 803 ms
48,724 KB
testcase_22 AC 452 ms
26,112 KB
testcase_23 AC 424 ms
26,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/modint>
using namespace std;
using mint=atcoder::modint998244353;
template<typename S, auto op, auto e>
struct xor_segtree
{
    xor_segtree(const vector<S>&v):n((int)v.size())
    {
        log=0;
        while((1<<log)<n)log++;
        mid=(log+1)/2;
        sz=1<<log;
        node.assign(log+1,vector<S>(sz,e()));
        for(int i=0;i<n;i++)node[0][i]=v[i];
        for(int i=0;i<log;i++)for(int j=0;j<n;j++)update(i,j);
    }
    void set(int p, S x)
    {
        assert(0<=p&&p<n);
        node[0][p]=x;
        for(int i=0;i<mid;i++)for(int j=0;j<(1<<(i+1));j++)update(i,p^j);
    }
    S get(int p)
    {
        assert(0<=p&&p<n);
        return node[0][p];
    }
    S prod(int l, int r, int x)
    {
        assert(0<=l&&l<=r&&r<=n);
        assert(0<=x&&x<sz);
        S pl=e(),pr=e();
        int d=0;
        while(l<r&&d<mid)
        {
            if(l&1)pl=op(pl,node[d][((l++)<<d)^x]);
            if(r&1)pr=op(node[d][((--r)<<d)^x],pr);
            l>>=1,r>>=1,d++;
        }
        while(l<r)pl=op(pl,node[mid][((l++)<<mid)^x]);
        return op(pl,pr);
    }
private:
    int n,log,mid,sz;
    vector<vector<S>>node;
    void update(int i, int j){node[i+1][j]=op(node[i][j],node[i][j^(1<<i)]);}
};
mint p2[1<<18],p11[1<<18];
pair<mint,int>op(pair<mint,int>a, pair<mint,int>b)
{
    auto[xa,sa]=a;
    auto[xb,sb]=b;
    return make_pair(xa*p11[sb]+xb*p2[sa],sa+sb);
}
pair<mint,int>e(){return make_pair(0,0);}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    string S;
    cin>>N>>S;
    N=1<<N;
    p2[0]=p11[0]=1;
    for(int i=1;i<N;i++)
    {
        p2[i]=2*p2[i-1];
        p11[i]=11*p11[i-1];
    }
    vector<pair<mint,int>>A(N);
    for(int i=0;i<N;i++)A[i]=make_pair(S[i]-'0',1);
    xor_segtree<pair<mint,int>,op,e>seg(A);
    int Q;
    cin>>Q;
    while(Q--)
    {
        int t;
        cin>>t;
        if(t==1)
        {
            int p,x;
            cin>>p>>x;
            seg.set(p,make_pair(x,1));
        }
        else
        {
            int l,r,x;
            cin>>l>>r>>x;
            cout<<seg.prod(l,r+1,x).first.val()<<'\n';
        }
    }
}
0