結果
問題 |
No.3205 Range Pairwise Xor Query
|
ユーザー |
![]() |
提出日時 | 2025-07-19 00:27:40 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 590 ms / 2,000 ms |
コード長 | 941 bytes |
コンパイル時間 | 3,202 ms |
コンパイル使用メモリ | 281,848 KB |
実行使用メモリ | 99,392 KB |
最終ジャッジ日時 | 2025-07-19 00:28:01 |
合計ジャッジ時間 | 11,695 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 20 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; #ifdef LOCAL #include <debug.hpp> #else #define debug(...) #endif int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); int N, Q; cin >> N >> Q; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A[i]; // 各 i 桁ごとの 1, 0 の個数の累積和 vector one(30, vector<ll>(N + 1)); vector zero(30, vector<ll>(N + 1)); for (int i = 0; i < N; i++) { for (int d = 0; d < 30; d++) { one[d][i + 1] = one[d][i] + ((A[i] >> d) & 1); zero[d][i + 1] = zero[d][i] + !((A[i] >> d) & 1); } } while (Q--) { int L, R; cin >> L >> R, L--; ll ans = 0; for (int d = 0; d < 30; d++) { ans += (1LL << d) * (one[d][R] - one[d][L]) * (zero[d][R] - zero[d][L]); } cout << ans << '\n'; } }