| Task: | Xor sum |
| Sender: | discape |
| Submission time: | 2025-09-22 16:45:10 +0300 |
| Language: | C++ (C++20) |
| Status: | READY |
| Result: | ACCEPTED |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.00 s | details |
| #2 | ACCEPTED | 0.52 s | details |
Code
#include <bits/stdc++.h>
using namespace std;
// clang-format off
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { T value; is >> value; v.push_back(value); return is; }
#define preamble ios::sync_with_stdio(0); cin.tie(0); dbg("INIT");
// clang-format on
#ifdef DO_DBG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
template <typename T> using v = vector<T>;
template <typename T> using us = unordered_set<T>;
template <typename K, typename V> using um = unordered_map<K, V>;
constexpr int MOD = 1e9 + 7;
const int INF = 1e9;
const ld EPS = 1e-9;
#define loopi(n) for (int i = 0; i < n; i++)
#define loopj(n) for (int j = 0; j < n; j++)
#define loopk(n) for (int k = 0; k < n; k++)
#define loopz(n) for (int z = 0; z < n; z++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sq(x) ((x) * (x))
int main() {
int n, q;
cin >> n >> q;
v<int> x;
loopi(n) cin >> x;
dbg(n, q, x);
v<int> prefix(n);
int xorsum = 0;
loopi(n) {
xorsum ^= x[i];
prefix[i] = xorsum;
}
dbg(prefix);
loopz(q) {
int a, b;
cin >> a >> b;
// dbg(a, b);
int xorsum = prefix[a - 2] ^ prefix[b - 1];
cout << xorsum << "\n";
}
}
Test details
Test 1
Verdict: ACCEPTED
| 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 |
|---|
| 7 1 5 3 1 ... |
Test 2
Verdict: ACCEPTED
| input |
|---|
| 200000 200000 921726510 307633388 992247073 ... |
| correct output |
|---|
| 834756431 130379787 403037296 308618218 784778243 ... |
| user output |
|---|
| 834756431 130379787 403037296 308618218 784778243 ... Truncated |
