結果
| 問題 |
No.3205 Range Pairwise Xor Query
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2025-07-20 18:25:15 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 121 ms / 2,000 ms |
| コード長 | 931 bytes |
| コンパイル時間 | 586 ms |
| コンパイル使用メモリ | 42,432 KB |
| 実行使用メモリ | 7,720 KB |
| 最終ジャッジ日時 | 2025-07-20 18:25:21 |
| 合計ジャッジ時間 | 4,843 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 20 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:33:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
33 | scanf("%d%d", &n, &qn);
| ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:34:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
34 | for (int i = 0; i < n; i++) scanf("%d", as + i);
| ~~~~~^~~~~~~~~~~~~~
main.cpp:35:37: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
35 | for (int i = 0; i < qn; i++) scanf("%d%d", ls + i, rs + i), ls[i]--;
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 3205.cc: No.3205 Range Pairwise Xor Query - yukicoder
*/
#include<cstdio>
#include<algorithm>
using namespace std;
/* constant */
const int MAX_N = 200000;
const int MAX_QN = 200000;
const int BN = 26;
/* typedef */
using ll = long long;
/* global variables */
int as[MAX_N], ls[MAX_QN], rs[MAX_QN];
int css[MAX_N + 1];
ll res[MAX_QN];
/* subroutines */
/* main */
int main() {
int n, qn;
scanf("%d%d", &n, &qn);
for (int i = 0; i < n; i++) scanf("%d", as + i);
for (int i = 0; i < qn; i++) scanf("%d%d", ls + i, rs + i), ls[i]--;
for (int k = 0; k < BN; k++) {
for (int i = 0; i < n; i++)
css[i + 1] = css[i] + ((as[i] >> k) & 1);
for (int i = 0; i < qn; i++) {
int c1 = css[rs[i]] - css[ls[i]];
int c0 = (rs[i] - ls[i]) - c1;
res[i] += (((ll)c0 * c1) << k);
}
}
for (int i = 0; i < qn; i++) printf("%lld\n", res[i]);
return 0;
}
tnakao0123