| Task: | Xor sum |
| Sender: | aalto26dm_047 |
| Submission time: | 2026-09-21 17:12:41 +0300 |
| Language: | C++ (C++20) |
| Status: | READY |
| Result: | WRONG ANSWER |
| test | verdict | time | |
|---|---|---|---|
| #1 | WRONG ANSWER | 0.00 s | details |
| #2 | WRONG ANSWER | 0.17 s | details |
Code
#include <bits/stdc++.h>
using namespace std;
int xor_sum(int a,int b){
int axb =0;
int count = 0;
while (a>0 && b>0){
if (a%2 ==1){
if (b%2 == 0){
axb += 2^count;
b /=2;
}
else{
b= (b-1)/2;
}
a = (a-1)/2;
}
else{
if (b%2 == 1){
axb += 2^count;
b = (b-1)/2;
}
else{
b /=2;
}
a = a/2;
}
count+=1;
}
return axb;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, q;
cin >> n >> q;
vector<int> tree(2 * n);
for (int i = 0; i < n; i++) {
cin >> tree[n + i];
}
for (int i = n-1; i > 0; --i) {
tree[i] = xor_sum(tree[2 * i],tree[2 * i + 1]);
}
for (int i =0; i<q; i++){
int a;
int b;
cin>>a>>b;
a += n; b += n;
int s = 0;
while (a <= b) {
if (a%2 == 1) s = xor_sum(s,tree[a++]);
if (b%2 == 0) s = xor_sum(s,tree[b--]);
a /= 2; b /= 2;
}
cout<<s<<"\n";
}
}Test details
Test 1
Verdict: WRONG ANSWER
| input |
|---|
| 8 36 7 6 4 6 2 9 4 8 1 1 1 2 1 3 ... |
| correct output |
|---|
| 7 1 5 3 1 ... |
| user output |
|---|
| 0 0 0 0 0 ... |
Feedback: Incorrect character on line 1 col 1: expected "7", got "0"
Test 2
Verdict: WRONG ANSWER
| input |
|---|
| 200000 200000 921726510 307633388 992247073 ... |
| correct output |
|---|
| 834756431 130379787 403037296 308618218 784778243 ... |
| user output |
|---|
| 0 0 0 0 0 ... |
Feedback: Incorrect character on line 1 col 1: expected "834756431", got "0"
