結果

問題 No.3205 Range Pairwise Xor Query
ユーザー umimel
提出日時 2025-07-18 21:46:01
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 358 ms / 2,000 ms
コード長 1,329 bytes
コンパイル時間 1,800 ms
コンパイル使用メモリ 168,956 KB
実行使用メモリ 101,028 KB
最終ジャッジ日時 2025-07-18 21:46:44
合計ジャッジ時間 7,785 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
const ll MOD1000000007 = 1000000007;
const ll MOD998244353 = 998244353;
const ll MOD[3] = {999727999, 1070777777, 1000000007};
const ll LINF = 1LL << 60LL;
const int IINF = (1 << 30) - 1;


void solve(){
    int n, q; cin >> n >> q;
    vector<int> a(n+1); for(int i = 1; i <= n; i++) cin >> a[i];
    vector<vector<ll>> cnt0(n+1, vector<ll>(26, 0)), cnt1(n+1, vector<ll>(26, 0));
    for(int i=1; i<=n; i++){
        for(int j=0; j<26; j++){
            cnt0[i][j] = cnt0[i-1][j];
            cnt1[i][j] = cnt1[i-1][j];
            if((a[i]>>j) & 1){
                cnt1[i][j]++;
            } else {
                cnt0[i][j]++;
            }
        }
    }

    while(q--){
        int l, r; cin >> l >> r;
        ll ans = 0;
        for(int j=0; j<26; j++){
            ll c0 = cnt0[r][j] - cnt0[l-1][j];
            ll c1 = cnt1[r][j] - cnt1[l-1][j];
            ans += (c0 * c1) << j;
        }
        cout << ans << '\n';
    }
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int T=1;
    //cin >> T;
    while(T--) solve();
}
0