結果

問題 No.2498 OX Operations
ユーザー 👑 kmjpkmjp
提出日時 2023-10-12 00:28:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 163 ms / 4,000 ms
コード長 2,819 bytes
コンパイル時間 2,353 ms
コンパイル使用メモリ 207,172 KB
実行使用メモリ 20,324 KB
最終ジャッジ日時 2023-10-12 00:28:46
合計ジャッジ時間 7,165 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
19,404 KB
testcase_01 AC 9 ms
19,280 KB
testcase_02 AC 9 ms
19,360 KB
testcase_03 AC 9 ms
19,356 KB
testcase_04 AC 9 ms
19,244 KB
testcase_05 AC 9 ms
19,284 KB
testcase_06 AC 9 ms
19,412 KB
testcase_07 AC 9 ms
19,232 KB
testcase_08 AC 9 ms
19,280 KB
testcase_09 AC 9 ms
19,484 KB
testcase_10 AC 9 ms
19,472 KB
testcase_11 AC 9 ms
19,348 KB
testcase_12 AC 10 ms
19,356 KB
testcase_13 AC 10 ms
19,292 KB
testcase_14 AC 10 ms
19,308 KB
testcase_15 AC 99 ms
19,984 KB
testcase_16 AC 151 ms
20,208 KB
testcase_17 AC 73 ms
19,972 KB
testcase_18 AC 121 ms
20,308 KB
testcase_19 AC 90 ms
20,324 KB
testcase_20 AC 133 ms
20,208 KB
testcase_21 AC 161 ms
20,316 KB
testcase_22 AC 109 ms
19,744 KB
testcase_23 AC 105 ms
19,796 KB
testcase_24 AC 163 ms
20,208 KB
testcase_25 AC 162 ms
20,312 KB
testcase_26 AC 162 ms
20,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

template<class V,int NV> class SegTree_2 {
public:
	vector<V> val;
	SegTree_2(){val.resize(NV*2); FORR(v,val) v.second=(1<<30)-1;};
	int merge(int cur,pair<int,int> a) {
		return (cur&a.second)|(~cur&a.first);
	}
	pair<int,int> merge(pair<int,int> cur,pair<int,int> a) {
		
		return {merge(cur.first,a),merge(cur.second,a)};
	}
	
	V getval(int k) {
		int e=k+NV;
		V ret={0,(1<<30)-1};
		while(e>=1) {
			ret=merge(ret,val[e]);
			e/=2;
		}
		return ret;
	}
	
	void update(int x,int y, int orv,int xorv ,int l=0,int r=NV,int k=1) {
		if(l>=r) return;
		if(x<=l && r<=y) {
			if(orv) {
				val[k].first|=orv;
				val[k].second|=orv;
			}
			else {
				val[k].first^=xorv;
				val[k].second^=xorv;
			}
		}
		else if(l < y && x < r) {
			val[k*2]=merge(val[k*2],val[k]);
			val[k*2+1]=merge(val[k*2+1],val[k]);
			val[k]={0,(1<<30)-1};
			update(x,y,orv,xorv,l,(l+r)/2,k*2);
			update(x,y,orv,xorv,(l+r)/2,r,k*2+1);
		}
	}
};


SegTree_2<pair<int,int>, 1<<20> st;

int N,Q;
ll M[101010];
ll C[31][31];

ll from[33];
ll to[33],dp[33];
const ll mo=998244353;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	FOR(i,31) {
		C[i][0]=C[i][i]=1;
		for(j=1;j<i;j++) C[i][j]=C[i-1][j]+C[i-1][j-1];
	}
	
	cin>>N>>Q;
	
	FOR(i,N) cin>>M[i];
	while(Q--) {
		int L,R,X;
		cin>>s>>L>>R>>X;
		L--;
		if(s=="o") {
			st.update(L,R,X,0);
		}
		else {
			st.update(L,R,0,X);
		}
	}
	FOR(i,31) from[i]=1;
	
	FOR(i,N) {
		ZERO(to);
		ZERO(dp);
		auto p=st.getval(i);
		int add=0;
		for(j=29;j>=0;j--) {
			if(M[i]&(1<<j)) {
				int add2=add+((p.first>>j)%2);
				int both=__builtin_popcountll((p.first&p.second)&((1<<j)-1));
				int one=__builtin_popcountll((p.first^p.second)&((1<<j)-1));
				for(x=0;x<=one;x++) {
					(dp[add2+both+x]+=C[one][x]*(1LL<<(j-one)))%=mo;
				}
				if(p.second&(1<<j)) add++;
			}
			else {
				if(p.first&(1<<j)) add++;
			}
		}
		dp[add]++;
		FOR(j,31) {
			(dp[j+1]+=dp[j])%=mo;
			from[j]=from[j]*dp[j]%mo;
		}
	}
	
	ll ret=0;
	for(i=1;i<=30;i++) (ret+=i*(from[i]+mo-from[i-1]))%=mo;
	cout<<ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0