Task: | Xor sum |
Sender: | ZDHKLV |
Submission time: | 2024-09-23 16:26:37 +0300 |
Language: | C++ (C++11) |
Status: | READY |
Result: | TIME LIMIT EXCEEDED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.00 s | details |
#2 | TIME LIMIT EXCEEDED | -- | details |
Code
#include <bits/stdc++.h> using namespace std; #define MAXN 200000 #define SQRSIZE 400 long long arr[MAXN]; // original array long long block[SQRSIZE]; // decomposed array long long block_size; // block size void sqrt_decomposition_update(int index, long long value) { int block_number = index / block_size; block[block_number] ^= value - arr[index]; arr[index] = value; } // Time Complexity : O(sqrt(n)) int sqrt_decomposition_query(int left, int right) { int sum = 0; while (left < right and left % block_size != 0 and left != 0) { sum ^= arr[left]; left++; } while (left + block_size - 1 <= right) { sum ^= block[left / block_size]; left += block_size; } while (left <= right) { sum ^= arr[left]; left++; } return sum; } void sqrt_decomposition_preprocess(int input[], int n) { int block_index = -1; block_size = sqrt(n); for (int i = 0; i < n; i++) { arr[i] = input[i]; if (i % block_size == 0) block_index++; block[block_index] ^= arr[i]; } } int main() { int n, q; cin >> n >> q; int *input = new int[n]; for (int i = 0; i < n; i++) cin >> input[i]; sqrt_decomposition_preprocess(input, n); vector<long long> output; for (int i = 0; i < q; i++) { int a, b; cin >> a >> b; long long o = sqrt_decomposition_query(a-1, b-1); output.push_back(o); } for (long long o : output) cout << o << endl; return 0; }
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: TIME LIMIT EXCEEDED
input |
---|
200000 200000 921726510 307633388 992247073 ... |
correct output |
---|
834756431 130379787 403037296 308618218 784778243 ... |
user output |
---|
(empty) |