結果

問題 No.2265 Xor Range Substring Sum Query
ユーザー 👑 NachiaNachia
提出日時 2023-04-07 22:07:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,048 ms / 5,000 ms
コード長 2,672 bytes
コンパイル時間 1,068 ms
コンパイル使用メモリ 88,604 KB
実行使用メモリ 7,768 KB
最終ジャッジ日時 2024-04-10 17:10:31
合計ジャッジ時間 12,096 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 368 ms
7,644 KB
testcase_05 AC 369 ms
7,764 KB
testcase_06 AC 374 ms
7,764 KB
testcase_07 AC 377 ms
7,640 KB
testcase_08 AC 364 ms
7,640 KB
testcase_09 AC 627 ms
7,640 KB
testcase_10 AC 625 ms
7,640 KB
testcase_11 AC 619 ms
7,636 KB
testcase_12 AC 629 ms
7,640 KB
testcase_13 AC 633 ms
7,768 KB
testcase_14 AC 235 ms
7,640 KB
testcase_15 AC 233 ms
7,640 KB
testcase_16 AC 240 ms
7,768 KB
testcase_17 AC 237 ms
7,640 KB
testcase_18 AC 475 ms
7,764 KB
testcase_19 AC 472 ms
7,768 KB
testcase_20 AC 1,023 ms
7,512 KB
testcase_21 AC 1,048 ms
7,644 KB
testcase_22 AC 280 ms
5,632 KB
testcase_23 AC 282 ms
5,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <atcoder/modint>
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
const i64 INF = 1001001001001001001;

using Modint = atcoder::static_modint<998244353>;


int main(){
    int N;
    string S;
    cin >> N >> S;

    vector<int> Sval(1<<N);
    rep(i,1<<N) Sval[i] = S[i] - '0';
    int n = N/2;

    vector<Modint> pow10((1<<N)+1);
    pow10[0] = 1; rep(i,1<<N) pow10[i+1] = pow10[i] * 11;
    vector<Modint> pow2((1<<N)+1);
    pow2[0] = 1; rep(i,1<<N) pow2[i+1] = pow2[i] * 2;

    const int SZ = 1 << (N-n);
    const int MASK = SZ - 1;

    vector<vector<Modint>> micro(1<<n, vector<Modint>(SZ));
    rep(i,1<<n){
        rep(j,SZ) micro[i][j] = Sval[(i<<(N-n))+j];
        rep(d,N-n) rep(j,SZ) if(!(j&(1<<d))){
            auto& a = micro[i][j];
            auto& b = micro[i][j|(1<<d)];
            Modint ab = a * pow10[1<<d] + b * pow2[1<<d];
            Modint ba = a * pow2[1<<d] + b * pow10[1<<d];
            a = ab;
            b = ba;
        }
    }

    auto naive = [&](int l, int r, int x) -> Modint {
        Modint ans;
        for(int i=l; i<r; i++){
            ans += Modint::raw(Sval[i^x]) * pow2[i-l] * pow10[r-1-i];
        }
        return ans;
    };

    int Q; cin >> Q;
    rep(q,Q){
        int t; cin >> t;
        if(t == 1){
            int x, y; cin >> x >> y;
            y -= Sval[x]; Sval[x] += y;
            Modint dy = y;
            int i = x >> (N-n);
            auto iter = micro[i].begin();
            int xx = x & MASK;
            rep(j,SZ) iter[j] += dy * pow2[xx^j] * pow10[SZ-1-(xx^j)];
        }
        else if(t == 2){
            int l, r, x; cin >> l >> r >> x; r++;
            Modint ans = 0;
            if(r - l <= SZ * 2){
                ans = naive(l, r, x);
            }
            else{
                int lv = (l + (SZ - 1)) >> (N-n);
                int rv = r >> (N-n);
                int lowmask = x & MASK;
                int himask = x >> (N-n);
                ans += naive(l, lv << (N-n), x) * pow10[r - (lv << (N-n))];
                for(int d=lv; d<rv; d++){
                    ans += micro[d^himask][lowmask] * pow2[(d<<(N-n))-l] * pow10[r-((d+1)<<(N-n))];
                }
                ans += naive(rv << (N-n), r, x) * pow2[(rv << (N-n)) - l];
            }
            cout << ans.val() << '\n';
        }
    }
    return 0;
}



struct ios_do_not_sync{
    ios_do_not_sync(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    }
} ios_do_not_sync_instance;

0