結果
| 問題 |
No.3205 Range Pairwise Xor Query
|
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2025-11-06 16:02:04 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 338 ms / 2,000 ms |
| コード長 | 1,283 bytes |
| コンパイル時間 | 7,395 ms |
| コンパイル使用メモリ | 281,264 KB |
| 実行使用メモリ | 120,464 KB |
| 最終ジャッジ日時 | 2025-11-06 16:10:53 |
| 合計ジャッジ時間 | 19,470 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 20 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << ")", dbg_out(__VA_ARGS__)
#define int long long
const int MOD = 1e9 + 7;
const int INF = LLONG_MAX >> 1;
void solve() {
int n, q; cin >> n >> q;
int a[n];
vector<vector<int>> pref0(n + 1, vector<int> (32, 0));
vector<vector<int>> pref1(n + 1, vector<int> (32, 0));
for(int i=0; i<n; i++) {
cin >> a[i];
for(int j = 0; j<32; j++) {
if(a[i] >> j & 1) {
pref1[i + 1][j]++;
} else {
pref0[i + 1][j]++;
}
pref0[i + 1][j] += pref0[i][j];
pref1[i + 1][j] += pref1[i][j];
}
}
while(q--) {
int l, r; cin >> l >> r; --l;
int ans = 0;
for(int i=0; i<32; i++) {
int z = pref0[r][i] - pref0[l][i];
int o = pref1[r][i] - pref1[l][i];
ans += (z * o) * (1LL << i);
}
cout << ans << '\n';
}
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tc = 1;
// cin >> tc;
while (tc--) solve();
}
vjudge1