結果

問題 No.2498 OX Operations
ユーザー 沙耶花沙耶花
提出日時 2023-10-06 23:55:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3,397 ms / 4,000 ms
コード長 6,408 bytes
コンパイル時間 4,576 ms
コンパイル使用メモリ 274,632 KB
実行使用メモリ 7,680 KB
最終ジャッジ日時 2024-07-26 17:25:38
合計ジャッジ時間 36,937 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 3 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 6 ms
6,944 KB
testcase_12 AC 16 ms
6,940 KB
testcase_13 AC 11 ms
6,944 KB
testcase_14 AC 18 ms
6,944 KB
testcase_15 AC 2,016 ms
7,296 KB
testcase_16 AC 3,141 ms
7,424 KB
testcase_17 AC 1,404 ms
7,424 KB
testcase_18 AC 2,487 ms
7,680 KB
testcase_19 AC 1,759 ms
7,680 KB
testcase_20 AC 2,696 ms
7,680 KB
testcase_21 AC 3,358 ms
7,680 KB
testcase_22 AC 2,067 ms
6,940 KB
testcase_23 AC 1,959 ms
6,940 KB
testcase_24 AC 3,370 ms
7,552 KB
testcase_25 AC 3,397 ms
7,680 KB
testcase_26 AC 3,357 ms
7,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 1000000000000000001

template <class S,
          S (*op)(S, S),
          S (*e)(),
          class F,
          S (*mapping)(F, S),
          F (*composition)(F, F),
          F (*id)()>
struct dual_segtree {
  public:
    dual_segtree() : dual_segtree(0) {}
    explicit dual_segtree(int n) : dual_segtree(std::vector<S>(n, e())) {}
    explicit dual_segtree(const std::vector<S>& v) : _n(int(v.size())) {
        log = 0;
		while((1LL<<log) < _n){
			log++;
		}
        size = 1 << log;
        d = std::vector<S>(2 * size, e());
        lz = std::vector<F>(size, id());
        for (int i = 0; i < _n; i++) d[size + i] = v[i];

    }

    void set(int p, S x) {
        assert(0 <= p && p < _n);
        p += size;
        for (int i = log; i >= 1; i--) push(p >> i);
        d[p] = x;
    }

    S get(int p) {
        assert(0 <= p && p < _n);
        p += size;
        for (int i = log; i >= 1; i--) push(p >> i);
        return d[p];
    }

    S prod(int l, int r) {
        assert(0 <= l && l <= r && r <= _n);
        if (l == r) return e();

        l += size;
        r += size;

        for (int i = log; i >= 1; i--) {
            if (((l >> i) << i) != l) push(l >> i);
            if (((r >> i) << i) != r) push((r - 1) >> i);
        }

        S sml = e(), smr = e();
        while (l < r) {
            if (l & 1) sml = op(sml, d[l++]);
            if (r & 1) smr = op(d[--r], smr);
            l >>= 1;
            r >>= 1;
        }

        return op(sml, smr);
    }

    S all_prod() { return d[1]; }

    void apply(int p, F f) {
        assert(0 <= p && p < _n);
        p += size;
        for (int i = log; i >= 1; i--) push(p >> i);
        d[p] = mapping(f, d[p]);
    }
    void apply(int l, int r, F f) {
        assert(0 <= l && l <= r && r <= _n);
        if (l == r) return;

        l += size;
        r += size;

        for (int i = log; i >= 1; i--) {
            if (((l >> i) << i) != l) push(l >> i);
            if (((r >> i) << i) != r) push((r - 1) >> i);
        }

        {
            int l2 = l, r2 = r;
            while (l < r) {
                if (l & 1) all_apply(l++, f);
                if (r & 1) all_apply(--r, f);
                l >>= 1;
                r >>= 1;
            }
            l = l2;
            r = r2;
        }
    }

    template <bool (*g)(S)> int max_right(int l) {
        return max_right(l, [](S x) { return g(x); });
    }
    template <class G> int max_right(int l, G g) {
        assert(0 <= l && l <= _n);
        assert(g(e()));
        if (l == _n) return _n;
        l += size;
        for (int i = log; i >= 1; i--) push(l >> i);
        S sm = e();
        do {
            while (l % 2 == 0) l >>= 1;
            if (!g(op(sm, d[l]))) {
                while (l < size) {
                    push(l);
                    l = (2 * l);
                    if (g(op(sm, d[l]))) {
                        sm = op(sm, d[l]);
                        l++;
                    }
                }
                return l - size;
            }
            sm = op(sm, d[l]);
            l++;
        } while ((l & -l) != l);
        return _n;
    }

