結果

問題 No.1863 Xor Sum 2...?
ユーザー 沙耶花
提出日時 2022-03-04 21:56:28
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 156 ms / 2,000 ms
コード長 1,158 bytes
コンパイル時間 6,881 ms
コンパイル使用メモリ 254,512 KB
最終ジャッジ日時 2025-01-28 05:14:27
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using P = pair<int,int>;
P op(P a,P b){
	a.first &= b.first;
	a.second ^= b.second;
	return a;
}

P e(){
	return make_pair((1<<30)-1,0);
}	

long long cnt[2];
int main(){
	
	int n;
	cin>>n;
	vector<P> t(n);
	rep(i,n){
		cin>>t[i].first;
	}
	rep(i,n){
		cin>>t[i].second;
	}
	segtree<P,op,e> seg(t);
	vector<int> cc(30,0);
	long long ans = 0LL;
	int r = 0;
	int rr = 0;
	rep(i,n){
		while(true){
			if(r==n)break;
			int m = 0;
			rep(j,30){
				if((t[r].first>>j)&1){
					cc[j]++;
					m = max(m,cc[j]);
				}
			}
			if(m<=1){
				r++;
			}
			else{
				rep(j,30){
					if((t[r].first>>j)&1){
						cc[j]--;
						m = max(m,cc[j]);
					}
				}
				break;
			}
		}
		
		while(r!=rr){
			rr++;
			cnt[seg.prod(0,rr).second]++;
			//rr++;
		}
		//cout<<r<<','<<cnt[0]<<','<<cnt[1]<<endl;
		ans += cnt[seg.prod(0,i).second];
		cnt[seg.prod(0,i+1).second]--;
		rep(j,30){
			if((t[i].first>>j)&1)cc[j]--;
		}
		
	}
	cout<<ans<<endl;
	
	return 0;
}
0