結果

問題 No.3205 Range Pairwise Xor Query
コンテスト
ユーザー vjudge1
提出日時 2025-11-06 15:43:31
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 250 ms / 2,000 ms
コード長 1,076 bytes
コンパイル時間 7,412 ms
コンパイル使用メモリ 281,056 KB
実行使用メモリ 46,976 KB
最終ジャッジ日時 2025-11-06 15:46:21
合計ジャッジ時間 18,594 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define nl "\n"
#define int long long
#define yes cout<<"YES"<< nl;
#define no cout<<"NO"<< nl;
#define pb push_back
#define vi vector<int>
#define si set<int>
#define ip(x) for(auto &it : x) cin>>it 
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
                                                     // Mohammad Hasibur Rahman

void solve(){
    int n, q; cin >> n >> q;
    vi v(n + 1);
    for (int i = 1; i <= n; i++) cin >> v[i];
    int x = 26;
    vector<vector<int>> vv(x, vector<int>(n + 1, 0));

    for (int i = 0; i < x; i++) {
        for (int j = 1; j <= n; j++) {
            vv[i][j] = vv[i][j-1] + ((v[j] >> i) & 1);
        }
    }

    while(q--) {
        int l, r; cin >> l >> r;
        int ans = 0;

        for (int i = 0; i < x; i++) {
            int a = vv[i][r] - vv[i][l - 1];
            int b = (r - l + 1) - a;

            ans += a * b * (1LL << i);
        }
        cout << ans << nl;
    }
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
int t;
    solve(); 
}
0