    template <bool (*g)(S)> int min_left(int r) {
        return min_left(r, [](S x) { return g(x); });
    }
    template <class G> int min_left(int r, G g) {
        assert(0 <= r && r <= _n);
        assert(g(e()));
        if (r == 0) return 0;
        r += size;
        for (int i = log; i >= 1; i--) push((r - 1) >> i);
        S sm = e();
        do {
            r--;
            while (r > 1 && (r % 2)) r >>= 1;
            if (!g(op(d[r], sm))) {
                while (r < size) {
                    push(r);
                    r = (2 * r + 1);
                    if (g(op(d[r], sm))) {
                        sm = op(d[r], sm);
                        r--;
                    }
                }
                return r + 1 - size;
            }
            sm = op(d[r], sm);
        } while ((r & -r) != r);
        return 0;
    }

  private:
    int _n, size, log;
    std::vector<S> d;
    std::vector<F> lz;

    void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
    void all_apply(int k, F f) {
        d[k] = mapping(f, d[k]);
        if (k < size) lz[k] = composition(f, lz[k]);
    }
    void push(int k) {
        all_apply(2 * k, lz[k]);
        all_apply(2 * k + 1, lz[k]);
        lz[k] = id();
    }
};

using A = array<int,2>;

A op(A a,A b){
	return a;
}

A e(){
	A ret;
	ret[0] = 0,ret[1] = (1<<30)-1;
	return ret;
}

A mapping(A a,A b){
	A ret;
	ret[0] = 0,ret[1] = 0;
	rep(i,30){
		rep(j,2){
			ret[j] |= ((a[(b[j]>>i)&1]>>i)&1)<<i;
		}
	}
	return ret;
}

A composition(A a,A b){
	A ret;
	ret[0] = 0,ret[1] = 0;
	rep(i,30){
		rep(j,2){
			ret[j] |= ((a[(b[j]>>i)&1]>>i)&1)<<i;
		}
	}
	return ret;
}

A id(){
	A ret;
	ret[0] = 0,ret[1] = (1<<30)-1;
	return ret;
}

int main(){
	
	int N,Q;
	cin>>N>>Q;
	
	vector<int> m(N);
	rep(i,N)scanf("%d",&m[i]);
	dual_segtree<A,op,e,A,mapping,composition,id> seg(N);
	rep(i,Q){
		char c;
		cin>>c;
		int l,r,x;
		scanf("%d %d %d",&l,&r,&x);
		l--;

		A t;
		t[0] = 0,t[1] = 0;
		
		rep(j,30){
			//cout<<j<<endl;
			if(c=='o'){
				if((x>>j)&1)t[0] |= 1<<j,t[1] |= 1<<j;
				else t[1] |= 1<<j;
			}
			else{
				if((x>>j)&1)t[0] |= 1<<j;
				else t[1] |= 1<<j;
			}
		}
		
		seg.apply(l,r,t);
	}
//	cout<<'h'<<endl;
	vector<mint> dp(31,0);
	dp[0] = 1;
	rep(i,N){
		auto ret = seg.get(i);
		vector tdp(2,vector<mint>(31,0));
		int M = m[i];
		tdp[0][0] = 1;
		int C = 1;
		{
			vector ndp(2,vector<mint>(31,0));
			for(int j=29;j>=0;j--){
				ndp.assign(2,vector<mint>(31,0));
				rep(l,2){
					rep(k,C){
						if(tdp[l][k]==0)continue;
						rep(n,2){
							int kk = k,ll = l;
							if(l==0){
								if((M>>j)&1){
									if(n==0)ll++;
								}
								else{
									if(n==1)continue;
								}
							}
							if((ret[n]>>j)&1)kk++;
							ndp[ll][kk] += tdp[l][k];
						}
					}
				}
				C++;
				swap(tdp,ndp);
			}
		}
		vector<mint> ndp(31,0);
		rep(j,31){
			rep(k,31){
				ndp[max(j,k)] += dp[j] * (tdp[0][k] + tdp[1][k]);
			}
		}
		swap(dp,ndp);
	}
	mint ans = 0;
	rep(i,dp.size())ans += dp[i] * i;
	cout<<ans.val()<<endl;
	
	return 0;
}
0