結果

問題 No.2498 OX Operations
ユーザー 沙耶花沙耶花
提出日時 2023-10-06 23:17:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,931 bytes
コンパイル時間 5,010 ms
コンパイル使用メモリ 272,428 KB
実行使用メモリ 36,884 KB
最終ジャッジ日時 2023-10-06 23:17:45
合計ジャッジ時間 15,307 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 8 ms
4,380 KB
testcase_12 AC 27 ms
4,380 KB
testcase_13 AC 16 ms
4,380 KB
testcase_14 AC 29 ms
4,376 KB
testcase_15 AC 3,871 ms
31,240 KB
testcase_16 TLE -
testcase_17 AC 3,290 ms
31,252 KB
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

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

using A = array<array<bool,30>,2>;

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

A e(){
	A ret;
	rep(i,30){
		rep(j,2){
			ret[j][i] = j;
		}
	}
	return ret;
}

A mapping(A a,A b){
	rep(i,30){
		rep(j,2){
			b[j][i] = a[b[j][i]][i];
		}
	}
	return b;
}

A composition(A a,A b){
	rep(i,30){
		rep(j,2){
			b[j][i] = a[b[j][i]][i];
		}
	}
	return b;
}

A id(){
	A ret;
	rep(i,30){
		rep(j,2){
			ret[j][i] = j;
		}
	}
	return ret;
}

int main(){
	
	int N,Q;
	cin>>N>>Q;
	
	vector<int> m(N);
	rep(i,N)cin>>m[i];
	lazy_segtree<A,op,e,A,mapping,composition,id> seg(N);
	rep(i,Q){
		char c;
		cin>>c;
		int l,r,x;
		cin>>l>>r>>x;
		l--;
		//cout<<l<<endl;
		A t = e();
		//cout<<r<<endl;
		rep(j,30){
			//cout<<j<<endl;
			if(c=='o'){
				if((x>>j)&1)t[0][j] = 1,t[1][j] = 1;
				else t[0][j] = 0,t[1][j] = 1;
			}
			else{
				if((x>>j)&1)t[0][j] = 1,t[1][j] = 0;
				else t[0][j] = 0,t[1][j] = 1;
			}
		}
		
		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(31,vector<mint>(2,0));
		int M = m[i];
		tdp[0][0] = 1;
		for(int j=29;j>=0;j--){
			vector ndp(31,vector<mint>(2,0));
			rep(k,31){
				rep(l,2){
					if(tdp[k][l]==0)continue;
					rep(n,2){
						int kk = k,ll = l;
						if(ret[n][j])kk++;
						if(l==0){
							if((M>>j)&1){
								if(n==0)ll++;
							}
							else{
								if(n==1)continue;
							}
						}
						ndp[kk][ll] += tdp[k][l];
					}
				}
			}
			swap(tdp,ndp);
		}
		vector<mint> ndp(31,0);
		rep(j,31){
			rep(k,31){
				ndp[max(j,k)] += dp[j] * (tdp[k][0] + tdp[k][1]);
			}
		}
		swap(dp,ndp);
	}
	mint ans = 0;
	rep(i,dp.size())ans += dp[i] * i;
	cout<<ans.val()<<endl;
	
	return 0;
}
0