結果

問題 No.2265 Xor Range Substring Sum Query
ユーザー nononnonon
提出日時 2024-04-08 18:20:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,080 ms / 5,000 ms
コード長 2,304 bytes
コンパイル時間 2,692 ms
コンパイル使用メモリ 212,172 KB
実行使用メモリ 46,716 KB
最終ジャッジ日時 2024-04-08 18:20:26
合計ジャッジ時間 20,562 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,676 KB
testcase_01 AC 4 ms
6,676 KB
testcase_02 AC 4 ms
6,676 KB
testcase_03 AC 4 ms
6,676 KB
testcase_04 AC 774 ms
46,716 KB
testcase_05 AC 783 ms
46,716 KB
testcase_06 AC 743 ms
46,716 KB
testcase_07 AC 748 ms
46,716 KB
testcase_08 AC 745 ms
46,716 KB
testcase_09 AC 983 ms
46,716 KB
testcase_10 AC 1,035 ms
46,716 KB
testcase_11 AC 1,033 ms
46,716 KB
testcase_12 AC 1,080 ms
46,716 KB
testcase_13 AC 1,024 ms
46,716 KB
testcase_14 AC 717 ms
46,716 KB
testcase_15 AC 753 ms
46,716 KB
testcase_16 AC 761 ms
46,716 KB
testcase_17 AC 767 ms
46,716 KB
testcase_18 AC 499 ms
46,716 KB
testcase_19 AC 442 ms
46,716 KB
testcase_20 AC 901 ms
46,716 KB
testcase_21 AC 891 ms
46,716 KB
testcase_22 AC 512 ms
25,084 KB
testcase_23 AC 482 ms
25,084 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():xor_segtree(0){}
    xor_segtree(int n_):xor_segtree(vector<S>(n_,e())){}
    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)*sz,e());
        for(int i=0;i<n;i++)node[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[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[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[idx(d,((l++)<<d)^x)]);
            if(r&1)pr=op(node[idx(d,((--r)<<d)^x)],pr);
            l>>=1,r>>=1,d++;
        }
        while(l<r)pl=op(pl,node[idx(mid,((l++)<<mid)^x)]);
        return op(pl,pr);
    }
private:
    int n,log,mid,sz;
    vector<S>node;
    int idx(int p, int q){return p*sz+q;}
    void update(int p, int q){node[idx(p+1,q)]=op(node[idx(p,q)],node[idx(p,q^(1<<p))]);}
};
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